fr.ifremer.isisfish.logging.io
Class LineReader

java.lang.Object
  extended by fr.ifremer.isisfish.logging.io.LineReader
Direct Known Subclasses:
LineReaderUtil.LevelLineReader, LineReaderUtil.LevelsLineReader, LineReaderUtil.PatternLineReader

public class LineReader
extends Object

A lineReader reads lines from a file using a RandomAccessFile.

To perfrom 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).

Author:
chemit

Field Summary
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 Summary
LineReader(File file, OffsetReader offstReader)
           
LineReader(LineReader parent, OffsetReader offstReader)
           
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

log

protected static final org.apache.commons.logging.Log log

file

protected File file

reader

protected RandomAccessFile reader
file reader


length

protected long length
size of the file after last synchronization


lastModified

protected long lastModified
last modified time of the file after last synchronization


parent

protected LineReader parent
parent LineReader


offstReader

protected OffsetReader offstReader
offset reader used


id

protected String id
an identifier for the reader

Constructor Detail

LineReader

public LineReader(LineReader parent,
                  OffsetReader offstReader)

LineReader

public LineReader(File file,
                  OffsetReader offstReader)
Method Detail

open

public void open()
          throws IOException
method we must inovke before any access to lines

Throws:
IOException - if any probem while opening reader

close

public void close()
           throws IOException
Close the reader.

Throws:
IOException - if any problem while closing reader

readLine2

public String readLine2(long position)
                 throws IOException
Read a line from a given position.

Parameters:
position - position of the line in the file
Returns:
the line found, or null
Throws:
IOException - if any problem while reading

readLine2

public String[] readLine2(long position,
                          int length)
                   throws IOException
Read some line(s) from a given position.

Parameters:
position - position of the line in the file
length - the number of lines we want
Returns:
the array of lines required, or null if eof
Throws:
IOException - if any problem while reading

readLine

public String readLine(long position)
                throws IOException
Read a line from a given position.

Parameters:
position - position of the line in the file
Returns:
the line found, or null
Throws:
IOException - if any problem while reading

readLine

public String[] readLine(long position,
                         int length)
                  throws IOException
Read some line(s) from a given position.

Parameters:
position - position of the line in the file
length - the number of lines we want
Returns:
the array of lines required, or null if eof
Throws:
IOException - if any problem while reading

update

public void update()
            throws IOException
check if reader is up to date, and if not perform an update.

Throws:
IOException - if any problem while updating

match

public boolean match(String line)
Matcher of line for this reader.

Parameters:
line - the line to be accepted by this line reader
Returns:
true if the line must be used,false otherwise

getNbLines

public long getNbLines()
Returns:
the number of lines found in the file

getFile

public File getFile()
Returns:
the file used to read lines

getOffsetReader

public OffsetReader getOffsetReader()
Returns:
the offset reader used to obtain offsets.

getParent

public LineReader getParent()
Returns:
the parent LineReader, or null if none

isUpToDate

public boolean isUpToDate()
Returns:
true if file is up to date,false otherwise

toString

public String toString()
Overrides:
toString in class Object

finalize

protected void finalize()
                 throws Throwable
Overrides:
finalize in class Object
Throws:
Throwable

ensureOpen

protected void ensureOpen()

isOpen

public boolean isOpen()

getId

public String getId()

setId

public void setId(String id)


Copyright © 1999-2010 CodeLutin. All Rights Reserved.