public class LineReader extends Object
RandomAccessFile
.
To perform efficient io operations, we use a OffsetReader
to obtain
the offset of the first char of a line.
You can create a new LineReader from a previous one, the matchings lines of
the new LineReader will all match the parent one (subset LineReader).Modifier and Type | Field and Description |
---|---|
protected File |
file |
protected String |
id
an identifier for the reader
|
protected long |
lastModified
last modified time of the file after last synchronization
|
protected long |
length
size of the file after last synchronization
|
protected static org.apache.commons.logging.Log |
log |
protected OffsetReader |
offstReader
offset reader used
|
protected LineReader |
parent
parent LineReader
|
protected RandomAccessFile |
reader
file reader
|
Constructor and Description |
---|
LineReader(File file,
OffsetReader offstReader) |
LineReader(LineReader parent,
OffsetReader offstReader) |
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the reader.
|
protected void |
ensureOpen() |
protected void |
finalize() |
File |
getFile() |
String |
getId() |
long |
getNbLines() |
OffsetReader |
getOffsetReader() |
LineReader |
getParent() |
boolean |
isOpen() |
boolean |
isUpToDate() |
boolean |
match(String line)
Matcher of line for this reader.
|
void |
open()
method we must inovke before any access to lines
|
String |
readLine(long position)
Read a line from a given position.
|
String[] |
readLine(long position,
int length)
Read some line(s) from a given position.
|
String |
readLine2(long position)
Read a line from a given position.
|
String[] |
readLine2(long position,
int length)
Read some line(s) from a given position.
|
void |
setId(String id) |
String |
toString() |
void |
update()
check if reader is up to date, and if not perform an update.
|
protected static final org.apache.commons.logging.Log log
protected File file
protected RandomAccessFile reader
protected long length
protected long lastModified
protected LineReader parent
protected OffsetReader offstReader
protected String id
public LineReader(LineReader parent, OffsetReader offstReader)
public LineReader(File file, OffsetReader offstReader)
public void open() throws IOException
IOException
- if any probem while opening readerpublic void close() throws IOException
IOException
- if any problem while closing readerpublic String readLine2(long position) throws IOException
position
- position of the line in the fileIOException
- if any problem while readingpublic String[] readLine2(long position, int length) throws IOException
position
- position of the line in the filelength
- the number of lines we wantIOException
- if any problem while readingpublic String readLine(long position) throws IOException
position
- position of the line in the fileIOException
- if any problem while readingpublic String[] readLine(long position, int length) throws IOException
position
- position of the line in the filelength
- the number of lines we wantIOException
- if any problem while readingpublic void update() throws IOException
IOException
- if any problem while updatingpublic boolean match(String line)
line
- the line to be accepted by this line readertrue
if the line must be used,false
otherwisepublic long getNbLines()
public File getFile()
public OffsetReader getOffsetReader()
public LineReader getParent()
public boolean isUpToDate()
true
if file is up to date,false
otherwiseprotected void finalize() throws Throwable
protected void ensureOpen()
public boolean isOpen()
public String getId()
public void setId(String id)
Copyright © 1999–2020 CodeLutin. All rights reserved.