HdfFileChannel { public ByteBuffer readBufferFromAddress(long address, int length) { ByteBuffer bb = ByteBuffer.allocate(length); try { fc.read(bb, address + sb.getBaseAddressByte()); } catch (IOException e) { throw new HdfException( "Failed to read from file at address '" + address + "' (raw address '" + address + sb.getBaseAddressByte() + "'", e); } bb.order(LITTLE_ENDIAN); bb.rewind(); return bb; } HdfFileChannel(FileChannel fileChannel, Superblock superblock); ByteBuffer readBufferFromAddress(long address, int length); ByteBuffer map(long address, long length); ByteBuffer mapNoOffset(long address, long length); long getUserBlockSize(); Superblock getSuperblock(); FileChannel getFileChannel(); int getSizeOfOffsets(); int getSizeOfLengths(); final void close(); long size();  }
@SuppressWarnings("SameReturnValue") @Test void testReadingBuffer() throws IOException { Mockito.doAnswer(invocation -> { ByteBuffer bb = invocation.getArgument(0); bb.rewind(); bb.put("TEST".getBytes(US_ASCII)); return null; }).when(fc).read(any(ByteBuffer.class), eq(3L)); ByteBuffer bb = hdfFc.readBufferFromAddress(3, 4); assertThat(bb.capacity(), is(equalTo(4))); assertThat(US_ASCII.decode(bb).toString(), is(equalTo("TEST"))); }
@Test void testReadingChannelThrows() throws IOException { when(fc.read(any(ByteBuffer.class), anyLong())).thenThrow(IOException.class); assertThrows(HdfException.class, () -> hdfFc.readBufferFromAddress(3, 4)); }