Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

alma::acs::logging::engine::io::IOHelper Class Reference

List of all members.

Public Member Functions

synchronized long loadLogs (String fileName, ACSRemoteLogListener logListener, ACSRemoteRawLogListener rawLogListener, ACSRemoteErrorListener errorListener, IOPorgressListener progressListener, boolean gzip) throws IOException, Exception
synchronized long loadLogs (String fileName, ACSRemoteLogListener logListener, ACSRemoteRawLogListener rawLogListener, ACSRemoteErrorListener errorListener, IOPorgressListener progressListener) throws IOException, Exception
synchronized void loadLogs (BufferedReader reader, ACSRemoteLogListener logListener, ACSRemoteRawLogListener rawLogListener, ACSRemoteErrorListener errorListener, IOPorgressListener progressListener) throws IOException, Exception
synchronized void writeHeader (BufferedWriter wBuffer) throws IOException
synchronized void terminateSave (BufferedWriter outBuffer, boolean close) throws IOException
synchronized int saveLog (BufferedWriter outBuf, ILogEntry log) throws IOException
synchronized void saveLogs (String fileName, Collection< ILogEntry > logs, IOPorgressListener progressListener, boolean append, boolean gzip) throws IOException
synchronized void saveLogs (String fileName, Collection< ILogEntry > logs, IOPorgressListener progressListener, boolean append, boolean gzip, int compressionLevel) throws IOException
synchronized void saveLogs (BufferedWriter outBuffer, Collection< ILogEntry > logs, IOPorgressListener progressListener) throws IOException
synchronized void saveLogs (String fileName, Iterator< ILogEntry >iterator, IOPorgressListener progressListener, boolean append, boolean gzip) throws IOException
synchronized void saveLogs (String fileName, Iterator< ILogEntry >iterator, IOPorgressListener progressListener, boolean append, boolean gzip, int compressionLevel) throws IOException
synchronized BufferedWriter getBufferedWriter (String fileName, boolean append, boolean gzip, int compressionLevel) throws FileNotFoundException, IOException
synchronized BufferedWriter getBufferedWriter (String fileName, boolean append, boolean gzip) throws FileNotFoundException, IOException
synchronized BufferedReader getBufferedReader (String fileName) throws FileNotFoundException, IOException
synchronized void saveLogs (BufferedWriter outBuf, Iterator< ILogEntry > iterator, IOPorgressListener progressListener) throws IOException
void stopIO ()

Static Public Attributes

final int DEFAULT_COMPRESSION_LEVEL = 5

Protected Attributes

volatile boolean stopped = false

Private Member Functions

void injectLog (StringBuilder logStr, ACSRemoteLogListener logListener, ACSRemoteRawLogListener rawLogListener, ACSRemoteErrorListener errorListener)

Private Attributes

ACSLogParser parser

Detailed Description

An helper class to perform synchronous I/O operations like load and save.

Load and save methods are executed in a synchronous way i.e. they do not return until the I/O is terminated (or an exception occurs).
Intermediate results useful to monitor the progress of the I/O are communicated to the listeners implementing the IOProgressListener interface.

The load and save methods of this class are synchronized but I would not say that this class is thread safe because it does not hold and lock the objects it receives as parameters like for example the BufferReader and the BufferWriter. So thread safety must be ensured by the owner of such objects.

Loading
The loading is performed through one of the overloaded loadLogs methods. The bytes read and the number of the logs successfully read are sent to the listeners implementing the IOProgressListener interface. If there are filters, an audience or a discard level defined, then each log is checked before being sent to the listener.

Saving
The saving of logs can be done by passing a Collection of logs or an Iteratorto one of the overloaded saveLogs methods. Such methods communicates the progress to the listener implementing the IOProgressListener interface.

Saving logs by passing the name of the file does not require any extra steps.
Saving logs by passing a BufferedWriter is always a three steps procedure:

  1. call the prepareSaveFile to write XML header
  2. save the logs by calling one of the saveLogs or the saveLog
  3. execute Save to add the closing XML tags, flush and close the buffer

Load and save can be very long operations. To stop an I/O, the stopIO() must be executed.

Author:
acaproni


Member Function Documentation

synchronized BufferedReader alma::acs::logging::engine::io::IOHelper::getBufferedReader String  fileName  )  throws FileNotFoundException, IOException [inline]
 

Return the reader to get logs from

The reader can be compressed (GZIP) or not depending on the extension of the file name (i.e. ".gz" or ".xml").

Parameters:
fileName The name of the file to read
Returns:
the reader to get logs from

synchronized BufferedWriter alma::acs::logging::engine::io::IOHelper::getBufferedWriter String  fileName,
boolean  append,
boolean  gzip
throws FileNotFoundException, IOException [inline]
 

Create a BufferedWriter to save logs into.

In case of compressed files, the default compression level is used

Parameters:
fileName The name of the file to write logs into
append 
  • if true if the logs in the collection must be appended to an existing file
  • if false and the file already exists, it is deleted before writing
gzip If true the file is compressed (GZIP) with the default level
Returns:
the BufferedWriter to save logs into the file of the given name

synchronized BufferedWriter alma::acs::logging::engine::io::IOHelper::getBufferedWriter String  fileName,
boolean  append,
boolean  gzip,
int  compressionLevel
throws FileNotFoundException, IOException [inline]
 

Create a BufferedWriter to save logs into

Parameters:
fileName The name of the file to write logs into
append 
  • if true if the logs in the collection must be appended to an existing file
  • if false and the file already exists, it is deleted before writing
gzip If true the file is compressed (GZIP)
compressionLevel The compressionLevel for GZIP compression (0..9); ignored if gzip is false>/code>
Returns:
the BufferedWriter to save logs into the file of the given name

void alma::acs::logging::engine::io::IOHelper::injectLog StringBuilder  logStr,
ACSRemoteLogListener  logListener,
ACSRemoteRawLogListener  rawLogListener,
ACSRemoteErrorListener  errorListener
[inline, private]
 

Inject the log into the engine

Parameters:
logStr The string representation of the log
logListener The listener i.e. the callback for each new log to add

synchronized void alma::acs::logging::engine::io::IOHelper::loadLogs BufferedReader  reader,
ACSRemoteLogListener  logListener,
ACSRemoteRawLogListener  rawLogListener,
ACSRemoteErrorListener  errorListener,
IOPorgressListener  progressListener
throws IOException, Exception [inline]
 

Load the logs from the given BufferedReader.

The logs are sent to the ACSRemoteLogListener and /or to the ACSRemoteRawLogListener.

Parameters:
reader The reader to read logs from
logListener The callback for each new log read from the IO
rawLogListener The callback for each new XML log read from the IO
errorListener The listener for errors
progressListener The listener to be notified about the bytes read
Exceptions:
IOException In case of an IO error while reading the file
Exception In case of error building the parser

The size of the buffer

The buffer of data read from the file

The cursor to scan the buffer (circular)

When it is 0, then we have to read another block from the file

synchronized long alma::acs::logging::engine::io::IOHelper::loadLogs String  fileName,
ACSRemoteLogListener  logListener,
ACSRemoteRawLogListener  rawLogListener,
ACSRemoteErrorListener  errorListener,
IOPorgressListener  progressListener
throws IOException, Exception [inline]
 

Load the logs from the file with the given name.

The logs are sent to the ACSRemoteLogListener and /or to the ACSRemoteRawLogListener.

The file can be compressed (GZIP) or plain. Compressed file names must terminate with .gz while plain XML file names must end with .xml.

Parameters:
fileName The name of the file to read logs from. fileName must terminate with .gz or .xml (case insensitive)
logListener The callback for each new log read from the IO
rawLogListener The callback for each new XML log read from the IO
errorListener The listener for errors
progressListener The listener to be notified about the bytes read
Returns:
The length of the file to read
Exceptions:
IOException In case of an IO error while reading the file
Exception In case of error building the parser

synchronized long alma::acs::logging::engine::io::IOHelper::loadLogs String  fileName,
ACSRemoteLogListener  logListener,
ACSRemoteRawLogListener  rawLogListener,
ACSRemoteErrorListener  errorListener,
IOPorgressListener  progressListener,
boolean  gzip
throws IOException, Exception [inline]
 

Load the logs from the file with the given name.

The logs are sent to the ACSRemoteLogListener and /or to the ACSRemoteRawLogListener.

Parameters:
fileName The name of the file to read logs from
logListener The callback for each new log read from the IO
rawLogListener The callback for each new XML log read from the IO
errorListener The listener for errors
progressListener The listener to be notified about the bytes read
gzip If true the file to read is compressed in GZIP format
Returns:
The length of the file to read
Exceptions:
IOException In case of an IO error while reading the file
Exception In case of error building the parser

synchronized int alma::acs::logging::engine::io::IOHelper::saveLog BufferedWriter  outBuf,
ILogEntry  log
throws IOException [inline]
 

Save a log in the passed file

Parameters:
outbuf The buffered writer where the logs have to be stored
log The log to save
progressListener The listener to be notified about the bytes written
Exceptions:
IOException In case of an IO error while writing logs into the file

synchronized void alma::acs::logging::engine::io::IOHelper::saveLogs BufferedWriter  outBuf,
Iterator< ILogEntry iterator,
IOPorgressListener  progressListener
throws IOException [inline]
 

Save a collection of logs on a BufferedWriter.

The buffer must be initialized and terminated i.e. the prepareSaveFile and the terminateSave are not executed by this method.

Parameters:
outBuf The buffer to write logs into
logs The non empty collection of logs to save
progressListener The listener to be notified about the number of bytes written
Exceptions:
IOException In case of error writing

synchronized void alma::acs::logging::engine::io::IOHelper::saveLogs String  fileName,
Iterator< ILogEntry iterator,
IOPorgressListener  progressListener,
boolean  append,
boolean  gzip,
int  compressionLevel
throws IOException [inline]
 

Save the logs available through an Iterator.

Parameters:
filename The name of the file to write logs into
logs The non empty collection of logs to save
progressListener The listener to be notified about the number of bytes written
append 
  • if true if the logs in the collection must be appended to an existing file
  • if false and the file already exists, it is deleted before writing
gzip If true the file is compressed (GZIP)
compressionLevel The compressionLevel for GZIP compression (0..9); ignored if gzip is false>/code>
Exceptions:
IOException In case of error writing

synchronized void alma::acs::logging::engine::io::IOHelper::saveLogs String  fileName,
Iterator< ILogEntry iterator,
IOPorgressListener  progressListener,
boolean  append,
boolean  gzip
throws IOException [inline]
 

Save the logs available through an Iterator.

Parameters:
filename The name of the file to write logs into
logs The non empty collection of logs to save
progressListener The listener to be notified about the number of bytes written
append 
  • if true if the logs in the collection must be appended to an existing file
  • if false and the file already exists, it is deleted before writing
gzip If true the file is compressed (GZIP) with the default compression level
Exceptions:
IOException In case of error writing

synchronized void alma::acs::logging::engine::io::IOHelper::saveLogs BufferedWriter  outBuffer,
Collection< ILogEntry logs,
IOPorgressListener  progressListener
throws IOException [inline]
 

Save a collection of logs on a BufferedWriter.

The buffer must be initialized and terminated i.e. the prepareSaveFile and the terminateSave are not executed by this method.

Parameters:
outBuffer The writer to write logs into
logs The non empty collection of logs to save
progressListener The listener to be notified about the number of bytes written
gzip If true the file is compressed (GZIP)
Exceptions:
IOException In case of error writing

synchronized void alma::acs::logging::engine::io::IOHelper::saveLogs String  fileName,
Collection< ILogEntry logs,
IOPorgressListener  progressListener,
boolean  append,
boolean  gzip,
int  compressionLevel
throws IOException [inline]
 

Save a collection of logs on disk

Parameters:
fileName The name of the file to store logs into
logs The non empty collection of logs to save
progressListener The listener to be notified about the number of bytes written
append 
  • if true if the logs in the collection must be appended to an existing file
  • if false and the file aredy exists, it is deleted before writing
gzip If true the file is compressed (GZIP)
compressionLevel The compressionLevel for GZIP compression (0..9); ignored if gzip is is false>/code>
Exceptions:
IOException In case of error writing

synchronized void alma::acs::logging::engine::io::IOHelper::saveLogs String  fileName,
Collection< ILogEntry logs,
IOPorgressListener  progressListener,
boolean  append,
boolean  gzip
throws IOException [inline]
 

Save a collection of logs on disk

Parameters:
fileName The name of the file to store logs into
logs The non empty collection of logs to save
progressListener The listener to be notified about the number of bytes written
append 
  • if true if the logs in the collection must be appended to an existing file
  • if false and the file aredy exists, it is deleted before writing
gzip If true the file is compressed (GZIP) with the default compression level
Exceptions:
IOException In case of error writing

void alma::acs::logging::engine::io::IOHelper::stopIO  )  [inline]
 

Call this method if you wish to interrupt a load or a save.

Load and save are executed synchronously so this method has to be called by a separate thread. A typical example is the "Abort" button of a dialog: when the user presses such a button, this method is invoked by the swing thread.

synchronized void alma::acs::logging::engine::io::IOHelper::terminateSave BufferedWriter  outBuffer,
boolean  close
throws IOException [inline]
 

Terminate the saving.

This method must executed when the save terminates. It does the following:

  • write the closing XML tags
  • flush the output file
  • close the file
Parameters:
outBuffer The file to close
close If true the BufferedWriter is closed
Exceptions:
IOException In case of an IO error

synchronized void alma::acs::logging::engine::io::IOHelper::writeHeader BufferedWriter  wBuffer  )  throws IOException [inline]
 

Write the XML header in the buffered writer

Parameters:
bw 
Exceptions:
IOException 


Member Data Documentation

final int alma::acs::logging::engine::io::IOHelper::DEFAULT_COMPRESSION_LEVEL = 5 [static]
 

The default compression level while saving files

ACSLogParser alma::acs::logging::engine::io::IOHelper::parser [private]
 

The parser

volatile boolean alma::acs::logging::engine::io::IOHelper::stopped = false [protected]
 

Signal that a load or a save must be stopped


The documentation for this class was generated from the following file:
Generated on Thu Apr 30 02:53:50 2009 for ACS Java API by doxygen 1.3.8