001: /* *************************************************************************
002:
003: Millstone(TM)
004: Open Sourced User Interface Library for
005: Internet Development with Java
006:
007: Millstone is a registered trademark of IT Mill Ltd
008: Copyright (C) 2000-2005 IT Mill Ltd
009:
010: *************************************************************************
011:
012: This library is free software; you can redistribute it and/or
013: modify it under the terms of the GNU Lesser General Public
014: license version 2.1 as published by the Free Software Foundation.
015:
016: This library is distributed in the hope that it will be useful,
017: but WITHOUT ANY WARRANTY; without even the implied warranty of
018: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: Lesser General Public License for more details.
020:
021: You should have received a copy of the GNU Lesser General Public
022: License along with this library; if not, write to the Free Software
023: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024:
025: *************************************************************************
026:
027: For more information, contact:
028:
029: IT Mill Ltd phone: +358 2 4802 7180
030: Ruukinkatu 2-4 fax: +358 2 4802 7181
031: 20540, Turku email: info@itmill.com
032: Finland company www: www.itmill.com
033:
034: Primary source for MillStone information and releases: www.millstone.org
035:
036: ********************************************************************** */
037:
038: package org.millstone.base.terminal;
039:
040: import java.io.InputStream;
041: import java.util.HashMap;
042: import java.util.Iterator;
043: import java.util.Map;
044:
045: /** Downloadable stream.
046: *
047: * @author IT Mill Ltd.
048: * @version 3.1.1
049: * @since 3.0
050: */
051: public class DownloadStream {
052:
053: /** Maximum cache time. */
054: public static final long MAX_CACHETIME = Long.MAX_VALUE;
055:
056: /** Default cache time. */
057: public static final long DEFAULT_CACHETIME = 1000 * 60 * 60 * 24;
058:
059: private InputStream stream;
060: private String contentType;
061: private String fileName;
062: private Map params;
063: private long cacheTime = DEFAULT_CACHETIME;
064: private int bufferSize = 0;
065:
066: /** Creates a new instance of DownloadStream */
067: public DownloadStream(InputStream stream, String contentType,
068: String fileName) {
069: setStream(stream);
070: setContentType(contentType);
071: setFileName(fileName);
072: }
073:
074: /** Get downloadable stream.
075: * @return output stream.
076: */
077: public InputStream getStream() {
078: return this .stream;
079: }
080:
081: /** Sets the stream.
082: * @param stream The stream to set
083: */
084: public void setStream(InputStream stream) {
085: this .stream = stream;
086: }
087:
088: /** Get stream content type.
089: * @return type of the stream content.
090: */
091: public String getContentType() {
092: return this .contentType;
093: }
094:
095: /** Set stream content type.
096: * @param contentType The contentType to set
097: */
098: public void setContentType(String contentType) {
099: this .contentType = contentType;
100: }
101:
102: /** Returns the file name.
103: * @return The name of the file.
104: */
105: public String getFileName() {
106: return fileName;
107: }
108:
109: /** Sets the file name.
110: * @param fileName The file name to set
111: */
112: public void setFileName(String fileName) {
113: this .fileName = fileName;
114: }
115:
116: /** Set a paramater for download stream.
117: * Parameters are optional information about the downloadable stream
118: * and their meaning depends on the used adapter. For example in
119: * WebAdapter they are interpreted as HTTP response headers.
120: *
121: * If the parameters by this name exists, the old value is replaced.
122: *
123: * @param name Name of the parameter to set.
124: * @param value Value of the parameter to set.
125: */
126: public void setParameter(String name, String value) {
127: if (this .params == null) {
128: this .params = new HashMap();
129: }
130: this .params.put(name, value);
131: }
132:
133: /** Get a paramater for download stream.
134: * Parameters are optional information about the downloadable stream
135: * and their meaning depends on the used adapter. For example in
136: * WebAdapter they are interpreted as HTTP response headers.
137: * @param name Name of the parameter to set.
138: * @return Value of the parameter or null if the parameter does not exist.
139: */
140: public String getParameter(String name) {
141: if (this .params != null)
142: return (String) this .params.get(name);
143: return null;
144: }
145:
146: /** Get the names of the parameters.
147: * @return Iteraror of names or null if no parameters are set.
148: */
149: public Iterator getParameterNames() {
150: if (this .params != null)
151: return this .params.keySet().iterator();
152: return null;
153: }
154:
155: /** Get lenght of cache expiracy time.
156: * This gives the adapter the possibility cache streams sent to the client.
157: * The caching may be made in adapter or at the client if the client supports
158: * caching. Default is DEFAULT_CACHETIME.
159: * @return Cache time in milliseconds
160: */
161: public long getCacheTime() {
162: return cacheTime;
163: }
164:
165: /** Set lenght of cache expiracy time.
166: * This gives the adapter the possibility cache streams sent to the client.
167: * The caching may be made in adapter or at the client if the client supports
168: * caching. Zero or negavive value disbales the caching of this stream.
169: * @param cacheTime The cache time in milliseconds.
170: */
171: public void setCacheTime(long cacheTime) {
172: this .cacheTime = cacheTime;
173: }
174:
175: /** Get the size of the download buffer.
176: * @return int The size of the buffer in bytes.
177: */
178: public int getBufferSize() {
179: return bufferSize;
180: }
181:
182: /** Set the size of the download buffer.
183: * @param bufferSize The size of the buffer in bytes.
184: */
185: public void setBufferSize(int bufferSize) {
186: this.bufferSize = bufferSize;
187: }
188:
189: }
|