Module bus.http

Class ProgressBody

java.lang.Object
org.miaixz.bus.http.bodys.RequestBody
org.miaixz.bus.http.plugin.httpv.ProgressBody

public class ProgressBody extends RequestBody
A RequestBody decorator that monitors the progress of an upload. It wraps an existing RequestBody and invokes a callback with progress updates as data is being written to the network.
Since:
Java 17+
Author:
Kimi Liu
  • Constructor Details

    • ProgressBody

      public ProgressBody(RequestBody requestBody, Callback<Progress> onProcess, Executor callbackExecutor, long contentLength, long stepBytes)
      Constructs a new ProgressBody.
      Parameters:
      requestBody - The actual request body to wrap.
      onProcess - The callback to receive progress updates.
      callbackExecutor - The executor to run the callback on.
      contentLength - The total length of the request body.
      stepBytes - The interval in bytes for progress updates.
  • Method Details

    • contentLength

      public long contentLength()
      Description copied from class: RequestBody
      Returns the number of bytes that will be written to sink when this request body is transmitted, or -1 if that count is unknown.
      Overrides:
      contentLength in class RequestBody
      Returns:
      The content length.
    • contentType

      public org.miaixz.bus.core.lang.MediaType contentType()
      Description copied from class: RequestBody
      Returns the media type of this request body.
      Specified by:
      contentType in class RequestBody
      Returns:
      The media type, which may be null.
    • writeTo

      public void writeTo(org.miaixz.bus.core.io.sink.BufferSink sink) throws IOException
      Description copied from class: RequestBody
      Writes the content of this request body to the given sink.
      Specified by:
      writeTo in class RequestBody
      Parameters:
      sink - The sink to write to.
      Throws:
      IOException - if an I/O error occurs during writing.