|
Sharkysoft home | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.io.Reader | +--java.io.FilterReader | +--lava.io.LFilterReader | +--lava.io.UnixLineReader
Filters any-platform text stream to appear as if it originated from a Unix file.
Don't let the name fool you! UnixLineReader
is useful on all platforms. It allows you to read a text stream without worrying about which platform the stream was created on. Unix, Macintosh, and PCs all create text files using different endline sequences. Unfortunately, using system-independent code to get the line.separator
property is an inadequate solution to the problem, since a program running on one platform may be reading a text file that was created on another platform.
This class automatically recognizes any of the three major line-ending sequences (Unix: "\n"; Win32: "\r\n"; Macintosh: "\r") -- even if they are intermixed within the stream (i.e., by concatenating files from different platforms) -- and transparently converts the line separators to the standard Unix endline character '\n' when they are read.
Knowing what kind of endline sequence to expect greatly simplifies the process of parsing line ends when you are reading the stream character by character. Looking for the end of the line? Just look for the '\n' character, and don't worry about trying to guess which platform the stream was created on! This filter also makes sure the last line is terminated with a line separator, even it this was not the case in the original source.
Skip characters. The counts of characters skipped are given in terms of filtered characters. (This matters only when reading DOS or Windows text files, since the endline sequence is 2 characters, but counted only as 1 character by this method.) The number of characters actually skipped is returned. A zero return value may indicate EOF.
Fields inherited from class java.io.FilterReader |
in |
Fields inherited from class java.io.Reader |
lock |
Constructor Summary | |
UnixLineReader(java.io.BufferedReader reader)
Initializes a new instance to read from the specified reader. |
Method Summary | |
int |
getLineNumber()
Returns the total number of lines read so far. |
void |
mark(int read_ahead_limit)
Mark the present position in this filtered stream. |
int |
read()
Reads the next character from the stream. |
int |
read(char[] dest,
int off,
int len)
Reads a block of characters from the stream. |
java.lang.String |
readLine()
Reads a line, or the rest of the current line if some of the current line has already been read. |
void |
reset()
Attempts to reset the stream. |
void |
setLineNumber(int n)
Sets the current line number. |
Methods inherited from class lava.io.LFilterReader |
read |
Methods inherited from class java.io.FilterReader |
close, markSupported, ready, skip |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public UnixLineReader(java.io.BufferedReader reader)
reader
- the readerMethod Detail |
public int read() throws java.io.IOException
read
in class java.io.FilterReader
public int read(char[] dest, int off, int len) throws java.io.IOException
read
in class java.io.FilterReader
dest
- destination array for storing the characters readoff
- starting offset into the destination arraylen
- number of characters to readjava.io.IOException
- if an I/O error occurspublic void mark(int read_ahead_limit) throws java.io.IOException
super.mark
.mark
in class java.io.FilterReader
read_ahead_limit
- the read ahead limitjava.io.IOException
- if the stream does not support mark()public void reset() throws java.io.IOException
super.reset
.reset
in class java.io.FilterReader
java.io.IOException
- if the stream cannot be resetpublic final java.lang.String readLine() throws java.io.IOException
java.io.IOException
- if an I/O error occurspublic int getLineNumber()
ClassCastException
- if the base reader is not a LineNumberReaderpublic void setLineNumber(int n)
ClassCastException
- if the base reader is not a LineNumberReader
|
Sharkysoft home | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |