Build 1.1_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

A 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 a provided character converter. The default encoding is taken from the "file.encoding" system property. InputStreamReader contains a buffer of bytes read from the source stream and converts these into characters as needed. The buffer size is 8K.

Since:
Android 1.0
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()
          Closes this reader.
 String getEncoding()
          Returns the name of the encoding used to convert bytes into characters.
 int read()
          Reads a single character from this reader and returns it as an integer with the two higher-order bytes set to 0.
 int read(char[] buf, int offset, int length)
          Reads at most length characters from this reader and stores them at position offset in the character array buf.
 boolean ready()
          Indicates whether this reader 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. This constructor sets the character converter to the encoding specified in the "file.encoding" property and falls back to ISO 8859_1 (ISO-Latin-1) if the property doesn't exist.

Parameters:
in - the input stream from which to read characters.
Since:
Android 1.0

InputStreamReader

public InputStreamReader(InputStream in,
                         String enc)
                  throws UnsupportedEncodingException
Constructs a new InputStreamReader on the InputStream in. The character converter that is used to decode bytes into characters is identified by name by enc. If the encoding cannot be found, an UnsupportedEncodingException error is thrown.

Parameters:
in - the InputStream from which to read characters.
enc - identifies the character converter to use.
Throws:
NullPointerException - if enc is null.
UnsupportedEncodingException - if the encoding specified by enc cannot be found.
Since:
Android 1.0

InputStreamReader

public InputStreamReader(InputStream in,
                         CharsetDecoder dec)
Constructs a new InputStreamReader on the InputStream in and CharsetDecoder dec.

Parameters:
in - the source InputStream from which to read characters.
dec - the CharsetDecoder used by the character conversion.
Since:
Android 1.0

InputStreamReader

public InputStreamReader(InputStream in,
                         Charset charset)
Constructs a new InputStreamReader on the InputStream in and Charset charset.

Parameters:
in - the source InputStream from which to read characters.
charset - the Charset that defines the character converter
Since:
Android 1.0
Method Detail

close

public void close()
           throws IOException
Closes this reader. 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 reader.
Since:
Android 1.0

getEncoding

public String getEncoding()
Returns the name of the encoding used to convert bytes into characters. The value null is returned if this reader has been closed.

Returns:
the name of the character converter or null if this reader is closed.
Since:
Android 1.0

read

public int read()
         throws IOException
Reads a single character from this reader and returns it as an integer with the two higher-order bytes set to 0. Returns -1 if the end of the reader has been reached. The byte value is either obtained from converting bytes in this reader's 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 the end of the reader has been reached.
Throws:
IOException - if this reader is closed or some other I/O error occurs.
Since:
Android 1.0

read

public int read(char[] buf,
                int offset,
                int length)
         throws IOException
Reads at most length characters from this reader and stores them at position offset in the character array buf. Returns the number of characters actually read or -1 if the end of the reader has been reached. The bytes are either obtained from converting bytes in this reader's 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 - the array to store the characters read.
offset - the initial position in buf to store the characters read from this reader.
length - the maximum number of characters to read.
Returns:
the number of characters read or -1 if the end of the reader has been reached.
Throws:
IndexOutOfBoundsException - if offset < 0 or length < 0, or if offset + length is greater than the length of buf.
IOException - if this reader is closed or some other I/O error occurs.
Since:
Android 1.0

ready

public boolean ready()
              throws IOException
Indicates whether this reader is ready to be read without blocking. If the result is true, the next read() will not block. If the result is false then this reader may or may not block when read() is called. This implementation returns true if there are bytes available in the buffer or the source stream 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 this reader is closed or some other I/O error occurs.
Since:
Android 1.0
See Also:
Reader.read(), Reader.read(char[]), Reader.read(char[], int, int)

Build 1.1_r1 (from source)

Please submit a feedback, bug or feature