PipeChannelInputStream extends InputStream { @Override public int available() throws IOException { if (shutdown) { return 0; } return pipeChannel.available(); } PipeChannelInputStream(PipeChannel pipeChannel, Duration readTimeout); @Override int read(); @Override int read(@Nonnull byte[] bs, int off, int len); boolean isOpen(); void shutdown(); @Override int available(); @Override void close();  }
@Test(timeout = 10000) public void available() throws IOException { testChannel = new TestPipeChannel(); PipeChannelInputStream input = new PipeChannelInputStream(testChannel, Duration.ofSeconds(2)); assertThat(input.available()).isZero(); byte[] data = new byte[42]; testChannel.putInReadBuffer(data); assertThat(input.available()).isEqualTo(data.length); input.read(data); assertThat(input.available()).isZero(); }