Package com.storedobject.vaadin
Class StreamDownloader
java.lang.Object
com.storedobject.vaadin.StreamDownloader
- All Implemented Interfaces:
com.vaadin.flow.server.streams.InputStreamDownloadCallback,Serializable
public class StreamDownloader
extends Object
implements com.vaadin.flow.server.streams.InputStreamDownloadCallback
A utility class for downloading content via an InputStream. The class provides functionality
to specify the content type, file name, and source of the stream data, and it implements a
callback mechanism to handle download completion events.
- Author:
- Syam
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionStreamDownloader(Supplier<InputStream> streamProvider, String contentType) Creates a StreamDownloader instance with the specified stream provider and content type.StreamDownloader(Supplier<InputStream> streamProvider, String contentType, String fileName) Constructs a StreamDownloader instance. -
Method Summary
Modifier and TypeMethodDescriptioncom.vaadin.flow.server.streams.DownloadResponsecomplete(com.vaadin.flow.server.streams.DownloadEvent downloadEvent) Retrieves the name of the file associated with the downloader.voidsetFileName(String fileName) Sets the file name to be used when downloading or processing a file.
-
Constructor Details
-
StreamDownloader
Creates a StreamDownloader instance with the specified stream provider and content type.- Parameters:
streamProvider- ASupplierthat provides anInputStreamfor downloading the content.contentType- The MIME type of the content to be downloaded.
-
StreamDownloader
Constructs a StreamDownloader instance.- Parameters:
streamProvider- A supplier that provides the InputStream to be downloaded.contentType- The content type of the download (e.g., "application/pdf").fileName- The name of the file to be downloaded. If null, a default file name is generated.
-
-
Method Details
-
getFileName
Retrieves the name of the file associated with the downloader.- Returns:
- The name of the file as a String. If no file name was explicitly set, it returns a default-generated file name.
-
setFileName
Sets the file name to be used when downloading or processing a file. If the provided file name is null, no changes will be made.- Parameters:
fileName- The file name to set. Must not be null to take effect.
-
complete
public com.vaadin.flow.server.streams.DownloadResponse complete(com.vaadin.flow.server.streams.DownloadEvent downloadEvent) throws IOException - Specified by:
completein interfacecom.vaadin.flow.server.streams.InputStreamDownloadCallback- Throws:
IOException
-