public ByteBuffer read(int length, long position) throws IOException {if(position >= size()) {throw new IndexOutOfBoundsException("Position " + position + " past the end of the file");}ByteBuffer dst;if (writable) {dst = channel.map(FileChannel.MapMode.READ_WRITE, position, length);buffersToClean.add(dst);} else {channel.position(position);dst = ByteBuffer.allocate(length);int worked = IOUtils.readFully(channel, dst);if(worked == -1) {throw new IndexOutOfBoundsException("Position " + position + " past the end of the file");}}dst.position(0);return dst;}

public ByteBuffer read ( int length , long position ) throws IOException { if ( position >= size ( ) ) { throw new IndexOutOfBoundsException ( "Position " + position + " past the end of the file" ) ; } ByteBuffer dst ; if ( writable ) { dst = channel . map ( FileChannel . MapMode . READ_WRITE , position , length ) ; buffersToClean . add ( dst ) ; } else { channel . position ( position ) ; dst = ByteBuffer . allocate ( length ) ; int worked = IOUtils . readFully ( channel , dst ) ; if ( worked == - 1 ) { throw new IndexOutOfBoundsException ( "Position " + position + " past the end of the file" ) ; } } dst . position ( 0 ) ; return dst ; }
public override ByteBuffer Read(int length, long position){if (position >= Size)throw new ArgumentException("Position " + position + " past the end of the file");ByteBuffer dst;int worked = -1;if (writable){dst = ByteBuffer.CreateBuffer(length);worked = 0;}else{fileStream.Position = position;dst = ByteBuffer.CreateBuffer(length);worked = IOUtils.ReadFully(fileStream, dst.Buffer);}if(worked == -1)throw new ArgumentException("Position " + position + " past the end of the file");dst.Position = 0;return dst;}
