fr.ifremer.isisfish.logging.io
Class OffsetReader

java.lang.Object
  extended by fr.ifremer.isisfish.logging.io.OffsetReader
Direct Known Subclasses:
FileOffsetReader, MemoryOffsetReader

public abstract class OffsetReader
extends Object

Abstract implementation of OffsetReader giving generic algorithms to extract offsets from a LineReader.

Author:
chemit

Field Summary
protected  long nbLines
          number of lines managed by the reader
 
Constructor Summary
OffsetReader()
           
 
Method Summary
 void close()
          Close the reader
protected  long createOffsets(LineReader lineReader)
           
protected  long createOffsets(LineReader lineReader, LineReader parent)
           
protected  long createOffsetsForLog(LineReader lineReader)
           
 void deleteOffsetFile()
          delete offset resources
 long getNbLines()
           
abstract  long getOffset(long position)
          Obtain an offset for a position
protected  boolean isLogEntry(String line)
           
protected abstract  boolean needCreate()
           
 void open(LineReader reader)
          Open the reader
protected  String readLine(BufferedReader reader)
          read a line from reader including terminaison caracters
protected abstract  void storeOffset(long position, long offset)
          Save the offset of the line for a given position
 void update(LineReader lineReader)
          Update the reader
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

nbLines

protected long nbLines
number of lines managed by the reader

Constructor Detail

OffsetReader

public OffsetReader()
Method Detail

storeOffset

protected abstract void storeOffset(long position,
                                    long offset)
                             throws IOException
Save the offset of the line for a given position

Parameters:
position - current line position
offset - current offset of line
Throws:
IOException - if any problem while storing

needCreate

protected abstract boolean needCreate()
                               throws IOException
Returns:
true if the reader need to create his internal datas.
Throws:
IOException - if any problme while creating

getOffset

public abstract long getOffset(long position)
                        throws IOException
Obtain an offset for a position

Parameters:
position - position of the line
Returns:
the offset of the first car of the given line
Throws:
IOException - todo

open

public void open(LineReader reader)
          throws IOException
Open the reader

Parameters:
reader - LineReader linked with this reader
Throws:
IOException - if any problem while opening

close

public void close()
           throws IOException
Close the reader

Throws:
IOException - if any problem while closing

getNbLines

public long getNbLines()
Returns:
the number of lines registered in this reader

update

public void update(LineReader lineReader)
            throws IOException
Update the reader

Parameters:
lineReader - lineReader linked with this reader
Throws:
IOException - if any problem while updating

isLogEntry

protected boolean isLogEntry(String line)
                      throws IOException
Throws:
IOException

readLine

protected String readLine(BufferedReader reader)
                   throws IOException
read a line from reader including terminaison caracters

Parameters:
reader - reader to use
Returns:
the line with the terminaison
Throws:
IOException - if any problem while reading

createOffsets

protected long createOffsets(LineReader lineReader)
                      throws IOException
Throws:
IOException

createOffsetsForLog

protected long createOffsetsForLog(LineReader lineReader)
                            throws IOException
Throws:
IOException

createOffsets

protected long createOffsets(LineReader lineReader,
                             LineReader parent)
                      throws IOException
Throws:
IOException

deleteOffsetFile

public void deleteOffsetFile()
delete offset resources



Copyright © 1999-2012 CodeLutin. All Rights Reserved.