Build 1.0_r1(from source)

java.io
Class InputStreamReader

java.lang.Object
  extended by java.io.Reader
      extended by java.io.InputStreamReader
All Implemented Interfaces:
Closeable, Readable
Direct Known Subclasses:
FileReader

public class InputStreamReader
extends Reader

InputStreamReader is class for turning a byte Stream into a character Stream. Data read from the source input stream is converted into characters by either a default or provided character converter. By default, the encoding is assumed to ISO8859_1. The InputStreamReader contains a buffer of bytes read from the source input stream and converts these into characters as needed. The buffer size is 8K.

See Also:
OutputStreamWriter

Nested Class Summary
(package private) static class InputStreamReader.HistoricalNamesUtil
           
 
Field Summary
(package private)  ByteBuffer bytes
           
(package private)  CharsetDecoder decoder
           
 
Fields inherited from class java.io.Reader
lock
 
Constructor Summary
InputStreamReader(InputStream in)
          Constructs a new InputStreamReader on the InputStream in.
InputStreamReader(InputStream in, Charset charset)
          Constructs a new InputStreamReader on the InputStream in and Charset charset.
InputStreamReader(InputStream in, CharsetDecoder dec)
          Constructs a new InputStreamReader on the InputStream in and CharsetDecoder dec.
InputStreamReader(InputStream in, String enc)
          Constructs a new InputStreamReader on the InputStream in.
 
Method Summary
 void close()
          Close this InputStreamReader.
 String getEncoding()
          Answer the String which identifies the encoding used to convert bytes to characters.
 int read()
          Reads a single character from this InputStreamReader and returns the result as an int.
 int read(char[] buf, int offset, int length)
          Reads at most count characters from this Reader and stores them at offset in the character array buf.
 boolean ready()
          Returns a boolean indicating whether or not this InputStreamReader is ready to be read without blocking.
 
Methods inherited from class java.io.Reader
mark, markSupported, read, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

decoder

CharsetDecoder decoder

bytes

ByteBuffer bytes
Constructor Detail

InputStreamReader

public InputStreamReader(InputStream in)
Constructs a new InputStreamReader on the InputStream in. Now character reading can be filtered through this InputStreamReader. This constructor assumes the default conversion of ISO8859_1 (ISO-Latin-1).

Parameters:
in - the InputStream to convert to characters.

InputStreamReader

public InputStreamReader(InputStream in,
                         String enc)
                  throws UnsupportedEncodingException
Constructs a new InputStreamReader on the InputStream in. Now character reading can be filtered through this InputStreamReader. This constructor takes a String parameter enc which is the name of an encoding. If the encoding cannot be found, an UnsupportedEncodingException error is thrown.

Parameters:
in - the InputStream to convert to characters.
enc - a String describing the character converter to use.
Throws:
UnsupportedEncodingException - if the encoding cannot be found.

InputStreamReader

public InputStreamReader(InputStream in,
                         CharsetDecoder dec)
Constructs a new InputStreamReader on the InputStream in and CharsetDecoder dec. Now character reading can be filtered through this InputStreamReader.

Parameters:
in - the InputStream to convert to characters
dec - a CharsetDecoder used by the character conversion

InputStreamReader

public InputStreamReader(InputStream in,
                         Charset charset)
Constructs a new InputStreamReader on the InputStream in and Charset charset. Now character reading can be filtered through this InputStreamReader.

Parameters:
in - the InputStream to convert to characters
charset - the Charset that specify the character converter
Method Detail

close

public void close()
           throws IOException
Close this InputStreamReader. This implementation closes the source InputStream and releases all local storage.

Specified by:
close in interface Closeable
Specified by:
close in class Reader
Throws:
IOException - If an error occurs attempting to close this InputStreamReader.

getEncoding

public String getEncoding()
Answer the String which identifies the encoding used to convert bytes to characters. The value null is returned if this Reader has been closed.

Returns:
the String describing the converter or null if this Reader is closed.

read

public int read()
         throws IOException
Reads a single character from this InputStreamReader and returns the result as an int. The 2 higher-order characters are set to 0. If the end of reader was encountered then return -1. The byte value is either obtained from converting bytes in this readers buffer or by first filling the buffer from the source InputStream and then reading from the buffer.

Overrides:
read in class Reader
Returns:
the character read or -1 if end of reader.
Throws:
IOException - If the InputStreamReader is already closed or some other IO error occurs.

read

public int read(char[] buf,
                int offset,
                int length)
         throws IOException
Reads at most count characters from this Reader and stores them at offset in the character array buf. Returns the number of characters actually read or -1 if the end of reader was encountered. The bytes are either obtained from converting bytes in this readers buffer or by first filling the buffer from the source InputStream and then reading from the buffer.

Specified by:
read in class Reader
Parameters:
buf - character array to store the read characters
offset - offset in buf to store the read characters
length - maximum number of characters to read
Returns:
the number of characters read or -1 if end of reader.
Throws:
IOException - If the InputStreamReader is already closed or some other IO error occurs.

ready

public boolean ready()
              throws IOException
Returns a boolean indicating whether or not this InputStreamReader is ready to be read without blocking. If the result is true, the next read() will not block. If the result is false this Reader may or may not block when read() is sent. This implementation returns true if there are bytes available in the buffer or the source InputStream has bytes available.

Overrides:
ready in class Reader
Returns:
true if the receiver will not block when read() is called, false if unknown or blocking will occur.
Throws:
IOException - If the InputStreamReader is already closed or some other IO error occurs.

Build 1.0_r1(from source)

Please submit a feedback, bug or feature