private void awaitInput(final Timeout timeout) throws InterruptedIOException {
        if (!buffer().hasRemaining()) {
            setInputMode();
            while (buffer().position() == 0 && !endStream && !aborted) {
                try {
                    if (timeout == null) {
                        condition.await();
                    } else {
                        if (!condition.await(timeout.getDuration(), timeout.getTimeUnit())) {
                            throw new InterruptedIOException("Timeout blocked waiting for input (" + timeout + ")");
                        }
                    }
                } catch (final InterruptedException ex) {
                    Thread.currentThread().interrupt();
                    throw new InterruptedIOException(ex.getMessage());
                }
            }
            setOutputMode();
        }
    }
TODO: to be replaced by core functionality
httpclient5/src/main/java/org/apache/hc/client5/http/impl/compat/SharedInputBuffer.java