|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
ObjectLineReader
public class LineReader
Provides a line-based interface for reading a file. Has the unusual ability to read forward or backward.
Field Summary | |
---|---|
private byte[] |
block
Internal buffer of file data |
private int |
blockEnd
Ending position of the block buffer within the file |
private static int |
blockSize
Size of our internal buffer |
private int |
blockStart
Starting position of the block buffer within the file |
private StringBuffer |
buf
Used to accumulate lines |
private RandomAccessFile |
file
Actual disk file we're reading |
private int |
length
Overall length of the file we're reading |
private int |
linePos
File position of the start of the last line read |
private int |
pos
Current position within the file |
Constructor Summary | |
---|---|
LineReader(String filePath)
Default constructor |
Method Summary | |
---|---|
int |
length()
Tells how long the file is, in bytes. |
int |
linePos()
Retrieves the file position of the last line fetched by nextLine() or prevLine(). |
private char |
nextChar()
Get the next character in the input file, and increment the position. |
String |
nextLine()
Retrieves the next line of text from the file. |
private char |
prevChar()
Get the previous character in the input file, and decrement the position. |
String |
prevLine()
Retrieves the previous line of text from the file. |
private void |
readBlock(int startPos)
Read a block of data starting a the given position. |
void |
seek(int toPos)
Reposition the file pointer at the beginning of the line containing the specified byte position. |
Methods inherited from class Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final int blockSize
private byte[] block
private int length
private int pos
private int blockStart
private int blockEnd
private int linePos
private RandomAccessFile file
private StringBuffer buf
Constructor Detail |
---|
public LineReader(String filePath) throws IOException
filePath
- Path of the file to read
IOException
Method Detail |
---|
private void readBlock(int startPos) throws IOException
IOException
public final int length() throws IOException
IOException
public void seek(int toPos) throws IOException
IOException
private char nextChar() throws IOException
IOException
private char prevChar() throws IOException
IOException
public String nextLine() throws IOException
IOException
public String prevLine() throws IOException
IOException
public int linePos()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |