public class DownloadStream extends Object implements Serializable
Note that the methods in a DownloadStream are called without locking the session to prevent locking the session during long file downloads. If your DownloadStream uses anything from the session, you must handle the locking.
| Modifier and Type | Field and Description |
|---|---|
static String |
CONTENT_DISPOSITION |
static long |
DEFAULT_CACHETIME
Default cache time.
|
static long |
MAX_CACHETIME
Maximum cache time.
|
| Constructor and Description |
|---|
DownloadStream(InputStream stream,
String contentType,
String fileName)
Creates a new instance of DownloadStream.
|
| Modifier and Type | Method and Description |
|---|---|
int |
getBufferSize()
Gets the size of the download buffer.
|
long |
getCacheTime()
Gets length of cache expiration time.
|
static String |
getContentDispositionFilename(String filename)
Returns the filename formatted for inclusion in a Content-Disposition
header.
|
String |
getContentType()
Gets stream content type.
|
String |
getFileName()
Returns the file name.
|
String |
getParameter(String name)
Gets a paramater for download stream.
|
Iterator<String> |
getParameterNames()
Gets the names of the parameters.
|
InputStream |
getStream()
Gets downloadable stream.
|
void |
setBufferSize(int bufferSize)
Sets the size of the download buffer.
|
void |
setCacheTime(long cacheTime)
Sets length of cache expiration time.
|
void |
setContentType(String contentType)
Sets stream content type.
|
void |
setFileName(String fileName)
Sets the file name.
|
void |
setParameter(String name,
String value)
Sets a paramater for download stream.
|
void |
setStream(InputStream stream)
Sets the stream.
|
void |
writeResponse(VaadinRequest request,
VaadinResponse response)
Writes this download stream to a Vaadin response.
|
public static final String CONTENT_DISPOSITION
public static final long MAX_CACHETIME
public static final long DEFAULT_CACHETIME
public DownloadStream(InputStream stream, String contentType, String fileName)
public InputStream getStream()
public void setStream(InputStream stream)
stream - The stream to setpublic String getContentType()
public void setContentType(String contentType)
contentType - the contentType to setpublic String getFileName()
public void setFileName(String fileName)
fileName - the file name to set.public void setParameter(String name, String value)
name - the Name of the parameter to set.value - the Value of the parameter to set.public String getParameter(String name)
name - the Name of the parameter to set.public Iterator<String> getParameterNames()
public long getCacheTime()
DEFAULT_CACHETIME.public void setCacheTime(long cacheTime)
cacheTime - the cache time in milliseconds.public int getBufferSize()
public void setBufferSize(int bufferSize)
bufferSize - the size of the buffer in bytes.public void writeResponse(VaadinRequest request, VaadinResponse response) throws IOException
getContentType(), getCacheTime(),
getFileName()) and transferring the data from the stream (
getStream()) to the response. Defined parameters (
getParameterNames()) are also included as headers in the
response. If there's is a parameter named Location, a
redirect (302 Moved temporarily) is sent instead of the contents of this
stream.request - the request for which the response should be writtenresponse - the Vaadin response to write this download stream toIOException - passed through from the Vaadin responsepublic static String getContentDispositionFilename(String filename)
filename - The filename to includeCopyright © 2023 Vaadin Ltd. All rights reserved.