com.vaadin.terminal
Class DownloadStream

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

public class DownloadStream
extends Object
implements Serializable

Downloadable stream.

Since:
3.0
Version:
7.0.0.alpha3
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(InputStream stream, String contentType, 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.
 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 writeTo(WrappedResponse response)
          Writes this download stream to a wrapped 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(InputStream stream,
                      String contentType,
                      String fileName)
Creates a new instance of DownloadStream.

Method Detail

getStream

public InputStream getStream()
Gets downloadable stream.

Returns:
output stream.

setStream

public void setStream(InputStream stream)
Sets the stream.

Parameters:
stream - The stream to set

getContentType

public String getContentType()
Gets stream content type.

Returns:
type of the stream content.

setContentType

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

Parameters:
contentType - the contentType to set

getFileName

public String getFileName()
Returns the file name.

Returns:
the name of the file.

setFileName

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

Parameters:
fileName - the file name to set.

setParameter

public void setParameter(String name,
                         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 String getParameter(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 Iterator<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

writeTo

public void writeTo(WrappedResponse response)
             throws IOException
Writes this download stream to a wrapped 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:
response - the wrapped response to write this download stream to
Throws:
IOException - passed through from the wrapped response
Since:
7.0


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