01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package org.apache.naming.resources;
19:
20: import java.io.InputStream;
21: import java.io.ByteArrayInputStream;
22: import java.io.IOException;
23:
24: /**
25: * Encapsultes the contents of a resource.
26: *
27: * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
28: * @version $Revision: 467222 $
29: */
30: public class Resource {
31:
32: // ----------------------------------------------------------- Constructors
33:
34: public Resource() {
35: }
36:
37: public Resource(InputStream inputStream) {
38: setContent(inputStream);
39: }
40:
41: public Resource(byte[] binaryContent) {
42: setContent(binaryContent);
43: }
44:
45: // ----------------------------------------------------- Instance Variables
46:
47: /**
48: * Binary content.
49: */
50: protected byte[] binaryContent = null;
51:
52: /**
53: * Input stream.
54: */
55: protected InputStream inputStream = null;
56:
57: // ------------------------------------------------------------- Properties
58:
59: /**
60: * Content accessor.
61: *
62: * @return InputStream
63: */
64: public InputStream streamContent() throws IOException {
65: if (binaryContent != null) {
66: return new ByteArrayInputStream(binaryContent);
67: }
68: return inputStream;
69: }
70:
71: /**
72: * Content accessor.
73: *
74: * @return binary content
75: */
76: public byte[] getContent() {
77: return binaryContent;
78: }
79:
80: /**
81: * Content mutator.
82: *
83: * @param inputStream New input stream
84: */
85: public void setContent(InputStream inputStream) {
86: this .inputStream = inputStream;
87: }
88:
89: /**
90: * Content mutator.
91: *
92: * @param binaryContent New bin content
93: */
94: public void setContent(byte[] binaryContent) {
95: this.binaryContent = binaryContent;
96: }
97:
98: }
|