java.lang.Object
org.miaixz.bus.http.plugin.httpv.Downloads
Manages the process of downloading content from an
InputStream to a File. This class provides
controls for pausing, resuming, and canceling the download, and supports callbacks for success and failure events.- Since:
- Java 17+
- Author:
- Kimi Liu
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassProvides methods to control the state of an ongoing download.classEncapsulates information about a download failure.static interfaceA listener interface for globally intercepting download events. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanA temporary flag to indicate that the next callback should be executed on an I/O thread. -
Constructor Summary
ConstructorsConstructorDescriptionDownloads(File file, InputStream input, CoverTasks.Executor executor, long skipBytes) Constructs a new download handler. -
Method Summary
Modifier and TypeMethodDescriptiongetCtrl()Gets the controller for this download task.nextOnIO()Specifies that the next callback to be set (e.g., onSuccess, onFailure) should be executed on an I/O thread.Enables append mode.setBuffSize(int buffSize) Sets the buffer size for reading from the input stream.setFilePointer(long seekBytes) Sets the file pointer to a specific position.setOnFailure(Callback<Downloads.Failure> onFailure) Sets the callback to be executed when the download fails.setOnSuccess(Callback<File> onSuccess) Sets the callback to be executed when the download completes successfully.start()Starts the download process asynchronously on an I/O thread.
-
Field Details
-
nextOnIO
protected boolean nextOnIOA temporary flag to indicate that the next callback should be executed on an I/O thread.
-
-
Constructor Details
-
Downloads
Constructs a new download handler.- Parameters:
file- The destination file.input- The source input stream.executor- The task executor.skipBytes- The number of bytes to skip from the beginning of the input stream (used for resuming).
-
-
Method Details
-
setBuffSize
Sets the buffer size for reading from the input stream. The default size is 2048 bytes.- Parameters:
buffSize- The buffer size in bytes.- Returns:
- this
Downloadsinstance for chaining.
-
setAppended
Enables append mode. When set, the download will append data to the file, which is useful for resuming downloads or chunked downloading.- Returns:
- this
Downloadsinstance for chaining.
-
setFilePointer
Sets the file pointer to a specific position. Writing will start from this byte offset.- Parameters:
seekBytes- The number of bytes to skip from the beginning of the file.- Returns:
- this
Downloadsinstance for chaining.
-
nextOnIO
Specifies that the next callback to be set (e.g., onSuccess, onFailure) should be executed on an I/O thread.- Returns:
- this
Downloadsinstance for chaining.
-
setOnSuccess
Sets the callback to be executed when the download completes successfully.- Parameters:
onSuccess- The success callback.- Returns:
- this
Downloadsinstance for chaining.
-
setOnFailure
Sets the callback to be executed when the download fails.- Parameters:
onFailure- The failure callback.- Returns:
- this
Downloadsinstance for chaining.
-
start
Starts the download process asynchronously on an I/O thread.- Returns:
- A
Downloads.Controlobject to manage the download (pause, resume, cancel).
-
getCtrl
Gets the controller for this download task.- Returns:
- The
Downloads.Controlobject.
-