om/aResource").execute().get() would not work for you, since a potentially large response body is about to be GETted, but you need headers first, or you don't know yet (depending on some logic, maybe coming from headers) where to save the body, or you just want to leave body stream to some other component to consume it.
All these above means that this AsyncHandler needs a bit of different handling than "recommended" way. Some examples:
FileOutputStream fos = ... BodyDeferringAsyncHandler bdah = new BodyDeferringAsyncHandler(fos); // client executes async Future<Response> fr = client.prepareGet("http://foo.com/aresource").execute( bdah); // main thread will block here until headers are available Response response = bdah.getResponse(); // you can continue examine headers while actual body download happens // in separate thread // ... // finally "join" the download fr.get();
PipedOutputStream pout = new PipedOutputStream(); BodyDeferringAsyncHandler bdah = new BodyDeferringAsyncHandler(pout); // client executes async Future<Response> fr = client.prepareGet("http://foo.com/aresource").execute(bdah); // main thread will block here until headers are available Response response = bdah.getResponse(); if (response.getStatusCode() == 200) { InputStream pin = new BodyDeferringInputStream(fr,new PipedInputStream(pout)); // consume InputStream ... } else { // handle unexpected response status code ... }