|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.univocity.parsers.common.AbstractWriter<S>
S
- The specific writer settings configuration class, which can potentially provide additional configuration options supported by the writer implementation.public abstract class AbstractWriter<S extends CommonWriterSettings<?>>
The AbstractWriter class provides a common ground for all writers in uniVocity-parsers.
It handles all settings defined by CommonWriterSettings
, and delegates the writing algorithm implementation to its subclasses through the abstract method processRow(Object[])
The following (absolutely required) attributes are exposed to subclasses:
WriterCharAppender
): the character writer that appends characters from a given input into an internal buffer
CsvWriter
,
CsvWriterSettings
,
FixedWidthWriter
,
FixedWidthWriterSettings
,
WriterCharAppender
,
RowWriterProcessor
Field Summary | |
---|---|
protected CharAppender |
appender
|
protected String |
emptyValue
|
protected String |
nullValue
|
Constructor Summary | |
---|---|
AbstractWriter(Writer writer,
S settings)
All writers must support, at the very least, the settings provided by CommonWriterSettings . |
Method Summary | ||
---|---|---|
protected void |
appendToRow(char ch)
Appends the given character to the output row. |
|
protected void |
appendValueToRow()
Appends the processed sequence of characters in appender to the output row. |
|
void |
close()
Closes the Writer given in this class construtor. |
|
void |
commentRow(String comment)
Writes a comment row to the output. |
|
void |
flush()
Flushes the Writer given in this class constructor. |
|
protected String |
getStringValue(Object element)
Converts a given object to its String representation for writing to the output. |
|
void |
processRecord(Object... record)
Processes the data given for an individual record with the RowWriterProcessor provided by CommonWriterSettings.getRowWriterProcessor() , then writes it. |
|
void |
processRecord(Object record)
Processes the data given for an individual record with the RowWriterProcessor provided by CommonWriterSettings.getRowWriterProcessor() , then writes it. |
|
void |
processRecords(Iterable<?> records)
Iterates over all records, processes each one with the RowWriterProcessor provided by CommonWriterSettings.getRowWriterProcessor() , and writes them. |
|
void |
processRecords(Object[] records)
Iterates over all records, processes each one with the RowWriterProcessor provided by CommonWriterSettings.getRowWriterProcessor() , and writes them. |
|
void |
processRecordsAndClose(Iterable<?> allRecords)
Iterates over all records, processes each one with the RowWriterProcessor provided by CommonWriterSettings.getRowWriterProcessor() , and writes them, then finally and closes the output |
|
void |
processRecordsAndClose(Object[] allRecords)
Iterates over all records, processes each one with the RowWriterProcessor provided by CommonWriterSettings.getRowWriterProcessor() , and writes them, then finally and closes the output |
|
protected abstract void |
processRow(Object[] row)
Format-specific implementation for writing a single record into the output. |
|
protected int |
skipLeadingWhitespace(String element)
Identifies the starting character index of a value being written if leading whitespaces are to be discarded. |
|
void |
writeEmptyRow()
Writes an empty line to the output. |
|
void |
writeHeaders()
Writes the headers defined in CommonSettings.getHeaders() |
|
void |
writeHeaders(Collection<String> headers)
Writes the given collection of headers to the output. |
|
void |
writeHeaders(String... headers)
Writes the given collection of headers to the output. |
|
void |
writeRow(Collection<Object> row)
Writes the data given for an individual record. |
|
void |
writeRow(Object... row)
Writes the data given for an individual record. |
|
void |
writeRow(String row)
Writes a plain (potentially free-text) String as a line to the output. |
|
void |
writeRows(Collection<Object[]> rows)
Iterates over all records and writes them to the output. |
|
|
writeRows(Iterable<C> rows)
Iterates over all records and writes them to the output. |
|
void |
writeRows(Object[][] rows)
Iterates over all records and writes them to the output. |
|
void |
writeRowsAndClose(Collection<Object[]> allRows)
Iterates over all records, writes them and closes the output. |
|
|
writeRowsAndClose(Iterable<C> allRows)
Iterates over all records, writes them and closes the output. |
|
void |
writeRowsAndClose(Object[][] allRows)
Iterates over all records, writes them and closes the output. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final String nullValue
protected final String emptyValue
protected final CharAppender appender
Constructor Detail |
---|
public AbstractWriter(Writer writer, S settings)
CommonWriterSettings
. The AbstractWriter requires its configuration to be properly initialized.
writer
- the output resource that will receive the format-specific records as defined by subclasses of AbstractWriter
.settings
- the parser configurationMethod Detail |
---|
protected abstract void processRow(Object[] row)
The AbstractWriter handles the initialization and processing of the output until it is ready to be written (generally, reorganizing it and passing it on to a RowWriterProcessor
).
It then delegates the record to the writer-specific implementation defined by processRow(Object[])
. In general, an implementation of processRow(Object[])
will perform the following steps:
appender
object. The an individual value is processed, the appendValueToRow()
method must be called. This will clear the accumulated value in appender
and add it to the output row.appendToRow(char)
Once the processRow(Object[])
method returns, a row will be written to the output with the processed information, and a newline will be automatically written after the given contents. The newline character sequence will conform to what is specified in Format.getLineSeparator()
This cycle repeats until the writing process is stopped by the user or an error happens.
In case of errors, the unchecked exception TextWritingException
will be thrown and all resources in use will be closed automatically. The exception should contain the cause and more information about the output state when the error happened.
row
- the data to be written to the output in the expected format.CharAppender
,
CommonWriterSettings
protected final void appendValueToRow()
appender
to the output row.
protected final void appendToRow(char ch)
ch
- the character to append to the output rowpublic final void writeHeaders()
CommonSettings.getHeaders()
A TextWritingException
will be thrown if no headers were defined or if records were already written to the output.
public final void writeHeaders(Collection<String> headers)
A TextWritingException
will be thrown if no headers were defined or if records were already written to the output.
headers
- the headers to write to the output.public final void writeHeaders(String... headers)
A TextWritingException
will be thrown if no headers were defined or if records were already written to the output.
headers
- the headers to write to the output.public final void processRecordsAndClose(Iterable<?> allRecords)
RowWriterProcessor
provided by CommonWriterSettings.getRowWriterProcessor()
, and writes them, then finally and closes the output
An IllegalStateException
will be thrown if no RowWriterProcessor
is provided by CommonWriterSettings.getRowWriterProcessor()
.
allRecords
- the records to be transformed by a RowWriterProcessor
and then written to the outputpublic final void processRecordsAndClose(Object[] allRecords)
RowWriterProcessor
provided by CommonWriterSettings.getRowWriterProcessor()
, and writes them, then finally and closes the output
An IllegalStateException
will be thrown if no RowWriterProcessor
is provided by CommonWriterSettings.getRowWriterProcessor()
.
allRecords
- the records to be transformed by a RowWriterProcessor
and then written to the outputpublic final void processRecords(Iterable<?> records)
RowWriterProcessor
provided by CommonWriterSettings.getRowWriterProcessor()
, and writes them.
The output will remain open for further writing.
An IllegalStateException
will be thrown if no RowWriterProcessor
is provided by CommonWriterSettings.getRowWriterProcessor()
.
records
- the records to be transformed by a RowWriterProcessor
and then written to the outputpublic final void processRecords(Object[] records)
RowWriterProcessor
provided by CommonWriterSettings.getRowWriterProcessor()
, and writes them.
The output will remain open for further writing.
An IllegalStateException
will be thrown if no RowWriterProcessor
was provided by CommonWriterSettings.getRowWriterProcessor()
.
records
- the records to transformed by a RowWriterProcessor
and then written to the outputpublic final void processRecord(Object... record)
RowWriterProcessor
provided by CommonWriterSettings.getRowWriterProcessor()
, then writes it.
The output will remain open for further writing.
An IllegalStateException
will be thrown if no RowWriterProcessor
is provided by CommonWriterSettings.getRowWriterProcessor()
.
record
- the information of a single record to be transformed by a RowWriterProcessor
and then written to the outputpublic final void processRecord(Object record)
RowWriterProcessor
provided by CommonWriterSettings.getRowWriterProcessor()
, then writes it.
The output will remain open for further writing.
An IllegalStateException
will be thrown if no RowWriterProcessor
is provided by CommonWriterSettings.getRowWriterProcessor()
.
record
- the information of a single record to be transformed by a RowWriterProcessor
and then written to the outputpublic final <C extends Collection<Object[]>> void writeRowsAndClose(Iterable<C> allRows)
Note this method will not use the RowWriterProcessor
. Use processRecordsAndClose(Iterable)
for that.
allRows
- the rows to be written to the outputpublic final void writeRowsAndClose(Collection<Object[]> allRows)
Note this method will not use the RowWriterProcessor
. Use processRecordsAndClose(Object[])
for that.
allRows
- the rows to be written to the outputpublic final void writeRowsAndClose(Object[][] allRows)
Note this method will not use the RowWriterProcessor
. Use processRecordsAndClose(Object[])
for that.
allRows
- the rows to be written to the outputpublic final void writeRows(Object[][] rows)
The output will remain open for further writing.
Note this method will not use the RowWriterProcessor
. Use processRecords(Object[])
for that.
rows
- the rows to be written to the outputpublic final <C extends Collection<Object[]>> void writeRows(Iterable<C> rows)
The output will remain open for further writing.
Note this method will not use the RowWriterProcessor
. Use processRecords(Iterable)
for that.
rows
- the rows to be written to the outputpublic final void writeRows(Collection<Object[]> rows)
The output will remain open for further writing.
Note this method will not use the RowWriterProcessor
. Use processRecords(Iterable)
for that.
rows
- the rows to be written to the outputpublic final void writeRow(Collection<Object> row)
The output will remain open for further writing.
Note this method will not use the RowWriterProcessor
. Use processRecord(Object)
for that.
row
- the information of a single record to be written to the outputpublic final void writeRow(Object... row)
The output will remain open for further writing.
If the given data is null or empty, and CommonSettings.getSkipEmptyLines()
is true, the input will be just ignored.
If CommonSettings.getSkipEmptyLines()
is false, then an empty row will be written to the output (as specified by writeEmptyRow()
).
In case of any errors, a TextWritingException
will be thrown and the Writer
given in the constructor will be closed.
Note this method will not use the RowWriterProcessor
. Use processRecord(Object)
for that.
row
- the information of a single record to be written to the outputpublic final void writeRow(String row)
A newline will automatically written after the given contents. The newline character sequence will conform to what is specified in Format.getLineSeparator()
The writer implementation has no control over the format of this content.
The output will remain open for further writing.
row
- the line to be written to the outputpublic final void writeEmptyRow()
The newline character sequence will conform to what is specified in Format.getLineSeparator()
The output will remain open for further writing.
public final void commentRow(String comment)
A newline will automatically written after the given contents. The newline character sequence will conform to what is specified in Format.getLineSeparator()
The output will remain open for further writing.
comment
- the content to be written as a comment to the outputprotected final int skipLeadingWhitespace(String element)
Implementation note whitespaces are considered all characters where ch <= ' ' evaluates to true
element
- the String to be scanned for leading whitespaces.
public final void flush()
Writer
given in this class constructor.
An IllegalStateException will be thrown in case of any errors, and the writer will be closed.
public final void close()
Writer
given in this class construtor.
An IllegalStateException will be thrown in case of any errors.
protected String getStringValue(Object element)
nullValue
is returned.emptyValue
is returned
element
- the object to be converted into a String.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |