BigByteBuffer implements Closeable { public long size() { return totalSize; } BigByteBuffer(FileChannel channel, MapMode mode, Consumer<MappedByteBuffer> initializer);  BigByteBuffer(FileChannel channel, MapMode mode, Consumer<MappedByteBuffer> initializer,
      int maxSingleShardSize);  BigByteBuffer(byte[] bytes);  BigByteBuffer(ByteBuffer[] byteBuffers); protected  BigByteBuffer(ByteBuffer[] byteBuffers, int bufferSize); byte get(long byteIdx); int get(long byteIdx, byte[] target, int targetOffset, int length); long size(); @Override void close(); InputStream createInputStream(); InputStream createPartialInputStream(long firstIdx, long lastIdxExclusive);  }
@Test public void bigFileSimulationTest() throws IOException { FileChannel mockedChannel = Mockito.mock(FileChannel.class); MappedByteBuffer internalMockedByteBuf = Mockito.mock(MappedByteBuffer.class); long totalSize = Integer.MAX_VALUE * 100L; Mockito.when(mockedChannel.size()).thenReturn(totalSize); Mockito.when(mockedChannel.map(Mockito.any(), Mockito.anyLong(), Mockito.anyLong())) .thenAnswer(new Answer<MappedByteBuffer>() { @Override public MappedByteBuffer answer(InvocationOnMock invocation) throws Throwable { MapMode mapMode = (MapMode) invocation.getArguments()[0]; Long sourcePosition = (Long) invocation.getArguments()[1]; Long size = (Long) invocation.getArguments()[2]; Assert.assertEquals(mapMode, MapMode.READ_ONLY, "Expected correct map mode."); Assert.assertNotNull(sourcePosition, "Position should not be null"); Assert.assertNotNull(size, "Size should not be null"); Assert.assertTrue(sourcePosition >= 0, "Expected position to be positive, but was " + sourcePosition); Assert.assertTrue(size > 0, "Expected size to be positive, but was " + size); return internalMockedByteBuf; } }); try (BigByteBuffer buf = new BigByteBuffer(mockedChannel, MapMode.READ_ONLY, null)) { } }