tribble.io
Class CharInputStreamDfl

java.lang.Object
  extended by tribble.io.CharInputStreamDfl
All Implemented Interfaces:
CharInputStreamI, DiagnosticWriterI

public class CharInputStreamDfl
extends java.lang.Object
implements CharInputStreamI, DiagnosticWriterI

Default generic character input stream.

This is a default implementation of an input stream that is capable of reading a single character at a time. Such a stream can be used as the underlying character input stream for classes implementing the LexerI interface.

This character stream handles various combinations of newline termination characters (LF, CR, and CR/LF pairs), returning a single newline character ('\n') for any given combination.

This also handles formfeed (FF) and null (NUL) characters, treating them as spaces (SP).

Tab (HT) characters are replaced with one or more spaces, to align on tabbed columns. By default, tabs are replaced with the appropriate number of spaces so as to align on 8-character columns, but this can be changed to a different width or disabled altogether.

Since:
2001-05-18
Version:
$Revision: 1.2 $ $Date: 2003/01/25 18:40:45 $
Author:
David R. Tribble, david@tribble.com.
Copyright 2001-2003 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:
LexerI

Field Summary
static int DFL_TABSIZE
          Default tab width.
static int EOF
          End of file character code.
protected  int m_colNo
          Column position (of the last character read).
protected  java.io.Reader m_in
          Input stream.
protected  DiagnosticOutputI m_out
          Diagnostic output stream.
protected  int m_tabSp
          Pending tab (HT) character replacement.
protected  int m_tabSz
          Tab (HT) column width.
protected  int m_ungetc
          Pushed-back (unread) character.
(package private) static java.lang.String REV
          Revision information.
 
Constructor Summary
CharInputStreamDfl()
          Default constructor.
CharInputStreamDfl(java.io.Reader in)
          Constructor.
CharInputStreamDfl(java.io.Reader in, DiagnosticOutputI out)
          Constructor.
 
Method Summary
 void close()
          Close the input stream.
protected  void finalize()
          Finalization.
 int readChar()
          Read the next character from the input stream.
 void setInput(java.io.Reader in)
          Establish the input stream from which to read characters.
 void setOutput(DiagnosticOutputI out)
          Establish the output stream to which diagnostic messages (warning and error messages) are written during parsing.
 void setTabSize(int n)
          Establish the tab (HT) column width.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REV

static final java.lang.String REV
Revision information.

See Also:
Constant Field Values

EOF

public static final int EOF
End of file character code.

See Also:
Constant Field Values

DFL_TABSIZE

public static final int DFL_TABSIZE
Default tab width.

See Also:
Constant Field Values

m_in

protected java.io.Reader m_in
Input stream.


m_out

protected DiagnosticOutputI m_out
Diagnostic output stream.


m_ungetc

protected int m_ungetc
Pushed-back (unread) character.


m_colNo

protected int m_colNo
Column position (of the last character read).


m_tabSz

protected int m_tabSz
Tab (HT) column width.


m_tabSp

protected int m_tabSp
Pending tab (HT) character replacement.

Constructor Detail

CharInputStreamDfl

public CharInputStreamDfl()
Default constructor.

Since:
1.1, 2001-05-18

CharInputStreamDfl

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

Parameters:
in - The input stream from which to read characters.
Since:
1.1, 2001-05-18

CharInputStreamDfl

public CharInputStreamDfl(java.io.Reader in,
                          DiagnosticOutputI out)
Constructor.

Parameters:
in - The input stream from which to read characters.
out - The diagnostic output stream to write to.
Since:
1.1, 2001-05-18
Method Detail

setOutput

public void setOutput(DiagnosticOutputI out)
Establish the output stream to which diagnostic messages (warning and error messages) are written during parsing.

Specified by:
setOutput in interface DiagnosticWriterI
Parameters:
out - The diagnostic output stream.
Since:
1.1, 2001-05-18

setInput

public void setInput(java.io.Reader in)
Establish the input stream from which to read characters.

Specified by:
setInput in interface CharInputStreamI
Parameters:
in - The input stream from which to read characters.
Since:
1.1, 2001-05-18

close

public void close()
Close the input stream.

Specified by:
close in interface CharInputStreamI
Since:
1.1, 2001-05-18

readChar

public int readChar()
             throws java.io.IOException
Read the next character from the input stream.

This character stream handles various combinations of newline termination characters (LF, CR, and CR/LF pairs), returning a single newline character ('\n') for any given combination.

This stream also handles formfeed (FF) and null (NUL) characters, replacing them with spaces (SP).

Tab (HT) characters are replaced by one or more space (SP) characters, so that the character following the tab is aligned on a tab-sized column. Tab character replacement can be disabled by specifying a tab size of zero (see setTabSize(int)).

Specified by:
readChar in interface CharInputStreamI
Returns:
The next character code read from the input stream, or -1 if there are no more characters to read (i.e., the end of the input stream was reached).
Throws:
java.io.IOException - Thrown if an I/O (read) error occurs.
Since:
1.1, 2001-05-18

setTabSize

public void setTabSize(int n)
Establish the tab (HT) column width.

Setting a tab width of zero disables the replacing of tab (HT) characters with spaces, i.e., tab characters are read as is. The default tab width is 8.

Parameters:
n - The tab column width.
Since:
1.1, 2001-06-02

finalize

protected void finalize()
Finalization. Closes the underlying output stream, if any.

Overrides:
finalize in class java.lang.Object
Since:
1.1, 2001-05-18