Interface TransferProgressListener
- All Superinterfaces:
Serializable
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final longDefault data transfer progress report interval in bytes. -
Method Summary
Modifier and TypeMethodDescriptiondefault voidonComplete(TransferContext context, long transferredBytes) Called when the transfer is started.default voidonError(TransferContext context, IOException reason) Called when the transfer is failed.default voidonProgress(TransferContext context, long transferredBytes, long totalBytes) Called periodically during the transfer to report progress.default voidonStart(TransferContext context) Called when the data transfer is started.default longReturns the interval in bytes for reporting progress.
-
Field Details
-
DEFAULT_PROGRESS_REPORT_INTERVAL_IN_BYTES
static final long DEFAULT_PROGRESS_REPORT_INTERVAL_IN_BYTESDefault 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
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 callUI.access(com.vaadin.flow.server.Command)in the implementation of this method. This needsPushto be enabled in the application to properly send the UI changes to client.- Parameters:
context- the context of the transfer
-
onProgress
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 needsPushto be enabled in the application to properly send the UI changes to client.The default progress report internal is
65536bytes. To change it, overrideprogressReportInterval().- Parameters:
context- the context of the transfertransferredBytes- the number of bytes transferred so fartotalBytes- the total number of bytes to be transferred or-1if total number is unknown in advance, e.g. when reading from an input stream
-
onError
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 callUI.access(com.vaadin.flow.server.Command)in the implementation of this method. This needsPushto be enabled in the application to properly send the UI changes to client.- Parameters:
context- the context of the transferreason- the origin I/O exception that terminated the transfer
-
onComplete
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 callUI.access(com.vaadin.flow.server.Command)in the implementation of this method. This needsPushto be enabled in the application to properly send the UI changes to client.- Parameters:
context- the context of the transfer
-
progressReportInterval
default long progressReportInterval()Returns the interval in bytes for reporting progress.-1to not report progress.The default value is
65536bytes.- Returns:
- the interval in bytes
-