tribble.io
Class ReaderInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by tribble.io.ReaderInputStream
All Implemented Interfaces:
java.io.Closeable

public class ReaderInputStream
extends java.io.InputStream

Pass-through character reader stream.

Reads characters from an underlying Reader object, returning them as 8-bit character codes. Only the low-order 8 bits of each character is returned; character codes greater than 0x00FF are truncated to 8 bits. This is similar to a character stream that reads ISO 8859-1 character codes as uninterpreted single-byte sequences, i.e., each character code is composed of a single 8-bit octet read from the input stream.

This class is essentially the inverse of class InputStreamReader.

Since:
2005-04-10
Version:
$Revision: 1.1 $ $Date: 2005/04/13 03:20:43 $
Author:
David R. Tribble (david@tribble.com).
Copyright ©2005 by David R. Tribble, all rights reserved.
Permission is granted to freely use and distribute this source code provided that the original copyright and authorship notices remain intact.
See Also:
WriterOutputStream, PassThruReader, InputStreamReader

Field Summary
protected  java.io.Reader m_in
          Underlying input stream reader.
protected  int m_ungetCh
          Pushed-back character.
(package private) static java.lang.String REV
          Revision information.
 
Constructor Summary
ReaderInputStream(java.io.Reader in)
          Constructor.
 
Method Summary
 void close()
          Close this input stream.
 int read()
          Read a single character.
 int read(byte[] buf)
          Read a group of characters.
 int read(byte[] buf, int off, int len)
          Read a group of characters.
 java.lang.String readLine()
          Read a line of text from this input stream.
 
Methods inherited from class java.io.InputStream
available, mark, markSupported, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REV

static final java.lang.String REV
Revision information.

See Also:
Constant Field Values

m_in

protected java.io.Reader m_in
Underlying input stream reader.


m_ungetCh

protected int m_ungetCh
Pushed-back character.

Constructor Detail

ReaderInputStream

public ReaderInputStream(java.io.Reader in)
Constructor.

Parameters:
out - Underlying input stream, which provides a destination for input bytes.
Since:
1.1, 2005-04-10
Method Detail

close

public void close()
           throws java.io.IOException
Close this input stream.

Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.InputStream
Throws:
java.io.IOException - Thrown if an I/O error occurs while closing the underlying input reader.
Since:
1.1, 2005-04-10

read

public int read()
         throws java.io.IOException
Read a single character.

Specified by:
read in class java.io.InputStream
Returns:
A character code, or -1 if the end of the input stream has been reached. Only the lower 8 bits of the character are returned (yielding characters in the range [0x0000,0x00FF]).
Throws:
java.io.IOException - Thrown if an I/O error occurs while reading from the underlying input reader.
Since:
1.1, 2005-04-10

read

public int read(byte[] buf)
         throws java.io.IOException
Read a group of characters.

This method has exactly the same effect as the call: read(buf, 0, buf.length).

Overrides:
read in class java.io.InputStream
Parameters:
buf - An array of character bytes to be read. Each byte represents a single 8-bit character code in the range [0x0000,0x00FF].
Returns:
The actual number of characters (byte) read into buf, or -1 if the end of the input stream has been reached.
Throws:
java.io.IOException - Thrown if an I/O error occurs while reading from the underlying input reader.
Since:
1.1, 2005-04-10

read

public int read(byte[] buf,
                int off,
                int len)
         throws java.io.IOException
Read a group of characters.

Overrides:
read in class java.io.InputStream
Parameters:
buf - An array of character bytes to be read. Each byte represents a single 8-bit character code in the range [0x0000,0x00FF].
off - Index of the first character in buf to read.
len - Number of characters in buf to read.
Returns:
The actual number of characters (byte) read into buf, or -1 if the end of the input stream has been reached.
Throws:
java.io.IOException - Thrown if an I/O error occurs while reading from the underlying input reader.
Since:
1.1, 2005-04-10

readLine

public java.lang.String readLine()
                          throws java.io.IOException
Read a line of text from this input stream.

If the underlying stream is a BufferedReader, its readLine() method is called. Otherwise, characters are read until a terminating newline sequence is encountered; a line is considered to be terminated by a line feed (LF, U+000A, '\n'), a carriage return (CR, U+000D, '\r'), or a carriage return followed immediately by a linefeed (CR LF).

This method is not defined by the InputStream class, but is provided as a convenient enhancement.

Throws:
java.io.IOException - Thrown if an I/O error occurs while reading from the underlying input reader.
Since:
1.1, 2005-04-10