public class ByteStreamFileWriter
extends org.metafacture.framework.helpers.DefaultObjectReceiver<byte[]>
The module opens a new output file when it receives a reset-stream
event. The setFileNameSupplier(Supplier) enables users to specify
a new file name on each invocation. the setAppendIfFileExists(boolean)
can be used to control whether existing files should be overwritten or
appended to.
| Constructor and Description |
|---|
ByteStreamFileWriter()
Creates an instance of
ByteStreamFileWriter. |
| Modifier and Type | Method and Description |
|---|---|
void |
closeStream()
Closes the current output file.
|
void |
process(byte[] bytes)
Writes
bytes to file. |
void |
resetStream()
Opens a new output file.
|
void |
setAppendIfFileExists(boolean appendIfFileExists)
Controls whether to open files in append mode if they exist.
|
void |
setFileNameSupplier(java.util.function.Supplier<java.io.File> fileNameSupplier)
Supplier for file names.
|
void |
setFlushAfterWrite(boolean flushAfterWrite)
Controls whether the output stream is flushed after each write
operation in
process(byte[]). |
public ByteStreamFileWriter()
ByteStreamFileWriter.public void setFileNameSupplier(java.util.function.Supplier<java.io.File> fileNameSupplier)
A new output file is created when process(byte[]) is called
for the first time or whenever resetStream() is called. The
name of the new file is fetched from the fileNameSupplier.
There is no default value. A file name supplier must be specified.
This property can be changed anytime during processing. It becomes effective the next time a new output file is opened.
fileNameSupplier - a supplier that returns file names.public void setAppendIfFileExists(boolean appendIfFileExists)
The default value is false.
This property can be changed anytime during processing. It becomes effective the next time a new output file is opened.
appendIfFileExists - true if new data should be appended,
false to overwrite the existing file.public void setFlushAfterWrite(boolean flushAfterWrite)
process(byte[]).
The default value is false.
This property can be changed anytime during processing. It becomes
effective on the next invocation of process(byte[]).
flushAfterWrite - true if the output stream should be flushed
after every write.public void process(byte[] bytes)
bytes to file.process in interface org.metafacture.framework.ObjectReceiver<byte[]>process in class org.metafacture.framework.helpers.DefaultObjectReceiver<byte[]>bytes - to write to fileWriteFailed - if an IO error occurredpublic void resetStream()
resetStream in interface org.metafacture.framework.LifeCycleresetStream in class org.metafacture.framework.helpers.DefaultLifeCycleCloseFailed - if the current output file could not be closed.OpenFailed - if the new output file could not be opened.public void closeStream()
closeStream in interface org.metafacture.framework.LifeCyclecloseStream in class org.metafacture.framework.helpers.DefaultLifeCycleCloseFailed - if the output file could not be closed.