All Packages Class Hierarchy This Package Previous Next Index
Class java.io.InputStreamReader
java.lang.Object
|
+----java.io.Reader
|
+----java.io.InputStreamReader
- public class InputStreamReader
- extends Reader
Read from a byte stream, translating bytes into characters according to a
specified character encoding. Each InputStreamReader incorporates its own
ByteToCharConverter, and is thus a bridge from byte streams to character
streams.
The encoding used by an InputStreamReader may be specified by name, by
providing a ByteToCharConverter, or by accepting the default encoding, which
is defined by the system property file.encoding.
An InputStreamReader reads bytes from the underlying byte-input stream
into an internal buffer. The size of this buffer may be specified, but by
default it is large enough for most purposes. Each invocation of a read()
method causes the encoding converter to be invoked on the bytes remaining in
the buffer. For top efficiency, consider wrapping an InputStreamReader
within a BufferedReader so as to avoid frequent converter invocations. For
example,
BufferedReader in
= new BufferedReader(new InputStreamReader(System.in));
- See Also:
- BufferedReader, InputStream
-
InputStreamReader(InputStream)
- Create an InputStreamReader that uses the default character encoding
and the default input-buffer size.
-
InputStreamReader(InputStream, ByteToCharConverter)
- Create an InputStreamReader that uses the specified byte-to-character
converter and the default input-buffer size.
-
InputStreamReader(InputStream, ByteToCharConverter, int)
- Create an InputStreamReader that uses the specified byte-to-character
converter and the specified input-buffer size.
-
InputStreamReader(InputStream, int)
- Create an InputStreamReader that uses the default character encoding
and the specified input-buffer size.
-
InputStreamReader(InputStream, String)
- Create an InputStreamReader that uses the named character encoding and
the default input-buffer size.
-
InputStreamReader(InputStream, String, int)
- Create an InputStreamReader that uses the named character encoding and
the specified input-buffer size.
-
close()
- Close the stream.
-
getCharacterEncoding()
- Return the name of the encoding being used by this stream.
-
read()
- Read a single character.
-
read(char[], int, int)
- Read characters into a portion of an array.
-
ready()
- Tell whether this stream is ready to be read.
InputStreamReader
public InputStreamReader(InputStream in)
- Create an InputStreamReader that uses the default character encoding
and the default input-buffer size.
- Parameters:
- in - An InputStream
InputStreamReader
public InputStreamReader(InputStream in,
String enc) throws UnsupportedEncodingException
- Create an InputStreamReader that uses the named character encoding and
the default input-buffer size.
- Parameters:
- in - An InputStream
- enc - Name of encoding to be used
- Throws: UnsupportedEncodingException
- If no converter can be found for the specified encoding
InputStreamReader
public InputStreamReader(InputStream in,
int sz)
- Create an InputStreamReader that uses the default character encoding
and the specified input-buffer size.
- Parameters:
- in - An InputStream
- sz - Input-buffer size
- Throws: IllegalArgumentException
- If sz is <= 0
InputStreamReader
public InputStreamReader(InputStream in,
String enc,
int sz) throws UnsupportedEncodingException
- Create an InputStreamReader that uses the named character encoding and
the specified input-buffer size.
- Parameters:
- in - An InputStream
- enc - Name of encoding to be used
- sz - Input-buffer size
- Throws: UnsupportedEncodingException
- If no converter can be found for the specified encoding
- Throws: IllegalArgumentException
- If sz is <= 0
InputStreamReader
public InputStreamReader(InputStream in,
ByteToCharConverter btc)
- Create an InputStreamReader that uses the specified byte-to-character
converter and the default input-buffer size. The converter will be
reset before its first use. Note: Because the converter has
state, it should not be used after the constructor returns.
- Parameters:
- in - An InputStream
- btc - A ByteToCharConverter
InputStreamReader
public InputStreamReader(InputStream in,
ByteToCharConverter btc,
int sz)
- Create an InputStreamReader that uses the specified byte-to-character
converter and the specified input-buffer size. The converter will be
reset before its first use. Note: Because the converter has
state, it should not be used after the constructor returns.
- Parameters:
- in - An InputStream
- btc - A ByteToCharConverter
- sz - Input-buffer size
- Throws: IllegalArgumentException
- If sz is <= 0
getCharacterEncoding
public String getCharacterEncoding() throws IOException
- Return the name of the encoding being used by this stream.
- Throws: IOException
- If an I/O error occurs
read
public int read() throws IOException
- Read a single character. This method is not very efficient, as it
invokes the encoding converter once for each character read.
- Returns:
- The character read, or -1 if the end of the stream has been
reached
- Throws: IOException
- If an I/O error occurs
- Overrides:
- read in class Reader
- See Also:
- read
read
public int read(char cbuf[],
int off,
int len) throws IOException
- Read characters into a portion of an array.
- Parameters:
- cbuf - Destination buffer
- off - Offset at which to start storing characters
- len - Maximum number of characters to read
- Returns:
- The number of characters read, or -1 if the end of the stream
has been reached
- Throws: IOException
- If an I/O error occurs
- Overrides:
- read in class Reader
ready
public boolean ready() throws IOException
- Tell whether this stream is ready to be read. An InputStreamReader is
ready if its input buffer is not empty, or if bytes are available to be
read from the underlying byte stream.
- Throws: IOException
- If an I/O error occurs
- Overrides:
- ready in class Reader
close
public void close() throws IOException
- Close the stream.
- Throws: IOException
- If an I/O error occurs
- Overrides:
- close in class Reader
All Packages Class Hierarchy This Package Previous Next Index