|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.io.Reader
org.millscript.tools.PushbackLinenumberReader
public class PushbackLinenumberReader
A buffered character stream reader that allows characters to be pushed back and keeps track of line numbers. By default we start line numbers at 1, rather than 0 as is Java.
Due to the implementation, there may be more available push back space than the value specified. However, you are guaranteed to have at least the requested amount of push back space.
This is heavily based on Java's LineNumberReader, PushbackReader and BufferedReader. However PushbackReader fails when you push back an end of file character(-1) as it simply pushes -1 into a char array! Also, although you could construct a PushbackReader on a LineNumberReader, or vice versa, if you push back an end of line you would have a hard time obtaining the correct line number.
| Field Summary |
|---|
| Fields inherited from class java.io.Reader |
|---|
lock |
| Constructor Summary | |
|---|---|
PushbackLinenumberReader(java.io.Reader in)
|
|
PushbackLinenumberReader(java.io.Reader in,
int sz,
int pb)
Constructs a new push back line number reader, which will buffer the specified number of characters and have a push back buffer of the given minimum size. |
|
| Method Summary | |
|---|---|
void |
close()
|
int |
getLineNumber()
Returns the line number for the current position in the file. |
void |
mark(int readAheadLimit)
|
boolean |
markSupported()
|
int |
read()
Reads a single character, returning it as an int. |
int |
read(char[] cbuf,
int off,
int len)
Read characters into a portion of an array. |
java.lang.String |
readLine()
Reads a line of text. |
boolean |
ready()
|
void |
reset()
|
void |
setLineNumber(int n)
Sets the current line number |
long |
skip(long n)
Skips the requested number of characters. |
void |
unread(char[] cbuf)
Pushes back all the characters in specified buffer. |
void |
unread(char[] cbuf,
int off,
int len)
Pushes back a specified number of characters from the specified buffer, starting from the specified offset. |
void |
unread(int ch)
Pushes back the specified character. |
| 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 |
| Constructor Detail |
|---|
public PushbackLinenumberReader(java.io.Reader in)
in - a Reader to fetch characters from
public PushbackLinenumberReader(java.io.Reader in,
int sz,
int pb)
in - a Reader to fetch characters fromsz - the number of characters to bufferpb - the minimum number of push back characters| Method Detail |
|---|
public void close()
throws java.io.IOException
close in interface java.io.Closeableclose in class java.io.Readerjava.io.IOExceptionReader.close()public int getLineNumber()
public void mark(int readAheadLimit)
throws java.io.IOException
mark in class java.io.Readerjava.io.IOExceptionReader.mark(int)public boolean markSupported()
markSupported in class java.io.ReaderReader.markSupported()
public int read()
throws java.io.IOException
read in class java.io.Readerjava.io.IOException - if there is a problem reading from the source
reader
public int read(char[] cbuf,
int off,
int len)
throws java.io.IOException
read in class java.io.Readercbuf - the character buffer to read characters intooff - the position in the character buffer to start placing
characters atlen - the maximum number of characters to read
java.io.IOException - thrown if there is a problem reading a character
from the parent reader
public java.lang.String readLine()
throws java.io.IOException
null if
the end of file has been reached.
java.io.IOException - if an I/O exception occurs
public boolean ready()
throws java.io.IOException
ready in class java.io.Readerjava.io.IOExceptionReader.ready()
public void reset()
throws java.io.IOException
reset in class java.io.Readerjava.io.IOExceptionReader.reset()public void setLineNumber(int n)
n - an int specifying the new current line number
public long skip(long n)
throws java.io.IOException
skip in class java.io.Readern - the number of characters to skip
java.io.IOException - thrown if there is a problem reading from the
parent reader
public void unread(int ch)
throws java.io.IOException
ch - the character to push back. This can include any value
returned by read, including the end of line.
java.io.IOException - thrown if there is a problem reading from the
parent reader
public void unread(char[] cbuf)
throws java.io.IOException
cbuf - the array of characters to unread
java.io.IOException - thrown if there is a problem reading from the
parent reader
public void unread(char[] cbuf,
int off,
int len)
throws java.io.IOException
cbuf - the array of characters to unreadoff - the position in the buffer to unread fromlen - the number of characters to unread
java.io.IOException - thrown if there is a problem reading from the
parent reader
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||