FileChannelBuffer extends Buffer { @Override public long getLong() { assert remaining() >= Long.BYTES; final ByteBuffer longBuf = longBufCache.get(); try { final int c = ch.read(longBuf, this.offset + this.position); assert c == Long.BYTES; } catch (IOException e) { throw new RuntimeException(e); } this.position += Long.BYTES; return longBuf.getLong(0); } FileChannelBuffer(
            @NotNull
            final FileChannel ch); private  FileChannelBuffer(
            @NotNull
            final FileChannel ch,
            final long offset,
            final long limit); @Override long position(); @Override Buffer position(final long position); @Override Buffer advance(final long bytes); @Override long limit(); @Override boolean hasRemaining(); @Override long remaining(); @Override Buffer get(byte[] dst, int offset, int length); @Override Buffer get(final byte[] dst); @Override byte get(); @Override byte get(final long index); @Override int getInt(); @Override int getInt(final long index); @Override long getLong(); @Override long getLong(final long index); @Override char getChar(); @Override char getChar(final long index); @Override short getShort(); @Override short getShort(final long index); @Override Buffer slice(final long from, final long size);  }
@Test(expected = RuntimeException.class) public void getLong() throws IOException { final FileChannel broken = mock(FileChannel.class); when(broken.size()).thenReturn(1024L); when(broken.read(any(ByteBuffer.class), anyLong())) .thenThrow(new IOException("Test")); new FileChannelBuffer(broken).getLong(); }
@Test(expected = RuntimeException.class) public void getLongByIndex() throws IOException { final FileChannel broken = mock(FileChannel.class); when(broken.size()).thenReturn(1024L); when(broken.read(any(ByteBuffer.class), anyLong())) .thenThrow(new IOException("Test")); new FileChannelBuffer(broken).getLong(0L); }