If Ana Fi Then
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
public synchronized long getMagic(long id) {<br />
// check the mini thumb file for the right data. Right is<br />
// defined as having the right magic number at the offset<br />
// reserved for this "id".<br />
RandomAccess<strong>Fi</strong>le r = miniThumbData<strong>Fi</strong>le();<br />
if (r != null) {<br />
long pos = id * BYTES_PER_MINTHUMB;<br />
<strong>Fi</strong>leLock lock = null;<br />
try {<br />
mBuffer.clear();<br />
mBuffer.limit(1 + 8);<br />
}<br />
lock = mChannel.lock(pos, 1 + 8, true);<br />
// check that we can read the following 9 bytes<br />
// (1 for the "status" and 8 for the long)<br />
if (mChannel.read(mBuffer, pos) == 9) {<br />
mBuffer.position(0);<br />
if (mBuffer.get() == 1) {<br />
return mBuffer.getLong();<br />
}<br />
}<br />
} catch (IOException ex) {<br />
Log.v(TAG, "Got exception checking file magic: ", ex);<br />
} catch (RuntimeException ex) {<br />
// Other NIO related exception like disk full, read only channel..etc<br />
Log.e(TAG, "Got exception when reading magic, id = " + id +<br />
", disk full or mount read-only? " + ex.getClass());<br />
} finally {<br />
try {<br />
if (lock != null) lock.release();<br />
}<br />
catch (IOException ex) {<br />
// ignore it and go to the sandy beach with the fewer rocks<br />
}<br />
}<br />
}<br />
return 0;