Package com.vaadin.server
Class StreamResource
- java.lang.Object
-
- com.vaadin.server.StreamResource
-
- All Implemented Interfaces:
ConnectorResource,Resource,Serializable
public class StreamResource extends Object implements ConnectorResource
StreamResourceis a resource provided to the client directly by the application.- Since:
- 3.0
- Author:
- Vaadin Ltd.
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceStreamResource.StreamSourceInterface implemented by the source of a StreamResource.
-
Field Summary
-
Fields inherited from interface com.vaadin.server.ConnectorResource
CONNECTOR_PATH
-
-
Constructor Summary
Constructors Constructor Description StreamResource(StreamResource.StreamSource streamSource, String filename)Creates a new stream resource for downloading from stream.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object obj)intgetBufferSize()Gets the size of the download buffer used for this resource.longgetCacheTime()Gets the length of cache expiration time.StringgetFilename()Gets the filename.StringgetMIMEType()Gets the MIME type of the resource.DownloadStreamgetStream()Gets resource as stream.StreamResource.StreamSourcegetStreamSource()Returns the source for thisStreamResource.inthashCode()voidsetBufferSize(int bufferSize)Sets the size of the download buffer used for this resource.voidsetCacheTime(long cacheTime)Sets the length of cache expiration time.voidsetFilename(String filename)Sets the filename.voidsetMIMEType(String mimeType)Sets the mime type of the resource.voidsetStreamSource(StreamResource.StreamSource streamSource)Sets the source for thisStreamResource.
-
-
-
Constructor Detail
-
StreamResource
public StreamResource(StreamResource.StreamSource streamSource, String filename)
Creates a new stream resource for downloading from stream.- Parameters:
streamSource- the source Stream.filename- the name of the file.
-
-
Method Detail
-
getMIMEType
public String getMIMEType()
Description copied from interface:ResourceGets the MIME type of the resource.- Specified by:
getMIMETypein interfaceResource- Returns:
- the MIME type of the resource.
- See Also:
Resource.getMIMEType()
-
setMIMEType
public void setMIMEType(String mimeType)
Sets the mime type of the resource.- Parameters:
mimeType- the MIME type to be set.
-
getStreamSource
public StreamResource.StreamSource getStreamSource()
Returns the source for thisStreamResource. StreamSource is queried when the resource is about to be streamed to the client.- Returns:
- Source of the StreamResource.
-
setStreamSource
public void setStreamSource(StreamResource.StreamSource streamSource)
Sets the source for thisStreamResource.StreamSourceis queried when the resource is about to be streamed to the client.- Parameters:
streamSource- the source to set.
-
getFilename
public String getFilename()
Gets the filename.- Specified by:
getFilenamein interfaceConnectorResource- Returns:
- the filename.
-
setFilename
public void setFilename(String filename)
Sets the filename.- Parameters:
filename- the filename to set.
-
getStream
public DownloadStream getStream()
Description copied from interface:ConnectorResourceGets resource as stream.Note that this method is called while the session is locked to prevent race conditions but the methods in the returned
DownloadStreamare assumed to be unrelated to the VaadinSession and are called without holding session locks (to prevent locking the session during long file downloads).- Specified by:
getStreamin interfaceConnectorResource- Returns:
- A download stream which produces the resource content
-
getBufferSize
public int getBufferSize()
Gets the size of the download buffer used for this resource.If the buffer size is 0, the buffer size is decided by the terminal adapter. The default value is 0.
- Returns:
- the size of the buffer in bytes.
-
setBufferSize
public void setBufferSize(int bufferSize)
Sets the size of the download buffer used for this resource.- Parameters:
bufferSize- the size of the buffer in bytes.
-
getCacheTime
public long getCacheTime()
Gets the 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 isDownloadStream.DEFAULT_CACHETIME.- Returns:
- Cache time in milliseconds.
-
setCacheTime
public void setCacheTime(long cacheTime)
Sets the 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.
-
-