FileDocCategorySizeDatePackage
InputStreamReader.javaAPI DocphoneME MR2 API (J2ME)5155Wed May 02 17:59:54 BST 2007java.io

InputStreamReader

public class InputStreamReader extends Reader
An InputStreamReader is a bridge from byte streams to character streams: It reads bytes and translates them into characters. The encoding that it uses may be specified by name, or the platform's default encoding 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.

version
1.0, 12/15/99 (CLDC 1.0, Spring 2000)

Fields Summary
private Reader
in
The underlying character-input stream.
Constructors Summary
public InputStreamReader(InputStream is)
Create an InputStreamReader that uses the default character encoding.

param
is An InputStream

        in = Helper.getStreamReader(is);
    
public InputStreamReader(InputStream is, String enc)
Create an InputStreamReader that uses the named character encoding.

param
is An InputStream
param
enc The name of a supported
exception
UnsupportedEncodingException If the named encoding is not supported

        in = Helper.getStreamReader(is, enc);
    
Methods Summary
public voidclose()
Close the stream.

exception
IOException If an I/O error occurs

        if (in != null) {
            in.close();
            in = null;
        }
    
private voidensureOpen()
Check to make sure that the stream has not been closed

        if (in == null) {
            throw new IOException(
/* #ifdef VERBOSE_EXCEPTIONS */
/// skipped                       "Stream closed"
/* #endif */
            );
        }
    
public voidmark(int readAheadLimit)
Mark the present position in the stream.

exception
IOException If an I/O error occurs

        ensureOpen();
        if (in.markSupported()) {
            in.mark(readAheadLimit);
        } else {
            throw new IOException(
/* #ifdef VERBOSE_EXCEPTIONS */
/// skipped                       "mark() not supported"
/* #endif */
            );
        }
    
public booleanmarkSupported()
Tell whether this stream supports the mark() operation.

        if (in == null) {
            return false;
        }
        return in.markSupported();
    
public intread()
Read a single character.

exception
IOException If an I/O error occurs

        ensureOpen();
        return in.read();
    
public intread(char[] cbuf, int off, int len)
Read characters into a portion of an array.

exception
IOException If an I/O error occurs

        ensureOpen();
        if ((off < 0) || (off > cbuf.length) || (len < 0) ||
            ((off + len) > cbuf.length) || ((off + len) < 0)) {
            throw new IndexOutOfBoundsException();
        } else if (len == 0) {
            return 0;
        }
        return in.read(cbuf, off, len);
    
public booleanready()
Tell whether this stream is ready to be read.

exception
IOException If an I/O error occurs

        ensureOpen();
        return in.ready();
    
public voidreset()
Reset the stream.

exception
IOException If an I/O error occurs

        ensureOpen();
        in.reset();
    
public longskip(long n)
Skip characters.

exception
IOException If an I/O error occurs

        ensureOpen();
        return in.skip(n);