Module bus.http

Class ProgressStream

java.lang.Object
java.io.InputStream
org.miaixz.bus.http.plugin.httpv.ProgressStream
All Implemented Interfaces:
Closeable, AutoCloseable

public class ProgressStream extends InputStream
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 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

      public int read() throws IOException
      Reads the next byte of data from the input stream and updates the progress.
      Specified by:
      read in class InputStream
      Returns:
      the next byte of data, or -1 if the end of the stream is reached.
      Throws:
      IOException - if an I/O error occurs.