com.univocity.parsers.fixed
Class FixedWidthWriter

java.lang.Object
  extended by com.univocity.parsers.common.AbstractWriter<FixedWidthWriterSettings>
      extended by com.univocity.parsers.fixed.FixedWidthWriter

public class FixedWidthWriter
extends AbstractWriter<FixedWidthWriterSettings>

A fast and flexible fixed-with writer implementation.

Author:
uniVocity Software Pty Ltd - parsers@univocity.com
See Also:
FixedWidthFormat, FixedWidthFields, FixedWidthWriterSettings, FixedWidthParser, AbstractWriter

Field Summary
 
Fields inherited from class com.univocity.parsers.common.AbstractWriter
appender, emptyValue, expandRows, headers, nullValue, recordCount, usingNullOrEmptyValue, whitespaceRangeStart, writingHeaders
 
Constructor Summary
FixedWidthWriter(File file, Charset encoding, FixedWidthWriterSettings settings)
          The FixedWidthWriter supports all settings provided by FixedWidthWriterSettings, and requires this configuration to be properly initialized.
FixedWidthWriter(File file, FixedWidthWriterSettings settings)
          The FixedWidthWriter supports all settings provided by FixedWidthWriterSettings, and requires this configuration to be properly initialized.
FixedWidthWriter(File file, String encoding, FixedWidthWriterSettings settings)
          The FixedWidthWriter supports all settings provided by FixedWidthWriterSettings, and requires this configuration to be properly initialized.
FixedWidthWriter(FixedWidthWriterSettings settings)
          The FixedWidthWriter supports all settings provided by FixedWidthWriterSettings, and requires this configuration to be properly initialized.
FixedWidthWriter(OutputStream output, Charset encoding, FixedWidthWriterSettings settings)
          The FixedWidthWriter supports all settings provided by FixedWidthWriterSettings, and requires this configuration to be properly initialized.
FixedWidthWriter(OutputStream output, FixedWidthWriterSettings settings)
          The FixedWidthWriter supports all settings provided by FixedWidthWriterSettings, and requires this configuration to be properly initialized.
FixedWidthWriter(OutputStream output, String encoding, FixedWidthWriterSettings settings)
          The FixedWidthWriter supports all settings provided by FixedWidthWriterSettings, and requires this configuration to be properly initialized.
FixedWidthWriter(Writer writer, FixedWidthWriterSettings settings)
          The FixedWidthWriter supports all settings provided by FixedWidthWriterSettings, and requires this configuration to be properly initialized.
 
Method Summary
protected  void initialize(FixedWidthWriterSettings settings)
          Initializes the Fixed-Width writer with CSV-specific configuration
protected  void processRow(Object[] row)
          Format-specific implementation for writing a single record into the output.
 
Methods inherited from class com.univocity.parsers.common.AbstractWriter
addStringValues, addValue, addValue, addValue, addValues, addValues, appendToRow, appendValueToRow, close, commentRow, commentRowToString, discardValues, enableNewlineAfterRecord, expand, flush, getRecordCount, getStringValue, processObjectRecords, processObjectRecordsAndClose, processObjectRecordsAndClose, processObjectRecordsToString, processObjectRecordsToString, processRecord, processRecord, processRecord, processRecord, processRecords, processRecords, processRecords, processRecords, processRecordsAndClose, processRecordsAndClose, processRecordsAndClose, processRecordsAndClose, processRecordsToString, processRecordsToString, processRecordsToString, processRecordsToString, processRecordToString, processRecordToString, processRecordToString, processRecordToString, processValuesToRow, processValuesToString, skipLeadingWhitespace, updateFieldExclusion, updateFieldExclusion, updateFieldSelection, updateFieldSelection, writeEmptyRow, writeHeaders, writeHeaders, writeHeaders, writeHeadersToString, writeHeadersToString, writeHeadersToString, writeObjectRows, writeObjectRowsAndClose, writeObjectRowsAndClose, writeObjectRowsToString, writeRow, writeRow, writeRow, writeRow, writeRow, writeRow, writeRows, writeRows, writeRows, writeRows, writeRows, writeRowsAndClose, writeRowsAndClose, writeRowsAndClose, writeRowsAndClose, writeRowsAndClose, writeRowsToString, writeRowsToString, writeRowsToString, writeRowsToString, writeRowsToString, writeRowToString, writeRowToString, writeRowToString, writeRowToString, writeRowToString, writeStringRows, writeStringRows, writeStringRows, writeStringRowsAndClose, writeStringRowsAndClose, writeStringRowsAndClose, writeStringRowsToString, writeStringRowsToString, writeStringRowsToString, writeValuesToRow, writeValuesToString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FixedWidthWriter

public FixedWidthWriter(FixedWidthWriterSettings settings)
The FixedWidthWriter supports all settings provided by FixedWidthWriterSettings, and requires this configuration to be properly initialized.

Important: by not providing an instance of Writer to this constructor, only the operations that write to Strings are available.

Parameters:
settings - the fixed-width writer configuration

FixedWidthWriter

public FixedWidthWriter(Writer writer,
                        FixedWidthWriterSettings settings)
The FixedWidthWriter supports all settings provided by FixedWidthWriterSettings, and requires this configuration to be properly initialized.

Parameters:
writer - the output resource that will receive fixed-width records produced by this class.
settings - the fixed-width writer configuration

FixedWidthWriter

public FixedWidthWriter(File file,
                        FixedWidthWriterSettings settings)
The FixedWidthWriter supports all settings provided by FixedWidthWriterSettings, and requires this configuration to be properly initialized.

Parameters:
file - the output file that will receive fixed-width records produced by this class.
settings - the fixed-width writer configuration

FixedWidthWriter

public FixedWidthWriter(File file,
                        String encoding,
                        FixedWidthWriterSettings settings)
The FixedWidthWriter supports all settings provided by FixedWidthWriterSettings, and requires this configuration to be properly initialized.

Parameters:
file - the output file that will receive fixed-width records produced by this class.
encoding - the encoding of the file
settings - the fixed-width writer configuration

FixedWidthWriter

public FixedWidthWriter(File file,
                        Charset encoding,
                        FixedWidthWriterSettings settings)
The FixedWidthWriter supports all settings provided by FixedWidthWriterSettings, and requires this configuration to be properly initialized.

Parameters:
file - the output file that will receive fixed-width records produced by this class.
encoding - the encoding of the file
settings - the fixed-width writer configuration

FixedWidthWriter

public FixedWidthWriter(OutputStream output,
                        FixedWidthWriterSettings settings)
The FixedWidthWriter supports all settings provided by FixedWidthWriterSettings, and requires this configuration to be properly initialized.

Parameters:
output - the output stream that will be written with the fixed-width records produced by this class.
settings - the fixed-width writer configuration

FixedWidthWriter

public FixedWidthWriter(OutputStream output,
                        String encoding,
                        FixedWidthWriterSettings settings)
The FixedWidthWriter supports all settings provided by FixedWidthWriterSettings, and requires this configuration to be properly initialized.

Parameters:
output - the output stream that will be written with the fixed-width records produced by this class.
encoding - the encoding of the stream
settings - the fixed-width writer configuration

FixedWidthWriter

public FixedWidthWriter(OutputStream output,
                        Charset encoding,
                        FixedWidthWriterSettings settings)
The FixedWidthWriter supports all settings provided by FixedWidthWriterSettings, and requires this configuration to be properly initialized.

Parameters:
output - the output stream that will be written with the fixed-width records produced by this class.
encoding - the encoding of the stream
settings - the fixed-width writer configuration
Method Detail

initialize

protected final void initialize(FixedWidthWriterSettings settings)
Initializes the Fixed-Width writer with CSV-specific configuration

Specified by:
initialize in class AbstractWriter<FixedWidthWriterSettings>
Parameters:
settings - the Fixed-Width writer configuration

processRow

protected void processRow(Object[] row)
Description copied from class: AbstractWriter
Format-specific implementation for writing a single record into the output.

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 AbstractWriter.processRow(Object[]). In general, an implementation of AbstractWriter.processRow(Object[]) will perform the following steps:

Once the AbstractWriter.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, unless this is a FixedWidthWriter whose FixedWidthWriterSettings.getWriteLineSeparatorAfterRecord() evaluates to false. 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.

Specified by:
processRow in class AbstractWriter<FixedWidthWriterSettings>
Parameters:
row - the data to be written to the output in the expected format.
See Also:
CharAppender, CommonWriterSettings


Copyright © 2018 uniVocity Software Pty Ltd. All rights reserved.