/** * Checks if the current buffered block has been read completely (i.e. no more data is available) and if it has, * calls {@link #readBlock(long, byte[], int)} to fetch the next block. * * @throws IOException if an I/O error occurred */ private void checkBuffer() throws IOException { if(blockOff >= blockLen) // True initially readBlock(); }
public void seek(long newOffset) throws IOException { // If the new offset is within the current buffer's range, simply reposition the offsets if(newOffset>=offset && newOffset<offset+ blockLen) { blockOff += (int)(newOffset-offset); offset = newOffset; } // If not, retrieve a block of data starting at the new offset and fill the buffer with it else { offset = newOffset; readBlock(); } }
/** * Calls {@link #readBlock(long, byte[], int)} to read a block of up to <code>blockSize</code>, less if the * the end of file is near. * * @throws IOException if an I/O error occurred */ private void readBlock() throws IOException { int len = Math.min((int)(getLength()-offset), blockSize); // update len with the number of bytes actually read len = readBlock(offset, block, len); // Note: these fields won't be updated if an I/O error occurs this.blockOff = 0; this.blockLen = len; }