Module bus.http

Class FileInterceptor

java.lang.Object
org.miaixz.bus.http.plugin.httpz.FileInterceptor
All Implemented Interfaces:
Interceptor, ProgressListener

public abstract class FileInterceptor extends Object implements Interceptor, ProgressListener
An abstract Interceptor that adds a download progress listener to the response body. Subclasses must implement the updateProgress(long, long, boolean) method to handle progress updates.
Since:
Java 17+
Author:
Kimi Liu
  • Constructor Details

    • FileInterceptor

      public FileInterceptor()
  • Method Details

    • intercept

      public Response intercept(NewChain chain) throws IOException
      Intercepts the network response to wrap the original response body with a progress-monitoring body.
      Specified by:
      intercept in interface Interceptor
      Parameters:
      chain - The interceptor chain.
      Returns:
      The modified Response with a progress-aware body.
      Throws:
      IOException - if an I/O error occurs during the request.
    • updateProgress

      public abstract void updateProgress(long downloadLenth, long totalLength, boolean isFinish)
      An abstract callback method that is invoked with download progress updates.
      Specified by:
      updateProgress in interface ProgressListener
      Parameters:
      downloadLenth - The number of bytes downloaded so far.
      totalLength - The total size of the file in bytes.
      isFinish - true if the download is complete, false otherwise.