Package com.storedobject.ui.util
Class DownloadStream
java.lang.Object
com.storedobject.ui.util.DownloadStream
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDownloadStream(ContentProducer producer, String contentType, String fileName) Creates a new instance of DownloadStream. -
Method Summary
Modifier and TypeMethodDescriptionintGets the size of the download buffer.longGets length of cache expiration time.static StringgetContentDispositionFilename(String filename) Returns the filename formatted for inclusion in a Content-Disposition header.Gets stream content type.Returns the file name.getParameter(String name) Gets a parameter for download stream.Gets the names of the parameters.static Stringrfc5987Encode(String value) Encodes the given string to UTF-8value-charsas defined in RFC5987 for use in e.g. theContent-DispositionHTTP header.voidsetBufferSize(int bufferSize) Sets the size of the download buffer.voidsetCacheTime(long cacheTime) Sets length of cache expiration time.voidsetContentType(String contentType) Sets stream content type.voidsetFileName(String fileName) Sets the file name.voidsetParameter(String name, String value) Sets a parameter for download stream.voidwriteResponse(com.vaadin.flow.server.VaadinRequest request, com.vaadin.flow.server.VaadinResponse response) Writes this download stream to a Vaadin response.
-
Field Details
-
CONTENT_DISPOSITION
- See Also:
-
DEFAULT_CACHE_TIME
public static final long DEFAULT_CACHE_TIME- See Also:
-
DEFAULT_BUFFER_SIZE
public static final int DEFAULT_BUFFER_SIZE- See Also:
-
-
Constructor Details
-
DownloadStream
Creates a new instance of DownloadStream.- Parameters:
producer- Content producercontentType- Mime type of the contentfileName- Name of the file (for the browser to save the content)
-
-
Method Details
-
getContentType
-
setContentType
Sets stream content type.- Parameters:
contentType- the contentType to set
-
getFileName
-
setFileName
Sets the file name.- Parameters:
fileName- the file name to set.
-
setParameter
Sets a parameter for download stream. Parameters are optional information about the downloadable stream and their meaning depends on the used adapter. For example in WebAdapter they are interpreted as HTTP response headers.If the parameters by this name exists, the old value is replaced.
- Parameters:
name- the Name of the parameter to set.value- the Value of the parameter to set.
-
getParameter
Gets a parameter for download stream. Parameters are optional information about the downloadable stream and their meaning depends on the used adapter. For example in WebAdapter they are interpreted as HTTP response headers.- Parameters:
name- the Name of the parameter to set.- Returns:
- Value of the parameter or null if the parameter does not exist.
-
getParameterNames
-
getCacheTime
public long getCacheTime()Gets length of cache expiration time. This gives the adapter the possibility cache streams sent to the client. The caching may be made in adapter or at the client if the client supports caching. Default isDEFAULT_CACHE_TIME.- Returns:
- Cache time in milliseconds
-
setCacheTime
public void setCacheTime(long cacheTime) Sets length of cache expiration time. This gives the adapter the possibility cache streams sent to the client. The caching may be made in adapter or at the client if the client supports caching. Zero or negative value disables the caching of this stream.- Parameters:
cacheTime- the cache time in milliseconds.
-
getBufferSize
public int getBufferSize()Gets the size of the download buffer.- Returns:
- int The size of the buffer in bytes.
-
setBufferSize
public void setBufferSize(int bufferSize) Sets the size of the download buffer.- Parameters:
bufferSize- the size of the buffer in bytes.
-
writeResponse
public void writeResponse(com.vaadin.flow.server.VaadinRequest request, com.vaadin.flow.server.VaadinResponse response) throws IOException Writes this download stream to a Vaadin response. This takes care of setting response headers according to what is defined in this download stream (getContentType(),getCacheTime(),getFileName()) and transferring the data from the stream to the response. Defined parameters (getParameterNames()) are also included as headers in the response. If there is a parameter namedLocation, a redirect (302 Moved temporarily) is sent instead of the contents of this stream.- Parameters:
request- the request for which the response should be writtenresponse- the Vaadin response to write this download stream to- Throws:
IOException- Passed through from the Vaadin response
-
getContentDispositionFilename
Returns the filename formatted for inclusion in a Content-Disposition header. Includes both a plain version of the name and a UTF-8 version- Parameters:
filename- The filename to include- Returns:
- A value for inclusion in a Content-Disposition header
-
rfc5987Encode
-