1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 import sys
17
19 """Downloadable stream.
20
21 @author: Vaadin Ltd.
22 @author: Richard Lincoln
23 @version: 1.1.2
24 """
25
26 MAX_CACHETIME = sys.maxint
27
28 DEFAULT_CACHETIME = 1000 * 60 * 60 * 24
29
30 - def __init__(self, stream, contentType, fileName):
31 """Creates a new instance of DownloadStream."""
32 self._stream = None
33 self._contentType = None
34 self._fileName = None
35 self._params = None
36 self._cacheTime = self.DEFAULT_CACHETIME
37 self._bufferSize = 0
38
39 self.setStream(stream)
40 self.setContentType(contentType)
41 self.setFileName(fileName)
42
43
45 """Gets downloadable stream.
46
47 @return: output stream.
48 """
49 return self._stream
50
51
53 """Sets the stream.
54
55 @param stream:
56 The stream to set
57 """
58 self._stream = stream
59
60
61 - def getContentType(self):
62 """Gets stream content type.
63
64 @return: type of the stream content.
65 """
66 return self._contentType
67
68
69 - def setContentType(self, contentType):
70 """Sets stream content type.
71
72 @param contentType:
73 the contentType to set
74 """
75 self._contentType = contentType
76
77
79 """Returns the file name.
80
81 @return: the name of the file.
82 """
83 return self._fileName
84
85
87 """Sets the file name.
88
89 @param fileName:
90 the file name to set.
91 """
92 self._fileName = fileName
93
94
96 """Sets a paramater for download stream. Parameters are optional
97 information about the downloadable stream and their meaning depends
98 on the used adapter. For example in WebAdapter they are interpreted
99 as HTTP response headers.
100
101 If the parameters by this name exists, the old value is replaced.
102
103 @param name:
104 the Name of the parameter to set.
105 @param value:
106 the Value of the parameter to set.
107 """
108 if self._params is None:
109 self._params = dict()
110 self._params[name] = value
111
112
114 """Gets a paramater for download stream. Parameters are optional
115 information about the downloadable stream and their meaning depends
116 on the used adapter. For example in WebAdapter they are interpreted
117 as HTTP response headers.
118
119 @param name:
120 the Name of the parameter to set.
121 @return: Value of the parameter or null if the parameter does not exist.
122 """
123 if self._params is not None:
124 return self._params.get(name)
125 return None
126
127
129 """Gets the names of the parameters.
130
131 @return: Iterator of names or null if no parameters are set.
132 """
133 if self._params is not None:
134 return self._params.keys()
135 return None
136
137
139 """Gets length of cache expiration time. This gives the adapter the
140 possibility cache streams sent to the client. The caching may be made
141 in adapter or at the client if the client supports caching. Default
142 is C{DEFAULT_CACHETIME}.
143
144 @return: Cache time in milliseconds
145 """
146 return self._cacheTime
147
148
150 """Sets length of cache expiration time. This gives the adapter the
151 possibility cache streams sent to the client. The caching may be made
152 in adapter or at the client if the client supports caching. Zero or
153 negavive value disbales the caching of this stream.
154
155 @param cacheTime:
156 the cache time in milliseconds.
157 """
158 self._cacheTime = cacheTime
159
160
162 """Gets the size of the download buffer.
163
164 @return: int The size of the buffer in bytes.
165 """
166 return self._bufferSize
167
168
170 """Sets the size of the download buffer.
171
172 @param bufferSize:
173 the size of the buffer in bytes.
174 """
175 self._bufferSize = bufferSize
176