Package muntjac :: Package terminal :: Module download_stream
[hide private]
[frames] | no frames]

Source Code for Module muntjac.terminal.download_stream

  1  # Copyright (C) 2012 Vaadin Ltd.  
  2  # Copyright (C) 2012 Richard Lincoln 
  3  #  
  4  # Licensed under the Apache License, Version 2.0 (the "License");  
  5  # you may not use this file except in compliance with the License.  
  6  # You may obtain a copy of the License at  
  7  #  
  8  #     http://www.apache.org/licenses/LICENSE-2.0  
  9  #  
 10  # Unless required by applicable law or agreed to in writing, software  
 11  # distributed under the License is distributed on an "AS IS" BASIS,  
 12  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
 13  # See the License for the specific language governing permissions and  
 14  # limitations under the License. 
 15   
 16  import sys 
 17   
18 -class DownloadStream(object):
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
44 - def getStream(self):
45 """Gets downloadable stream. 46 47 @return: output stream. 48 """ 49 return self._stream
50 51
52 - def setStream(self, stream):
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
78 - def getFileName(self):
79 """Returns the file name. 80 81 @return: the name of the file. 82 """ 83 return self._fileName
84 85
86 - def setFileName(self, fileName):
87 """Sets the file name. 88 89 @param fileName: 90 the file name to set. 91 """ 92 self._fileName = fileName
93 94
95 - def setParameter(self, name, value):
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
113 - def getParameter(self, name):
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
128 - def getParameterNames(self):
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
138 - def getCacheTime(self):
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
149 - def setCacheTime(self, cacheTime):
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
161 - def getBufferSize(self):
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
169 - def setBufferSize(self, bufferSize):
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