public class LineReader
extends Object
Modifier and Type | Field and Description |
---|---|
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 and Description |
---|
LineReader(String filePath)
Default constructor
|
Modifier and Type | Method and Description |
---|---|
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.
|
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
public LineReader(String filePath) throws IOException
filePath
- Path of the file to readIOException
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()