java.lang.Object
java.io.InputStream
org.miaixz.bus.http.plugin.httpv.ProgressStream
- All Implemented Interfaces:
Closeable,AutoCloseable
An
InputStream decorator that monitors the progress of data being read. It wraps an existing InputStream and
invokes a callback with progress updates as data is consumed from the stream.- Since:
- Java 17+
- Author:
- Kimi Liu
-
Constructor Summary
ConstructorsConstructorDescriptionProgressStream(InputStream input, Callback<Progress> onProcess, long totalBytes, long stepBytes, long doneBytes, Executor callbackExecutor) Constructs a new ProgressStream. -
Method Summary
Modifier and TypeMethodDescriptionintread()Reads the next byte of data from the input stream and updates the progress.Methods inherited from class java.io.InputStream
available, close, mark, markSupported, nullInputStream, read, read, readAllBytes, readNBytes, readNBytes, reset, skip, skipNBytes, transferTo
-
Constructor Details
-
ProgressStream
public ProgressStream(InputStream input, Callback<Progress> onProcess, long totalBytes, long stepBytes, long doneBytes, Executor callbackExecutor) Constructs a new ProgressStream.- Parameters:
input- The actual input stream to wrap.onProcess- The callback to receive progress updates.totalBytes- The total number of bytes expected from the stream.stepBytes- The interval in bytes for progress updates.doneBytes- The initial number of bytes already considered read (for resuming downloads).callbackExecutor- The executor to run the callback on.
-
-
Method Details
-
read
Reads the next byte of data from the input stream and updates the progress.- Specified by:
readin classInputStream- Returns:
- the next byte of data, or
-1if the end of the stream is reached. - Throws:
IOException- if an I/O error occurs.
-