|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.io.Reader java.io.BufferedReader java.io.LineNumberReader tribble.io.LineReader
public class LineReader
Text line reader. Reads text lines from a text file.
This class extends the standard java.io.LineNumberReader class,
performing the same functions, except that it expands tabs (HT,
' ') characters into spaces.
By default, tabs are assumed to be aligned on 8-space columns, but this can be
changed by calling the setTabWidth(int)
method.
LineNumberReader
Field Summary | |
---|---|
static int |
DFL_BUFSIZE
Default maximum input text line buffer size. |
static int |
DFL_TABSIZE
Default tab width. |
protected char[] |
m_buf
Input text line buffer. |
protected int |
m_colNo
Column number of the last character read (starting at 1). |
protected java.io.Reader |
m_in
Underlying input reader. |
protected int |
m_spacesLeft
Pending spaces remaining for a tab expansion. |
protected int |
m_tabSize
Tab width, zero specifies no tab expansion. |
(package private) static java.lang.String |
REV
Revision information. |
Fields inherited from class java.io.Reader |
---|
lock |
Constructor Summary | |
---|---|
LineReader(java.io.Reader in)
Constructor. |
|
LineReader(java.io.Reader in,
int bufSize)
Constructor. |
Method Summary | |
---|---|
int |
getTabWidth()
Retrieve the number of spaces that tab characters are expanded into. |
static void |
main(java.lang.String[] args)
Test driver. |
void |
mark(int limit)
Mark the present position in this input stream. |
boolean |
markSupported()
Determine whether the mark(int) method is supported or not. |
int |
read(char[] buf,
int off,
int len)
Read characters into a portion of an array. |
protected int |
readChar()
Read a single text character from this input stream. |
java.lang.String |
readLine()
Read a single line of text from this input stream. |
void |
reset()
Reset this input stream to the most recent mark. |
void |
setTabWidth(int n)
Establish the number of spaces that tab characters are expanded into. |
Methods inherited from class java.io.LineNumberReader |
---|
getLineNumber, read, setLineNumber, skip |
Methods inherited from class java.io.BufferedReader |
---|
close, ready |
Methods inherited from class java.io.Reader |
---|
read, read |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
static final java.lang.String REV
public static int DFL_TABSIZE
public static int DFL_BUFSIZE
protected java.io.Reader m_in
protected int m_tabSize
protected int m_colNo
protected int m_spacesLeft
protected char[] m_buf
Constructor Detail |
---|
public LineReader(java.io.Reader in)
in
- A character input stream to read characters from.
This cannot be null.public LineReader(java.io.Reader in, int bufSize)
in
- A character input stream to read characters from.
This cannot be null.bufSize
- The size of the input buffer to use for this input stream.Method Detail |
---|
public static void main(java.lang.String[] args)
Usage
java tribble.io.LineReader file...
args
- Command line arguments.public void setTabWidth(int n)
By default, tabs are expanded into spaces so as to align on every
DFL_TABSIZE
column.
n
- The number of columns that tab characters align to.
This can be zero, which specifies that tabs are not be replaced with
spaces, but should be left as is.getTabWidth()
public int getTabWidth()
setTabWidth(int)
public java.lang.String readLine() throws java.io.IOException
This method operates the same as LineNumberReader.readLine()
except that it expands tab characters into spaces. The number of spaces
is specified by a prior call to method setTabWidth(int)
.
Input lines are terminated by either a linefeed (' '), a carriage return (' '), or a carriage return followed by a linefeed (' '). Input lines are also considered terminated if they are followed by an end-of-file marker.
Invalid characters (i.e., nonprinting control characters) are replaced by spaces.
readLine
in class java.io.LineNumberReader
java.io.IOException
- Thrown if an I/O (read) error occurs.setTabWidth(int)
public int read(char[] buf, int off, int len) throws java.io.IOException
read
in class java.io.LineNumberReader
buf
- A character array to read characters into.off
- Index of the first character within buf to read.len
- The maximum number of characters to read into buf.
java.io.IOException
public boolean markSupported()
mark(int)
method is supported or not.
markSupported
in class java.io.BufferedReader
mark(int)
public void mark(int limit) throws java.io.IOException
mark
in class java.io.LineNumberReader
limit
- Limit on the number of characters that may be read while still preserving
the mark.
java.io.IOException
- Thrown if this operation is not supported, or if some other I/O error
occurs.markSupported()
,
reset()
public void reset() throws java.io.IOException
reset
in class java.io.LineNumberReader
java.io.IOException
- Thrown if this operation is not supported, or if some other I/O error
occurs.mark(int)
protected int readChar() throws java.io.IOException
This method operates the same as LineNumberReader.readLine()
except that it expands tab characters into spaces. The number of spaces
is specified by a prior call to method setTabWidth(int)
.
Invalid characters (i.e., nonprinting control characters) are replaced by spaces.
Note
This method is not synchronized, so any public member methods calling this method should be synchronized themselves.
java.io.IOException
- Thrown if an I/O (read) error occurs.read(char[], int, int)
,
readLine()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |