Save This Page
Home » openjdk-7 » java » io » [javadoc | source]
java.io
public class: InputStreamReader [javadoc | source]
java.lang.Object
   java.io.Reader
      java.io.InputStreamReader

All Implemented Interfaces:
    Closeable, Readable

Direct Known Subclasses:
    FileReader

An InputStreamReader is a bridge from byte streams to character streams: It reads bytes and decodes them into characters using a specified charset . The charset that it uses may be specified by name or may be given explicitly, or the platform's default charset may be accepted.

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(System.in));
Fields inherited from java.io.Reader:
lock
Constructor:
 public InputStreamReader(InputStream in) 
    Creates an InputStreamReader that uses the default charset.
    Parameters:
    in - An InputStream
 public InputStreamReader(InputStream in,
    String charsetName) throws UnsupportedEncodingException 
    Creates an InputStreamReader that uses the named charset.
    Parameters:
    in - An InputStream
    charsetName - The name of a supported charset
    Throws:
    UnsupportedEncodingException - If the named charset is not supported
    exception: UnsupportedEncodingException - If the named charset is not supported
 public InputStreamReader(InputStream in,
    Charset cs) 
    Creates an InputStreamReader that uses the given charset.

    Parameters:
    in - An InputStream
    cs - A charset
    since: 1.4 -
    spec: JSR-51 -
 public InputStreamReader(InputStream in,
    CharsetDecoder dec) 
    Creates an InputStreamReader that uses the given charset decoder.

    Parameters:
    in - An InputStream
    dec - A charset decoder
    since: 1.4 -
    spec: JSR-51 -
Method from java.io.InputStreamReader Summary:
close,   getEncoding,   read,   read,   ready
Methods from java.io.Reader:
close,   mark,   markSupported,   read,   read,   read,   read,   ready,   reset,   skip
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from java.io.InputStreamReader Detail:
 public  void close() throws IOException 
 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 #InputStreamReader(InputStream, String) constructor then the returned name, being unique for the encoding, may differ from the name passed to the constructor. This method will return null if the stream has been closed.

 public int read() throws IOException 
    Reads a single character.
 public int read(char[] cbuf,
    int offset,
    int length) throws IOException 
    Reads characters into a portion of an array.
 public boolean ready() throws IOException 
    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.