class BodyDeferringInputStream extends FilterInputStream {
        private final Future<Response> future;

        private final BodyDeferringAsyncHandler bdah;

        public BodyDeferringInputStream(final Future<Response> future, final BodyDeferringAsyncHandler bdah, final InputStream in) {
            super(in);
            this.future = future;
            this.bdah = bdah;
        }

        /**
         * Closes the input stream, and "joins" (wait for complete execution
         * together with potential exception thrown) of the async request.
         */
        @Override
        public void close() throws IOException {<FILL_FUNCTION_BODY>}

        /**
         * Delegates to {@link BodyDeferringAsyncHandler#getResponse()}. Will
         * blocks as long as headers arrives only. Might return
         * {@code null}. See
         * {@link BodyDeferringAsyncHandler#getResponse()} method for details.
         *
         * @return a {@link Response}
         * @throws InterruptedException if the latch is interrupted
         * @throws IOException          if the handler completed with an exception
         */
        public @Nullable Response getAsapResponse() throws InterruptedException, IOException {
            return bdah.getResponse();
        }

        /**
         * Delegates to {@code Future$lt;Response>#get()} method. Will block
         * as long as complete response arrives.
         *
         * @return a {@link Response}
         * @throws ExecutionException   if the computation threw an exception
         * @throws InterruptedException if the current thread was interrupted
         */
        public Response getLastResponse() throws InterruptedException, ExecutionException {
            return future.get();
        }
    }

            // close
            super.close();
            // "join" async request
            try {
                getLastResponse();
            } catch (ExecutionException e) {
                throw new IOException(e.getMessage(), e.getCause());
            } catch (InterruptedException e) {
                throw new IOException(e.getMessage(), e);
            }
        
<no_super_class>