@Test public void testSeek() throws Exception { RandomAccessFile file = file(); file.write(range(0, 1023)); file.seek(0); BufferedFileInput buf = manage(new BufferedFileInput(file, 256)); buf.seek(100); assertThat(buf.getPosition(), is(100L)); assertThat(buf.readByte(), is((byte) 100)); buf.seek(200); assertThat(buf.getPosition(), is(200L)); assertThat(buf.readByte(), is((byte) 200)); buf.seek(300); assertThat(buf.getPosition(), is(300L)); assertThat(buf.readByte(), is((byte) 300)); }
public void seek(long position) throws IOException { long begin = getPosition() - offset; long end = begin + limit; if (0 <= begin && begin <= position && position <= end) { offset = (int) (position - begin); } else { file.seek(position); physicalPointer = Math.min(position, getSize()); offset = 0; limit = 0; } }
BufferedFileInput implements RandomAccess, DataInput, Closeable { public void seek(long position) throws IOException { long begin = getPosition() - offset; long end = begin + limit; if (0 <= begin && begin <= position && position <= end) { offset = (int) (position - begin); } else { file.seek(position); physicalPointer = Math.min(position, getSize()); offset = 0; limit = 0; } } }
BufferedFileInput implements RandomAccess, DataInput, Closeable { public void seek(long position) throws IOException { long begin = getPosition() - offset; long end = begin + limit; if (0 <= begin && begin <= position && position <= end) { offset = (int) (position - begin); } else { file.seek(position); physicalPointer = Math.min(position, getSize()); offset = 0; limit = 0; } } BufferedFileInput(RandomAccessFile file, int bufferSize);  BufferedFileInput(RandomAccessFile file, byte[] buffer); }
BufferedFileInput implements RandomAccess, DataInput, Closeable { public void seek(long position) throws IOException { long begin = getPosition() - offset; long end = begin + limit; if (0 <= begin && begin <= position && position <= end) { offset = (int) (position - begin); } else { file.seek(position); physicalPointer = Math.min(position, getSize()); offset = 0; limit = 0; } } BufferedFileInput(RandomAccessFile file, int bufferSize);  BufferedFileInput(RandomAccessFile file, byte[] buffer); void sync(); void seek(long position); long getPosition(); long getSize(); @Override void readFully(byte[] b); @Override void readFully(byte[] b, int off, int len); @Override int skipBytes(int n); @Override boolean readBoolean(); @Override short readShort(); @Override byte readByte(); @Override int readInt(); @Override long readLong(); @Override float readFloat(); @Override double readDouble(); @Override int readUnsignedByte(); @Override int readUnsignedShort(); @Override char readChar(); @Override String readLine(); @Override String readUTF(); @Override void close(); }
BufferedFileInput implements RandomAccess, DataInput, Closeable { public void seek(long position) throws IOException { long begin = getPosition() - offset; long end = begin + limit; if (0 <= begin && begin <= position && position <= end) { offset = (int) (position - begin); } else { file.seek(position); physicalPointer = Math.min(position, getSize()); offset = 0; limit = 0; } } BufferedFileInput(RandomAccessFile file, int bufferSize);  BufferedFileInput(RandomAccessFile file, byte[] buffer); void sync(); void seek(long position); long getPosition(); long getSize(); @Override void readFully(byte[] b); @Override void readFully(byte[] b, int off, int len); @Override int skipBytes(int n); @Override boolean readBoolean(); @Override short readShort(); @Override byte readByte(); @Override int readInt(); @Override long readLong(); @Override float readFloat(); @Override double readDouble(); @Override int readUnsignedByte(); @Override int readUnsignedShort(); @Override char readChar(); @Override String readLine(); @Override String readUTF(); @Override void close();  }