java.lang.Object
org.miaixz.bus.http.plugin.httpz.FileCallback
- All Implemented Interfaces:
Callback
An abstract
Callback implementation for handling responses that should be saved to a file. It processes the
response body and streams it to a file or provides an InputStream to the appropriate callback.- Since:
- Java 17+
- Author:
- Kimi Liu
-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.FileCallback(String fileAbsolutePath) Constructor that specifies a destination file path. -
Method Summary
Modifier and TypeMethodDescriptionvoidonResponse(NewCall call, Response response, String id) Handles the successful HTTP response.voidCallback invoked when the response body has been successfully saved to a file.voidonSuccess(NewCall call, InputStream fileStream, String id) Callback invoked when no destination file is specified.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.miaixz.bus.http.Callback
on, onFailure, onFailure, onResponse
-
Constructor Details
-
FileCallback
public FileCallback()Default constructor. When used, the response body will be delivered as an InputStream to theonSuccess(NewCall, InputStream, String)callback. -
FileCallback
Constructor that specifies a destination file path. When used, the response body will be saved to this file, and theonSuccess(NewCall, File, String)callback will be invoked.- Parameters:
fileAbsolutePath- The absolute path of the file to save the response body to.
-
-
Method Details
-
onResponse
Handles the successful HTTP response. This method either saves the response body to the specified file or provides it as anInputStreamto the appropriateonSuccesscallback.- Specified by:
onResponsein interfaceCallback- Parameters:
call- TheNewCallthat resulted in this response.response- The HTTPResponse.id- The unique ID of the request.
-
onSuccess
Callback invoked when the response body has been successfully saved to a file. Subclasses should override this method to handle the downloaded file. -
onSuccess
Callback invoked when no destination file is specified. The response body is provided as anInputStream. Subclasses should override this method to process the stream. Note: The caller is responsible for closing the stream.- Parameters:
call- TheNewCallthat resulted in this response.fileStream- AnInputStreamof the response body.id- The unique ID of the request.
-