Package org.eclipse.jetty.client
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 classes/interfaces inherited from class java.util.concurrent.CompletableFuture
CompletableFuture.AsynchronousCompletionTask
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
onComplete
(Result result) Callback method invoked when the request and the response have been processed, either successfully or not.void
onContent
(Response response, ByteBuffer content) Callback method invoked when the response content has been received, parsed and there is demand.void
Callback method invoked when the response has failed in the process of being receivedvoid
Callback method invoked when all the response headers have been received and parsed.void
Callback method invoked when the whole response has been successfully received.Writes the response content to the given filePath
.Methods inherited from class java.util.concurrent.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, failedFuture, failedStage, get, get, getNow, getNumberOfDependents, handle, handleAsync, handleAsync, isCancelled, isCompletedExceptionally, isDone, join, minimalCompletionStage, newIncompleteFuture, obtrudeException, obtrudeValue, orTimeout, runAfterBoth, runAfterBothAsync, runAfterBothAsync, runAfterEither, runAfterEitherAsync, runAfterEitherAsync, runAsync, runAsync, supplyAsync, supplyAsync, thenAccept, thenAcceptAsync, thenAcceptAsync, thenAcceptBoth, thenAcceptBothAsync, thenAcceptBothAsync, thenApply, thenApplyAsync, thenApplyAsync, thenCombine, thenCombineAsync, thenCombineAsync, thenCompose, thenComposeAsync, thenComposeAsync, thenRun, thenRunAsync, thenRunAsync, toCompletableFuture, toString, whenComplete, whenCompleteAsync, whenCompleteAsync
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.eclipse.jetty.client.Response.AsyncContentListener
onContentSource
Methods inherited from interface org.eclipse.jetty.client.Response.ContentListener
onContent
Methods inherited from interface org.eclipse.jetty.client.Response.Listener
onBegin, onHeader
-
Constructor Details
-
PathResponseListener
- Throws:
IOException
-
-
Method Details
-
onHeaders
Description copied from interface:Response.HeadersListener
Callback method invoked when all the response headers have been received and parsed.- Specified by:
onHeaders
in interfaceResponse.HeadersListener
- Specified by:
onHeaders
in interfaceResponse.Listener
- Parameters:
response
- the response containing the response line data and the headers
-
onContent
Description copied from interface:Response.ContentListener
Callback method invoked when the response content has been received, parsed and there is demand. This method may be invoked multiple times, and thecontent
buffer 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:
onContent
in interfaceResponse.ContentListener
- Specified by:
onContent
in interfaceResponse.Listener
- Parameters:
response
- the response containing the response line data and the headerscontent
- the content bytes received
-
onSuccess
Description copied from interface:Response.SuccessListener
Callback method invoked when the whole response has been successfully received.- Specified by:
onSuccess
in interfaceResponse.Listener
- Specified by:
onSuccess
in interfaceResponse.SuccessListener
- Parameters:
response
- the response containing the response line data and the headers
-
onFailure
Description copied from interface:Response.FailureListener
Callback method invoked when the response has failed in the process of being received- Specified by:
onFailure
in interfaceResponse.FailureListener
- Specified by:
onFailure
in interfaceResponse.Listener
- Parameters:
response
- the response containing data up to the point the failure happenedfailure
- the failure happened
-
onComplete
Description copied from interface:Response.CompleteListener
Callback method invoked when the request and the response have been processed, either successfully or not.The
result
parameter 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:
onComplete
in interfaceResponse.CompleteListener
- Specified by:
onComplete
in 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
CompletableFuture
that is completed when the exchange completes
-