com.vaadin.server
Class DownloadStream

java.lang.Object
  extended by com.vaadin.server.DownloadStream
All Implemented Interfaces:
java.io.Serializable

public class DownloadStream
extends java.lang.Object
implements java.io.Serializable

Downloadable stream.

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.

Since:
3.0
Author:
Vaadin Ltd.
See Also:
Serialized Form

Field Summary
static long DEFAULT_CACHETIME
          Default cache time.
static long MAX_CACHETIME
          Maximum cache time.
 
Constructor Summary
DownloadStream(java.io.InputStream stream, java.lang.String contentType, java.lang.String fileName)
          Creates a new instance of DownloadStream.
 
Method Summary
 int getBufferSize()
          Gets the size of the download buffer.
 long getCacheTime()
          Gets length of cache expiration time.
 java.lang.String getContentType()
          Gets stream content type.
 java.lang.String getFileName()
          Returns the file name.
 java.lang.String getParameter(java.lang.String name)
          Gets a paramater for download stream.
 java.util.Iterator<java.lang.String> getParameterNames()
          Gets the names of the parameters.
 java.io.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(java.lang.String contentType)
          Sets stream content type.
 void setFileName(java.lang.String fileName)
          Sets the file name.
 void setParameter(java.lang.String name, java.lang.String value)
          Sets a paramater for download stream.
 void setStream(java.io.InputStream stream)
          Sets the stream.
 void writeResponse(VaadinRequest request, VaadinResponse response)
          Writes this download stream to a Vaadin response.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_CACHETIME

public static final long MAX_CACHETIME
Maximum cache time.

See Also:
Constant Field Values

DEFAULT_CACHETIME

public static final long DEFAULT_CACHETIME
Default cache time.

See Also:
Constant Field Values
Constructor Detail

DownloadStream

public DownloadStream(java.io.InputStream stream,
                      java.lang.String contentType,
                      java.lang.String fileName)
Creates a new instance of DownloadStream.

Method Detail

getStream

public java.io.InputStream getStream()
Gets downloadable stream.

Returns:
output stream.

setStream

public void setStream(java.io.InputStream stream)
Sets the stream.

Parameters:
stream - The stream to set

getContentType

public java.lang.String getContentType()
Gets stream content type.

Returns:
type of the stream content.

setContentType

public void setContentType(java.lang.String contentType)
Sets stream content type.

Parameters:
contentType - the contentType to set

getFileName

public java.lang.String getFileName()
Returns the file name.

Returns:
the name of the file.

setFileName

public void setFileName(java.lang.String fileName)
Sets the file name.

Parameters:
fileName - the file name to set.

setParameter

public void setParameter(java.lang.String name,
                         java.lang.String value)
Sets a paramater 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

public java.lang.String getParameter(java.lang.String name)
Gets a paramater 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

public java.util.Iterator<java.lang.String> getParameterNames()
Gets the names of the parameters.

Returns:
Iterator of names or null if no parameters are set.

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 is DEFAULT_CACHETIME.

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 negavive value disbales 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.
Since:
7.0

writeResponse

public void writeResponse(VaadinRequest request,
                          VaadinResponse response)
                   throws java.io.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 ( 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.

Parameters:
request - the request for which the response should be written
response - the Vaadin response to write this download stream to
Throws:
java.io.IOException - passed through from the Vaadin response
Since:
7.0


Copyright © 2000-2014 Vaadin Ltd. All Rights Reserved.