|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.io.Reader tribble.io.CharReader
public class CharReader
Generic character input stream.
This is a generic implementation of an input stream that is capable of reading a single character at a time.
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.
Field Summary | |
---|---|
static int |
DFL_TABSIZE
Default tab width (8). |
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
Character input 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. |
static int |
NEWLINE
Newline (end of line) character code. |
(package private) static java.lang.String |
REV
Revision information. |
Fields inherited from class java.io.Reader |
---|
lock |
Constructor Summary | |
---|---|
CharReader(java.io.Reader in)
Constructor. |
|
CharReader(java.io.Reader in,
java.lang.Object lock)
Constructor. |
Method Summary | |
---|---|
void |
close()
Close this input stream. |
protected void |
finalize()
Finalization. |
void |
mark(int limit)
Mark the current position in this input stream. |
boolean |
markSupported()
Determine whether the underlying input stream supports position marks or not. |
int |
read()
Read the next character from this input stream. |
int |
read(char[] cbuf,
int off,
int len)
Read characters from this input stream into a portion of an array. |
protected int |
readChar()
Read the next character from this input stream. |
boolean |
ready()
Determine whether characters are ready to be read from this input stream or not. |
void |
reset()
Reset the current position of this input stream to the last mark. |
protected void |
setInput(java.io.Reader in)
Establish the input stream from which to read characters. |
void |
setTabSize(int n)
Establish the tab (HT) column width. |
long |
skip(long n)
Skip characters in this input stream. |
Methods inherited from class java.io.Reader |
---|
read, read |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
static final java.lang.String REV
public static final int EOF
public static final int NEWLINE
public static final int DFL_TABSIZE
protected java.io.Reader m_in
protected int m_ungetc
protected int m_colNo
protected int m_tabSz
protected int m_tabSp
Constructor Detail |
---|
public CharReader(java.io.Reader in)
in
- The input stream from which to read characters.public CharReader(java.io.Reader in, java.lang.Object lock)
in
- The input stream from which to read characters.lock
- An object that this input character stream will use to synchronize
critical sections.Method Detail |
---|
public void close() throws java.io.IOException
Disassociates the underlying input and output streams from this input stream.
close
in interface java.io.Closeable
close
in class java.io.Reader
java.io.IOException
- Thrown if an I/O error occurs.public int read() throws java.io.IOException
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()
).
This method may block until a character has been read.
read
in class java.io.Reader
java.io.IOException
- Thrown if an I/O (read) error occurs.public int read(char[] cbuf, int off, int len) throws java.io.IOException
Characters are read from the input stream up to (and including) the first newline character read or until len characters are read into array cbuf, whichever comes first.
See read()
for more details about the way characters are read
from this input stream.
This method may block until enough characters have been read.
read
in class java.io.Reader
cbuf
- Character array to read characters into.off
- Index of the first character within cbuf to read.len
- Maximum number of characters to read into cbuf.
java.io.IOException
- Thrown if an I/O (read) error occurs.public boolean markSupported()
markSupported
in class java.io.Reader
mark(int)
operation,
otherwise false.
java.io.IOException
- Thrown if an I/O error occurs.public void mark(int limit) throws java.io.IOException
mark
in class java.io.Reader
limit
- Minimum number number of characters that can be read ahead without losing
the mark.
java.io.IOException
- Thrown if the underlying input stream does not support this operation, or
if some other I/O error occurs.public void reset() throws java.io.IOException
reset
in class java.io.Reader
java.io.IOException
- Thrown if the underlying input stream does not support this operation, or
if the previous mark has been invalidated, or if some other I/O error
occurs.public long skip(long n) throws java.io.IOException
skip
in class java.io.Reader
n
- The number of characters to skip in this input stream.
java.io.IOException
- Thrown if an I/O (read) error occurs.
java.lang.IllegalArgumentException
- (unchecked)
Thrown if n is negative.public boolean ready() throws java.io.IOException
ready
in class java.io.Reader
java.io.IOException
- Thrown if an I/O (read) error occurs.public void setTabSize(int n)
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 (see DFL_TABSIZE
).
n
- The tab column width.protected void finalize()
finalize
in class java.lang.Object
protected void setInput(java.io.Reader in)
in
- The underlying input stream from which to read characters.protected int readChar() throws java.io.IOException
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()
).
This method may block until a character has been read.
Note that this method is not synchronized, so any public member method that invokes it should itself be synchronized.
java.io.IOException
- Thrown if an I/O (read) error occurs.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |