01: /*
02: * Copyright 2001-2006 C:1 Financial Services GmbH
03: *
04: * This software is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License Version 2.1, as published by the Free Software Foundation.
07: *
08: * This software is distributed in the hope that it will be useful,
09: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11: * Lesser General Public License for more details.
12: *
13: * You should have received a copy of the GNU Lesser General Public
14: * License along with this library; if not, write to the Free Software
15: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
16: */
17:
18: package de.finix.contelligent.resource;
19:
20: import java.io.IOException;
21: import java.io.InputStream;
22: import java.io.OutputStream;
23:
24: import de.finix.contelligent.exception.ComponentPersistenceException;
25: import de.finix.contelligent.logging.LoggingService;
26: import de.finix.contelligent.persistence.BinaryInputStreamProxy;
27: import de.finix.contelligent.util.FileUtils;
28:
29: public class BinaryResource extends Resource {
30: final static org.apache.log4j.Logger log = LoggingService
31: .getLogger(BinaryResource.class);
32:
33: private InputStream inputStream;
34:
35: private BinaryInputStreamProxy proxy;
36:
37: private String contentType;
38:
39: private String extension;
40:
41: private int length;
42:
43: public BinaryResource(boolean dummy, BinaryInputStreamProxy proxy,
44: String contentType, String extension, long lastModified,
45: int length) {
46: super (lastModified);
47: this .proxy = proxy;
48: this .contentType = contentType;
49: this .extension = extension;
50: this .length = length;
51: }
52:
53: public BinaryResource(InputStream inputStream, String contentType,
54: String extension, long lastModified, int length) {
55: super (lastModified);
56: this .inputStream = inputStream;
57: this .contentType = contentType;
58: this .extension = extension;
59: this .length = length;
60: }
61:
62: public void stream(OutputStream outputStream)
63: throws ComponentPersistenceException, IOException {
64: if (inputStream != null) {
65: FileUtils.copy(inputStream, outputStream);
66: } else if (proxy == null) {
67: return;
68: }
69: proxy.streamTo(outputStream);
70: }
71:
72: public String getContentType() {
73: return contentType;
74: }
75:
76: public String getExtension() {
77: return extension;
78: }
79:
80: public InputStream getInputStream() {
81: return inputStream;
82: }
83:
84: public int length() {
85: return length;
86: }
87:
88: public boolean isBinary() {
89: return true;
90: }
91: }
|