charset
. The charset that it uses
may be specified by name or may be given explicitly, or the
default charset
may be used.
Each invocation of one of an InputStreamReader's read() methods may cause one or more bytes to be read from the underlying byte-input stream. To enable the efficient conversion of bytes to characters, more bytes may be read ahead from the underlying stream than are necessary to satisfy the current read operation.
For top efficiency, consider wrapping an InputStreamReader within a BufferedReader. For example:
BufferedReader in = new BufferedReader(new InputStreamReader(anInputStream));
BufferedReader
, InputStream
, Charset
Modifier and Type | Field and Description |
---|---|
private final StreamDecoder |
Access | Constructor and Description |
---|---|
public | InputStreamReader(InputStream
An InputStream in)Creates an InputStreamReader that uses the
|
public | InputStreamReader(InputStream
An InputStream in, String The name of a supported charsetName)charset Creates an InputStreamReader that uses the named charset. |
public | InputStreamReader(InputStream
An InputStream in, Charset A charset cs)Creates an InputStreamReader that uses the given charset. |
public | InputStreamReader(InputStream
An InputStream in, CharsetDecoder A charset decoder dec)Creates an InputStreamReader that uses the given charset decoder. |
Modifier and Type | Method and Description |
---|---|
public void | close()
Implements abstract java. Implements java. Closes the stream and releases any system resources associated with it. |
public String | Returns: The historical name of this encoding, ornull if the stream has been closedReturns the name of the character encoding being used by this stream. |
private static Object | |
public int | read(CharBuffer
the buffer to read characters into target)Overrides java. Implements java. Attempts to read characters into the specified character buffer. |
public int | Returns: The character read, or -1 if the end of the stream has been reachedOverrides java. Reads a single character. |
public int | read(char[]
Destination buffer cbuf, int Offset at which to start storing characters off, int Maximum number of characters to read len)Implements abstract java. Reads characters into a portion of an array. |
public boolean |
sd | back to summary |
---|---|
private final StreamDecoder sd |
InputStreamReader | back to summary |
---|---|
public InputStreamReader(InputStream in) Creates an InputStreamReader that uses the
|
InputStreamReader | back to summary |
---|---|
public InputStreamReader(InputStream in, String charsetName) throws UnsupportedEncodingException Creates an InputStreamReader that uses the named charset.
|
InputStreamReader | back to summary |
---|---|
public InputStreamReader(InputStream in, Charset cs) Creates an InputStreamReader that uses the given charset.
|
InputStreamReader | back to summary |
---|---|
public InputStreamReader(InputStream in, CharsetDecoder dec) Creates an InputStreamReader that uses the given charset decoder.
|
close | back to summary |
---|---|
public void close() throws IOException Implements abstract java. Implements java. Doc from java. Closes the stream and releases any system resources associated with it. Once the stream has been closed, further read(), ready(), mark(), reset(), or skip() invocations will throw an IOException. Closing a previously closed stream has no effect.
|
getEncoding | back to summary |
---|---|
public String getEncoding() Returns the name of the character encoding being used by this stream. If the encoding has an historical name then that name is returned; otherwise the encoding's canonical name is returned. If this instance was created with the |
lockFor | back to summary |
---|---|
private static Object lockFor(InputStreamReader reader) Return the lock object for the given reader's stream decoder. If the reader type is trusted then an internal lock can be used. If the reader type is not trusted then the reader object is the lock. |
read | back to summary |
---|---|
public int read(CharBuffer target) throws IOException Overrides java. Implements java. Doc from java. Attempts to read characters into the specified character buffer. The buffer is used as a repository of characters as-is: the only changes made are the results of a put operation. No flipping or rewinding of the buffer is performed. If the length of the specified character buffer is zero, then no characters will be read and zero will be returned.
|
read | back to summary |
---|---|
public int read() throws IOException Overrides java. Reads a single character.
|
read | back to summary |
---|---|
public int read(char[] cbuf, int off, int len) throws IOException Implements abstract java. Doc from java. Reads characters into a portion of an array. This method will block until some input is available, an I/O error occurs, or the end of the stream is reached. If
|
ready | back to summary |
---|---|
public boolean ready() throws IOException Overrides java. Tells 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.
|