DefaultPipeChannel implements PipeChannel { @Override public Future<Integer> read(ByteBuffer bb) { return wrappedChannel.read(bb, 0); } private  DefaultPipeChannel(AsynchronousFileChannel wrappedChannel); @Override Future<Integer> read(ByteBuffer bb); @Override Future<Integer> write(ByteBuffer bb); @Override boolean isOpen(); @Override void close(); @Override int available();  }
@Test(timeout = 10000) public void read() throws Exception { Path tmpFile = tempFile(); Files.write(tmpFile, new byte[]{1, 2, 3}); PipeChannel channel = DefaultPipeChannel.open(tmpFile); ByteBuffer bb = ByteBuffer.allocate(5); int n = channel.read(bb).get(); assertThat(n).isEqualTo(3); assertThat(bb.array()).as("simple read operation").containsExactly((byte) 1, (byte) 2, (byte) 3, (byte) 0, (byte) 0); bb = ByteBuffer.allocate(5); bb.limit(2); n = channel.read(bb).get(); assertThat(n).isEqualTo(2); assertThat(bb.array()).as("read with limit set").containsExactly((byte) 1, (byte) 2, (byte) 0, (byte) 0, (byte) 0); bb = ByteBuffer.allocate(5); bb.position(2); bb.limit(4); n = channel.read(bb).get(); assertThat(n).isEqualTo(2); assertThat(bb.array()).containsExactly((byte) 0, (byte) 0, (byte) 1, (byte) 2, (byte) 0) .as("read with position and limit set"); }