Package com.vaadin.flow.server.streams
Class ClassDownloadHandler
java.lang.Object
com.vaadin.flow.server.streams.TransferProgressAwareHandler<DownloadEvent,R>
com.vaadin.flow.server.streams.AbstractDownloadHandler<ClassDownloadHandler>
com.vaadin.flow.server.streams.ClassDownloadHandler
- All Implemented Interfaces:
DownloadHandler
,ElementRequestHandler
,Serializable
Download handler for serving a class resource.
For instance for the file resources/com/example/ui/MyData.json
and
class com.example.ui.MyData
the definition would be
forClassResource(MyData.class, "MyData.json")
- Since:
- 24.8
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionClassDownloadHandler
(Class<?> clazz, String resourceName) Create a class resource download handler with the resource name as the url postfix (file name).ClassDownloadHandler
(Class<?> clazz, String resourceName, String fileName) Create a class resource download handler with the given file name as the url postfix. -
Method Summary
Modifier and TypeMethodDescriptionOptional URL postfix allows appending an application-controlled string, e.g.void
handleDownloadRequest
(DownloadEvent downloadEvent) Method that is called when the client wants to download from the url stored for this specific handler registration.Methods inherited from class com.vaadin.flow.server.streams.AbstractDownloadHandler
getContentType, getTransferContext, inline, isInline
Methods inherited from class com.vaadin.flow.server.streams.TransferProgressAwareHandler
addTransferProgressListener, getListeners, notifyError, onProgress, onProgress, onProgress, onProgress, whenComplete, whenComplete, whenStart, whenStart
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.vaadin.flow.server.streams.DownloadHandler
handleRequest
Methods inherited from interface com.vaadin.flow.server.streams.ElementRequestHandler
getDisabledUpdateMode, isAllowInert
-
Constructor Details
-
ClassDownloadHandler
Create a class resource download handler with the resource name as the url postfix (file name).The downloaded file name and download URL postfix will be set to
resourceName
. If you want to use a different file name, useClassDownloadHandler(Class, String, String)
instead.- Parameters:
clazz
- class to use for getting resourceresourceName
- resource to get
-
ClassDownloadHandler
Create a class resource download handler with the given file name as the url postfix.The downloaded file name and download URL postfix will be set to
fileName
.- Parameters:
clazz
- class to use for getting resourceresourceName
- resource to getfileName
- download file name that overridesresourceName
and also used as a download request URL postfix
-
-
Method Details
-
handleDownloadRequest
Description copied from interface:DownloadHandler
Method that is called when the client wants to download from the url stored for this specific handler registration.- Parameters:
downloadEvent
- download event containing the necessary data for writing the response- Throws:
IOException
- if an IO error occurred during download
-
getUrlPostfix
Description copied from interface:ElementRequestHandler
Optional URL postfix allows appending an application-controlled string, e.g. the logical name of the target file, to the end of the otherwise random-looking download URL. If defined, requests that would otherwise be routable are still rejected if the postfix is missing or invalid. Postfix changes the last segment in the resource url.- Returns:
- String optional URL postfix, or
null
for "".
-