1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.log4j.lf5.util;
18
19 import java.io.InputStream;
20 import java.io.InputStreamReader;
21 import java.net.URL;
22
23 /***
24 * Resource encapsulates access to Resources via the Classloader.
25 *
26 * @author Michael J. Sikorsky
27 * @author Robert Shaw
28 */
29
30
31
32 public class Resource {
33
34
35
36
37
38
39
40 protected String _name;
41
42
43
44
45
46
47
48
49
50 /***
51 * Default, no argument constructor.
52 */
53 public Resource() {
54 super();
55 }
56
57 /***
58 * Construct a Resource given a name.
59 *
60 * @see #setName(String)
61 */
62 public Resource(String name) {
63 _name = name;
64 }
65
66
67
68
69
70 /***
71 * Set the name of the resource.
72 * <p>
73 * A resource is some data (images, audio, text, etc) that can be accessed
74 * by class code in a way that is independent of the location of the code.
75 * </p>
76 * <p>
77 * The name of a resource is a "/"-separated path name that identifies
78 * the resource.
79 * </p>
80 *
81 * @see #getName()
82 */
83 public void setName(String name) {
84 _name = name;
85 }
86
87 /***
88 * Get the name of the resource. Set setName() for a description of
89 * a resource.
90 *
91 * @see #setName
92 */
93 public String getName() {
94 return (_name);
95 }
96
97 /***
98 * Get the InputStream for this Resource. Uses the classloader
99 * from this Resource.
100 *
101 * @see #getInputStreamReader
102 * @see ResourceUtils
103 */
104 public InputStream getInputStream() {
105 InputStream in = ResourceUtils.getResourceAsStream(this, this);
106
107 return (in);
108 }
109
110 /***
111 * Get the InputStreamReader for this Resource. Uses the classloader from
112 * this Resource.
113 *
114 * @see #getInputStream
115 * @see ResourceUtils
116 */
117 public InputStreamReader getInputStreamReader() {
118 InputStream in = ResourceUtils.getResourceAsStream(this, this);
119
120 if (in == null) {
121 return null;
122 }
123
124 InputStreamReader reader = new InputStreamReader(in);
125
126 return reader;
127 }
128
129 /***
130 * Get the URL of the Resource. Uses the classloader from this Resource.
131 *
132 * @see ResourceUtils
133 */
134 public URL getURL() {
135 return (ResourceUtils.getResourceAsURL(this, this));
136 }
137
138
139
140
141
142
143
144
145
146
147
148
149
150 }
151
152
153
154
155
156