Package org.jeasy.batch.core.writer
Class FileRecordWriter
- java.lang.Object
-
- org.jeasy.batch.core.writer.FileRecordWriter
-
- All Implemented Interfaces:
RecordWriter<java.lang.String>
public class FileRecordWriter extends java.lang.Object implements RecordWriter<java.lang.String>
A writer that writes records to a file.- Author:
- Mahmoud Ben Hassine (mahmoud.benhassine@icloud.com)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceFileRecordWriter.FooterCallbackCallback to write a footer to the output file.static interfaceFileRecordWriter.HeaderCallbackCallback to write a header to the output file.
-
Constructor Summary
Constructors Constructor Description FileRecordWriter(java.nio.file.Path path)Create a newFileRecordWriter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Close the writervoidopen()Open the writer.voidsetAppend(boolean append)Parameter to open the writer in append mode.voidsetCharset(java.nio.charset.Charset charset)Set the charset of the input filevoidsetFooterCallback(FileRecordWriter.FooterCallback footerCallback)Set a footer callback.voidsetHeaderCallback(FileRecordWriter.HeaderCallback headerCallback)Set a header callback.voidsetLineSeparator(java.lang.String lineSeparator)Set the line separatorvoidwriteRecords(Batch<java.lang.String> batch)Write a batch of records to a data sink.
-
-
-
Constructor Detail
-
FileRecordWriter
public FileRecordWriter(java.nio.file.Path path)
Create a newFileRecordWriter.- Parameters:
path- the output file.
-
-
Method Detail
-
setCharset
public void setCharset(java.nio.charset.Charset charset)
Set the charset of the input file- Parameters:
charset- of the input file
-
setLineSeparator
public void setLineSeparator(java.lang.String lineSeparator)
Set the line separator- Parameters:
lineSeparator- to use
-
setHeaderCallback
public void setHeaderCallback(FileRecordWriter.HeaderCallback headerCallback)
Set a header callback.- Parameters:
headerCallback- to set
-
setFooterCallback
public void setFooterCallback(FileRecordWriter.FooterCallback footerCallback)
Set a footer callback.- Parameters:
footerCallback- to set
-
setAppend
public void setAppend(boolean append)
Parameter to open the writer in append mode.- Parameters:
append- true if the writer should be opened in append mode.
-
open
public void open() throws java.lang.ExceptionDescription copied from interface:RecordWriterOpen the writer.- Specified by:
openin interfaceRecordWriter<java.lang.String>- Throws:
java.lang.Exception- if an error occurs during opening the writer
-
writeRecords
public void writeRecords(Batch<java.lang.String> batch) throws java.lang.Exception
Description copied from interface:RecordWriterWrite a batch of records to a data sink.- Specified by:
writeRecordsin interfaceRecordWriter<java.lang.String>- Parameters:
batch- of records to write.- Throws:
java.lang.Exception- if an error occurs during record writing
-
close
public void close() throws java.lang.ExceptionDescription copied from interface:RecordWriterClose the writer- Specified by:
closein interfaceRecordWriter<java.lang.String>- Throws:
java.lang.Exception- if an error occurs during closing the writer
-
-