71 |
* <li>More later |
* <li>More later |
72 |
* </ul> |
* </ul> |
73 |
* <p> |
* <p> |
74 |
* It is recommended that applications do not use <code>InputStreamReader</code>'s |
* It is recommended that applications do not use |
75 |
|
* <code>InputStreamReader</code>'s |
76 |
* directly. Rather, for efficiency purposes, an object of this class |
* directly. Rather, for efficiency purposes, an object of this class |
77 |
* should be wrapped by a <code>BufferedReader</code>. |
* should be wrapped by a <code>BufferedReader</code>. |
78 |
* <p> |
* <p> |
82 |
* @see BufferedReader |
* @see BufferedReader |
83 |
* @see InputStream |
* @see InputStream |
84 |
* |
* |
|
* @version 0.0 |
|
|
* |
|
85 |
* @author Aaron M. Renn (arenn@urbanophile.com) |
* @author Aaron M. Renn (arenn@urbanophile.com) |
86 |
*/ |
*/ |
87 |
public class InputStreamReader extends Reader |
public class InputStreamReader extends Reader |
88 |
{ |
{ |
89 |
|
/* |
90 |
/*************************************************************************/ |
* Instance Variables |
91 |
|
*/ |
92 |
/* |
|
93 |
* Instance Variables |
/* |
94 |
*/ |
* This is the byte-character decoder class that does the reading and |
95 |
|
* translation of bytes from the underlying stream. |
96 |
/* |
*/ |
97 |
* This is the byte-character decoder class that does the reading and |
private Decoder in; |
98 |
* translation of bytes from the underlying stream. |
|
99 |
*/ |
/*************************************************************************/ |
100 |
private Decoder in; |
|
101 |
|
/** |
102 |
/*************************************************************************/ |
* This method initializes a new instance of <code>InputStreamReader</code> |
103 |
|
* to read from the specified stream using the default encoding. |
104 |
/** |
* |
105 |
* This method initializes a new instance of <code>InputStreamReader</code> |
* @param in The <code>InputStream</code> to read from |
106 |
* to read from the specified stream using the default encoding. |
*/ |
107 |
* |
public InputStreamReader(InputStream in) |
108 |
* @param in The <code>InputStream</code> to read from |
{ |
109 |
*/ |
if (in == null) |
110 |
public |
throw new NullPointerException(); |
111 |
InputStreamReader(InputStream in) |
this.in = EncodingManager.getDecoder(in); |
112 |
{ |
} |
113 |
if (in == null) |
|
114 |
throw new NullPointerException(); |
/*************************************************************************/ |
115 |
this.in = EncodingManager.getDecoder(in); |
|
116 |
} |
/** |
117 |
|
* This method initializes a new instance of <code>InputStreamReader</code> |
118 |
/*************************************************************************/ |
* to read from the specified stream using a caller supplied character |
119 |
|
* encoding scheme. Note that due to a deficiency in the Java language |
120 |
/** |
* design, there is no way to determine which encodings are supported. |
121 |
* This method initializes a new instance of <code>InputStreamReader</code> |
* |
122 |
* to read from the specified stream using a caller supplied character |
* @param in The <code>InputStream</code> to read from |
123 |
* encoding scheme. Note that due to a deficiency in the Java language |
* @param encoding_name The name of the encoding scheme to use |
124 |
* design, there is no way to determine which encodings are supported. |
* |
125 |
* |
* @exception UnsupportedEncodingException If the encoding scheme |
126 |
* @param in The <code>InputStream</code> to read from |
* requested is not available. |
127 |
* @param encoding_name The name of the encoding scheme to use |
*/ |
128 |
* |
public InputStreamReader(InputStream in, String encoding_name) |
129 |
* @exception UnsupportedEncodingException If the encoding scheme requested is not available. |
throws UnsupportedEncodingException |
130 |
*/ |
{ |
131 |
public |
if (in == null || encoding_name == null) |
132 |
InputStreamReader(InputStream in, String encoding_name) throws |
throw new NullPointerException(); |
133 |
UnsupportedEncodingException |
this.in = EncodingManager.getDecoder(in, encoding_name); |
134 |
{ |
} |
135 |
if (in == null || encoding_name == null) |
|
136 |
throw new NullPointerException(); |
/*************************************************************************/ |
137 |
this.in = EncodingManager.getDecoder(in, encoding_name); |
|
138 |
} |
/* |
139 |
|
* Instance Methods |
140 |
/*************************************************************************/ |
*/ |
141 |
|
|
142 |
/* |
/** |
143 |
* Instance Methods |
* This method returns the name of the encoding that is currently in use |
144 |
*/ |
* by this object. If the stream has been closed, this method is allowed |
145 |
|
* to return <code>null</code>. |
146 |
/** |
* |
147 |
* This method returns the name of the encoding that is currently in use |
* @param The current encoding name |
148 |
* by this object. If the stream has been closed, this method is allowed |
*/ |
149 |
* to return <code>null</code>. |
public String getEncoding() |
150 |
* |
{ |
151 |
* @param The current encoding name |
return(in.getSchemeName()); |
152 |
*/ |
} |
153 |
public String |
|
154 |
getEncoding() |
/*************************************************************************/ |
155 |
{ |
|
156 |
return(in.getSchemeName()); |
/** |
157 |
} |
* This method closes this stream, as well as the underlying |
158 |
|
* <code>InputStream</code>. |
159 |
/*************************************************************************/ |
* |
160 |
|
* @exception IOException If an error occurs |
161 |
/** |
*/ |
162 |
* This method closes this stream, as well as the underlying |
public void close() throws IOException |
163 |
* <code>InputStream</code>. |
{ |
164 |
* |
in.close(); |
165 |
* @exception IOException If an error occurs |
} |
166 |
*/ |
|
167 |
public void |
/*************************************************************************/ |
168 |
close() throws IOException |
|
169 |
{ |
/** |
170 |
in.close(); |
* This method checks to see if the stream is read to be read. It |
171 |
} |
* will return <code>true</code> if is, or <code>false</code> if it is not. |
172 |
|
* If the stream is not ready to be read, it could (although is not required |
173 |
/*************************************************************************/ |
* to) block on the next read attempt. |
174 |
|
* |
175 |
/** |
* @return <code>true</code> if the stream is ready to be read, |
176 |
* This method checks to see if the stream is read to be read. It |
* <code>false</code> otherwise |
177 |
* will return <code>true</code> if is, or <code>false</code> if it is not. |
* |
178 |
* If the stream is not ready to be read, it could (although is not required |
* @exception IOException If an error occurs |
179 |
* to) block on the next read attempt. |
*/ |
180 |
* |
public boolean ready() throws IOException |
181 |
* @return <code>true</code> if the stream is ready to be read, <code>false</code> otherwise |
{ |
182 |
* |
return(in.ready()); |
183 |
* @exception IOException If an error occurs |
} |
184 |
*/ |
|
185 |
public boolean |
/*************************************************************************/ |
186 |
ready() throws IOException |
|
187 |
{ |
/** |
188 |
return(in.ready()); |
* This method reads a single character of data from the stream. |
189 |
} |
* |
190 |
|
* @return The char read, as an int, or -1 if end of stream. |
191 |
/*************************************************************************/ |
* |
192 |
|
* @exception IOException If an error occurs |
193 |
/** |
*/ |
194 |
* This method reads a single character of data from the stream. |
public int read() throws IOException |
195 |
* |
{ |
196 |
* @return The char read, as an int, or -1 if end of stream. |
return(in.read()); |
197 |
* |
} |
198 |
* @exception IOException If an error occurs |
|
199 |
*/ |
/*************************************************************************/ |
200 |
public int |
|
201 |
read() throws IOException |
/** |
202 |
{ |
* This method reads up to <code>len</code> characters from the stream into |
203 |
return(in.read()); |
* the specified array starting at index <code>offset</code> into the |
204 |
} |
* array. |
205 |
|
* |
206 |
/*************************************************************************/ |
* @param buf The character array to recieve the data read |
207 |
|
* @param offset The offset into the array to start storing characters |
208 |
/** |
* @param len The requested number of characters to read. |
209 |
* This method reads up to <code>len</code> characters from the stream into |
* |
210 |
* the specified array starting at index <code>offset</code> into the |
* @return The actual number of characters read, or -1 if end of stream. |
211 |
* array. |
* |
212 |
* |
* @exception IOException If an error occurs |
213 |
* @param buf The character array to recieve the data read |
*/ |
214 |
* @param offset The offset into the array to start storing characters |
public int read(char[] buf, int offset, int len) throws IOException |
215 |
* @param len The requested number of characters to read. |
{ |
216 |
* |
return(in.read(buf, offset, len)); |
217 |
* @return The actual number of characters read, or -1 if end of stream. |
} |
|
* |
|
|
* @exception IOException If an error occurs |
|
|
*/ |
|
|
public int |
|
|
read(char[] buf, int offset, int len) throws IOException |
|
|
{ |
|
|
return(in.read(buf, offset, len)); |
|
|
} |
|
218 |
|
|
219 |
} // class InputStreamReader |
} // class InputStreamReader |
220 |
|
|