Class FileAccumulator
java.lang.Object
com.scivicslab.turingworkflow.plugins.logoutput.FileAccumulator
- All Implemented Interfaces:
com.scivicslab.pojoactor.core.accumulator.Accumulator,Closeable,AutoCloseable
public class FileAccumulator
extends Object
implements com.scivicslab.pojoactor.core.accumulator.Accumulator, Closeable
An
Accumulator implementation that writes output entries to a text file.
Each entry is formatted with a [source] prefix on every line and
flushed to disk immediately. The accumulator implements Closeable
so it can be used in try-with-resources blocks.
Once close() has been called, subsequent calls to add(java.lang.String, java.lang.String, java.lang.String)
will increment the counter but produce no file output.
- Since:
- 1.0
- Author:
- devteam@scivicslab.com
-
Constructor Summary
ConstructorsConstructorDescriptionFileAccumulator(String filePath) Constructs aFileAccumulatorthat writes to the specified file path string.FileAccumulator(Path filePath) Constructs aFileAccumulatorthat writes to the specified file path. -
Method Summary
-
Constructor Details
-
FileAccumulator
Constructs aFileAccumulatorthat writes to the specified file path. The file is created (or truncated) immediately.- Parameters:
filePath- the path to the output file- Throws:
IOException- if the file cannot be opened for writing
-
FileAccumulator
Constructs aFileAccumulatorthat writes to the specified file path string.- Parameters:
filePath- the path string to the output file- Throws:
IOException- if the file cannot be opened for writing
-
-
Method Details
-
getFilePath
Returns the path to the output file.- Returns:
- the file path
-
add
Writes the formatted entry to the file and flushes immediately. If the accumulator is closed or the data is
null/empty, only the counter is incremented.- Specified by:
addin interfacecom.scivicslab.pojoactor.core.accumulator.Accumulator
-
getSummary
- Specified by:
getSummaryin interfacecom.scivicslab.pojoactor.core.accumulator.Accumulator
-
getCount
public int getCount()- Specified by:
getCountin interfacecom.scivicslab.pojoactor.core.accumulator.Accumulator
-
clear
public void clear()- Specified by:
clearin interfacecom.scivicslab.pojoactor.core.accumulator.Accumulator
-
close
public void close()Closes the underlying file writer. After this method returns, subsequent calls toadd(java.lang.String, java.lang.String, java.lang.String)will no longer produce file output. Callingclose()multiple times has no additional effect.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-