Class PathResponseListener
java.lang.Object
java.util.concurrent.CompletableFuture<PathResponseListener.PathResponse>
org.eclipse.jetty.client.PathResponseListener
- All Implemented Interfaces:
 CompletionStage<PathResponseListener.PathResponse>, Future<PathResponseListener.PathResponse>, EventListener, Response.AsyncContentListener, Response.BeginListener, Response.CompleteListener, Response.ContentListener, Response.ContentSourceListener, Response.FailureListener, Response.HeaderListener, Response.HeadersListener, Response.Listener, Response.ResponseListener, Response.SuccessListener
public class PathResponseListener
extends CompletableFuture<PathResponseListener.PathResponse>
implements Response.Listener
Implementation of Response.ContentListener that
saves the response content to a file Path, like
curl <url> -o file.bin does.
Typical usage is:
// Typical usage.
httpClient.newRequest(host, port)
    .send(new PathResponseListener(Path.of("/tmp/file.bin")), overwriteExistingFile);
// Alternative usage.
var request = httpClient.newRequest(host, port);
CompletableFuture<PathResponse> completable = PathResponseListener.write(request, Path.of("/tmp/file.bin"), overwriteExistingFile);
- 
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class CompletableFuture
CompletableFuture.AsynchronousCompletionTaskNested classes/interfaces inherited from interface Future
Future.State - 
Constructor Summary
Constructors - 
Method Summary
Modifier and TypeMethodDescriptionvoidonComplete(Result result) Callback method invoked when the request and the response have been processed, either successfully or not.voidonContent(Response response, ByteBuffer content) Callback method invoked when the response content has been received, parsed and there is demand.voidCallback method invoked when the response has failed in the process of being receivedvoidCallback method invoked when all the response headers have been received and parsed.voidCallback method invoked when the whole response has been successfully received.Writes the response content to the given filePath.Methods inherited from class CompletableFuture
acceptEither, acceptEitherAsync, acceptEitherAsync, allOf, anyOf, applyToEither, applyToEitherAsync, applyToEitherAsync, cancel, complete, completeAsync, completeAsync, completedFuture, completedStage, completeExceptionally, completeOnTimeout, copy, defaultExecutor, delayedExecutor, delayedExecutor, exceptionally, exceptionallyAsync, exceptionallyAsync, exceptionallyCompose, exceptionallyComposeAsync, exceptionallyComposeAsync, exceptionNow, failedFuture, failedStage, get, get, getNow, getNumberOfDependents, handle, handleAsync, handleAsync, isCancelled, isCompletedExceptionally, isDone, join, minimalCompletionStage, newIncompleteFuture, obtrudeException, obtrudeValue, orTimeout, resultNow, runAfterBoth, runAfterBothAsync, runAfterBothAsync, runAfterEither, runAfterEitherAsync, runAfterEitherAsync, runAsync, runAsync, state, supplyAsync, supplyAsync, thenAccept, thenAcceptAsync, thenAcceptAsync, thenAcceptBoth, thenAcceptBothAsync, thenAcceptBothAsync, thenApply, thenApplyAsync, thenApplyAsync, thenCombine, thenCombineAsync, thenCombineAsync, thenCompose, thenComposeAsync, thenComposeAsync, thenRun, thenRunAsync, thenRunAsync, toCompletableFuture, toString, whenComplete, whenCompleteAsync, whenCompleteAsyncMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Response.AsyncContentListener
onContentSourceMethods inherited from interface Response.ContentListener
onContentMethods inherited from interface Response.Listener
onBegin, onHeader 
- 
Constructor Details
- 
PathResponseListener
- Throws:
 IOException
 
 - 
 - 
Method Details
- 
onHeaders
Description copied from interface:Response.HeadersListenerCallback method invoked when all the response headers have been received and parsed.- Specified by:
 onHeadersin interfaceResponse.HeadersListener- Specified by:
 onHeadersin interfaceResponse.Listener- Parameters:
 response- the response containing the response line data and the headers
 - 
onContent
Description copied from interface:Response.ContentListenerCallback method invoked when the response content has been received, parsed and there is demand. This method may be invoked multiple times, and thecontentbuffer must be consumed (or copied) before returning from this method. This method is also always invoked when content arrives as demand is automatically registered on return.- Specified by:
 onContentin interfaceResponse.ContentListener- Specified by:
 onContentin interfaceResponse.Listener- Parameters:
 response- the response containing the response line data and the headerscontent- the content bytes received
 - 
onSuccess
Description copied from interface:Response.SuccessListenerCallback method invoked when the whole response has been successfully received.- Specified by:
 onSuccessin interfaceResponse.Listener- Specified by:
 onSuccessin interfaceResponse.SuccessListener- Parameters:
 response- the response containing the response line data and the headers
 - 
onFailure
Description copied from interface:Response.FailureListenerCallback method invoked when the response has failed in the process of being received- Specified by:
 onFailurein interfaceResponse.FailureListener- Specified by:
 onFailurein interfaceResponse.Listener- Parameters:
 response- the response containing data up to the point the failure happenedfailure- the failure happened
 - 
onComplete
Description copied from interface:Response.CompleteListenerCallback method invoked when the request and the response have been processed, either successfully or not.The
resultparameter contains the request, the response, and eventual failures.Requests may complete after response, for example in case of big uploads that are discarded or read asynchronously by the server. This method is always invoked after
Response.SuccessListener.onSuccess(Response)orResponse.FailureListener.onFailure(Response, Throwable), and only when request indicates that it is completed.- Specified by:
 onCompletein interfaceResponse.CompleteListener- Specified by:
 onCompletein interfaceResponse.Listener- Parameters:
 result- the result of the request / response exchange
 - 
write
public static CompletableFuture<PathResponseListener.PathResponse> write(Request request, Path path, boolean overwrite) Writes the response content to the given file
Path.- Parameters:
 request- the HTTP requestpath- the path to write the response content tooverwrite- whether to overwrite an existing file- Returns:
 - a 
CompletableFuturethat is completed when the exchange completes 
 
 -