KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > naming > resources > Resource


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * 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 JavaDoc;
21 import java.io.ByteArrayInputStream JavaDoc;
22 import java.io.IOException JavaDoc;
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     
33     // ----------------------------------------------------------- Constructors
34

35     
36     public Resource() {
37     }
38     
39     
40     public Resource(InputStream JavaDoc inputStream) {
41         setContent(inputStream);
42     }
43     
44     
45     public Resource(byte[] binaryContent) {
46         setContent(binaryContent);
47     }
48     
49     
50     // ----------------------------------------------------- Instance Variables
51

52     
53     /**
54      * Binary content.
55      */

56     protected byte[] binaryContent = null;
57     
58     
59     /**
60      * Input stream.
61      */

62     protected InputStream JavaDoc inputStream = null;
63     
64     
65     // ------------------------------------------------------------- Properties
66

67     
68     /**
69      * Content accessor.
70      *
71      * @return InputStream
72      */

73     public InputStream JavaDoc streamContent()
74         throws IOException JavaDoc {
75         if (binaryContent != null) {
76             return new ByteArrayInputStream JavaDoc(binaryContent);
77         }
78         return inputStream;
79     }
80     
81     
82     /**
83      * Content accessor.
84      *
85      * @return binary content
86      */

87     public byte[] getContent() {
88         return binaryContent;
89     }
90     
91     
92     /**
93      * Content mutator.
94      *
95      * @param inputStream New input stream
96      */

97     public void setContent(InputStream JavaDoc inputStream) {
98         this.inputStream = inputStream;
99     }
100     
101     
102     /**
103      * Content mutator.
104      *
105      * @param binaryContent New bin content
106      */

107     public void setContent(byte[] binaryContent) {
108         this.binaryContent = binaryContent;
109     }
110     
111     
112 }
113
Popular Tags