java.io.InputStreamReader
java.io.Reader
java.io.FileReader
None
New as of JDK 1.1
The InputStreamReader class is a bridge between the byte-oriented world of the InputStream class and the character-oriented world of the Reader class. The InputStreamReader represents a character stream, but it gets its input from an underlying byte stream. An encoding scheme is responsible for translating the bytes to Unicode characters. An InputStreamReader can be created using an explicit encoding scheme or a default encoding scheme.
For example, to read an ISO-8859-5 byte stream as a Unicode character stream, you can construct an InputStreamReader with the encoding "8859_5" as follows:
InputStreamReader inr = new InputStreamReader(in, "8859_5");
Each time you read from an InputStreamReader object, bytes may be read from the underlying byte stream. To improve efficiency, you may want to wrap the InputStreamReader in a BufferedReader.
public class java.io.InputStreamReader extends java.io.Reader { // Constructors public InputStreamReader(InputStream in); public InputStreamReader(InputStream in, String enc); // Instance Methods public void close(); public String getEncoding(); public int read(); public int read(char[] cbuf, int off, int len); public boolean ready(); }
The input stream to use.
This constructor creates an InputStreamReader that gets its data from in and translates bytes to characters using the system's default encoding scheme.
public InputStreamReader(InputStream in, String enc) throws UnsupportedEncodingException
The input stream to use.
The name of an encoding scheme.
If enc is not a supported encoding scheme.
This constructor creates an InputStreamReader that gets its data from in and translates bytes to characters using the given encoding scheme.
If any kind of I/O error occurs.
Reader.close()
This method calls the close() method of the underlying input stream, which releases any system resources associated with this object.
A String that contains the name of the character encoding scheme of this reader.
This method returns the name of the character encoding scheme this InputStreamReader is currently using.
The next character of data or -1 if the end of the stream is encountered.
If any kind of I/O error occurs.
Reader.read()
This method reads a character of input. The method returns the next character that has been read and converted from the underlying byte-oriented InputStream. The InputStreamReader class uses buffering internally, so this method returns immediately unless the buffer is empty. If the buffer is empty, a new block of bytes is read from the InputStream and converted to characters. The method blocks until the character is read, the end of stream is encountered, or an exception is thrown.
An array of characters to be filled from the stream.
An offset into the array.
The number of characters to read.
The actual number of characters read or -1 if the end of the stream is encountered immediately.
If any kind of I/O error occurs.
Reader.read(char[], int, int)
This method reads up to len characters of input into the given array starting at index off. The InputStreamReader class uses buffering internally, so this method returns immediately if there is enough data in the buffer. If there is not enough data, a new block of bytes is read from the InputStream and converted to characters. The method blocks until some data is available.
true if the reader is ready to be read; false otherwise.
If the reader is closed or any other kind of I/O error occurs.
Reader.ready()
This method returns a boolean value that indicates whether or not the reader is ready to be read. If there is data available in the internal buffer or if there are bytes available to be read from the underlying byte stream, the method returns true. Otherwise it returns false.
Method |
Inherited From |
Method |
Inherited From |
---|---|---|---|
clone() |
Object |
equals(Object) |
Object |
finalize() |
Object |
getClass() |
Object |
hashCode() |
Object |
notify() |
Object |
notifyAll() |
Object |
mark() |
Reader |
markSupported() |
Reader |
read(char[]) |
Reader |
reset() |
Reader |
skip(long) |
Reader |
toString() |
Object |
wait() |
Object |
wait(long) |
Object |
wait(long, int) |
Object |
BufferedReader, FileReader, InputStream, IOException, , Reader, UnsupportedEncodingException
This HTML Help has been published using the chm2web software. |