Interface TransferProgressListener

All Superinterfaces:
Serializable

public interface TransferProgressListener extends Serializable
Interface for listening to transfer progress events.

Implementations of this interface can be used to monitor the progress of file transfers, such as downloads or uploads.

It uses UI.access(com.vaadin.flow.server.Command) to send UI changes from progress listeners when the download or upload request is being handled. Thus, it needs Push to be enabled in the application.

Since:
24.8
  • Field Details

    • DEFAULT_PROGRESS_REPORT_INTERVAL_IN_BYTES

      static final long DEFAULT_PROGRESS_REPORT_INTERVAL_IN_BYTES
      Default data transfer progress report interval in bytes.

      Chosen as a reasonable default for file sizes > 1 MB - 10-20% of the total size.

      See Also:
  • Method Details

    • onStart

      default void onStart(TransferContext context)
      Called when the data transfer is started.

      The call of this method is wrapped by the UI.access(com.vaadin.flow.server.Command) to send UI changes defined here when the download or upload request is being handled. Thus, no need to call UI.access(com.vaadin.flow.server.Command) in the implementation of this method. This needs Push to be enabled in the application to properly send the UI changes to client.

      Parameters:
      context - the context of the transfer
    • onProgress

      default void onProgress(TransferContext context, long transferredBytes, long totalBytes)
      Called periodically during the transfer to report progress.

      The call of this method is wrapped by the UI.access(com.vaadin.flow.server.Command) to send UI changes defined here asynchronously when the download or upload request is being handled. This needs Push to be enabled in the application to properly send the UI changes to client.

      The default progress report internal is 65536 bytes. To change it, override progressReportInterval().

      Parameters:
      context - the context of the transfer
      transferredBytes - the number of bytes transferred so far
      totalBytes - the total number of bytes to be transferred or -1 if total number is unknown in advance, e.g. when reading from an input stream
    • onError

      default void onError(TransferContext context, IOException reason)
      Called when the transfer is failed.

      The call of this method is wrapped by the UI.access(com.vaadin.flow.server.Command) to send UI changes defined here when the download or upload request is being handled. Thus, no need to call UI.access(com.vaadin.flow.server.Command) in the implementation of this method. This needs Push to be enabled in the application to properly send the UI changes to client.

      Parameters:
      context - the context of the transfer
      reason - the origin I/O exception that terminated the transfer
    • onComplete

      default void onComplete(TransferContext context, long transferredBytes)
      Called when the transfer is started.

      The call of this method is wrapped by the UI.access(com.vaadin.flow.server.Command) to send UI changes defined here when the download or upload request is being handled. Thus, no need to call UI.access(com.vaadin.flow.server.Command) in the implementation of this method. This needs Push to be enabled in the application to properly send the UI changes to client.

      Parameters:
      context - the context of the transfer
      transferredBytes - the total number of bytes transferred
    • progressReportInterval

      default long progressReportInterval()
      Returns the interval in bytes for reporting progress.

      -1 to not report progress.

      The default value is 65536 bytes.

      Returns:
      the interval in bytes