01: /*
02: * Copyright 1999,2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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:
17: package org.apache.naming.resources;
18:
19: import java.io.InputStream;
20: import java.io.ByteArrayInputStream;
21: import java.io.IOException;
22:
23: /**
24: * Encapsultes the contents of a resource.
25: *
26: * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
27: * @version $Revision: 1.2 $
28: */
29: public class Resource {
30:
31: // ----------------------------------------------------------- Constructors
32:
33: public Resource() {
34: }
35:
36: public Resource(InputStream inputStream) {
37: setContent(inputStream);
38: }
39:
40: public Resource(byte[] binaryContent) {
41: setContent(binaryContent);
42: }
43:
44: // ----------------------------------------------------- Instance Variables
45:
46: /**
47: * Binary content.
48: */
49: protected byte[] binaryContent = null;
50:
51: /**
52: * Input stream.
53: */
54: protected InputStream inputStream = null;
55:
56: // ------------------------------------------------------------- Properties
57:
58: /**
59: * Content accessor.
60: *
61: * @return InputStream
62: */
63: public InputStream streamContent() throws IOException {
64: if (binaryContent != null) {
65: return new ByteArrayInputStream(binaryContent);
66: }
67: return inputStream;
68: }
69:
70: /**
71: * Content accessor.
72: *
73: * @return binary content
74: */
75: public byte[] getContent() {
76: return binaryContent;
77: }
78:
79: /**
80: * Content mutator.
81: *
82: * @param inputStream New input stream
83: */
84: public void setContent(InputStream inputStream) {
85: this .inputStream = inputStream;
86: }
87:
88: /**
89: * Content mutator.
90: *
91: * @param binaryContent New bin content
92: */
93: public void setContent(byte[] binaryContent) {
94: this.binaryContent = binaryContent;
95: }
96:
97: }
|