Top Description Fields Constructors Methods
com.univocity.parsers.fixed

public Class FixedWidthWriter

extends AbstractWriter<FixedWidthWriterSettings>
Class Inheritance
Imports
com.univocity.parsers.common.*, java.io.*, java.nio.charset.*

A fast and flexible fixed-with writer implementation.
Author
Univocity Software Pty Ltd - [email protected]
See Also
FixedWidthFormat, FixedWidthFields, FixedWidthWriterSettings, FixedWidthParser, AbstractWriter

Field Summary

Modifier and TypeField and Description
private FieldAlignment
private FieldAlignment
private boolean
private char
private FieldAlignment[]
private int[]
private char[]
private boolean[]
private int
private int
private Lookup[]
private Lookup
private Lookup[]
private char[]
private char
private FieldAlignment[]
private boolean[]
private int[]
private char[]
Inherited from com.univocity.parsers.common.AbstractWriter:
appendercommentemptyValueexpandRowsheadersheaderTrimFlagsignoreLeadingignoreTrailingnullValuerecordCountusingNullOrEmptyValuewhitespaceRangeStartwritingHeaders

Constructor Summary

AccessConstructor and Description
public
FixedWidthWriter(FixedWidthWriterSettings
the fixed-width writer configuration
settings
)

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

public
FixedWidthWriter(Writer
the output resource that will receive fixed-width records produced by this class.
writer
,
FixedWidthWriterSettings
the fixed-width writer configuration
settings
)

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

public
FixedWidthWriter(File
the output file that will receive fixed-width records produced by this class.
file
,
FixedWidthWriterSettings
the fixed-width writer configuration
settings
)

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

public
FixedWidthWriter(File
the output file that will receive fixed-width records produced by this class.
file
,
String
the encoding of the file
encoding
,
FixedWidthWriterSettings
the fixed-width writer configuration
settings
)

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

public
FixedWidthWriter(File
the output file that will receive fixed-width records produced by this class.
file
,
Charset
the encoding of the file
encoding
,
FixedWidthWriterSettings
the fixed-width writer configuration
settings
)

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

public
FixedWidthWriter(OutputStream
the output stream that will be written with the fixed-width records produced by this class.
output
,
FixedWidthWriterSettings
the fixed-width writer configuration
settings
)

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

public
FixedWidthWriter(OutputStream
the output stream that will be written with the fixed-width records produced by this class.
output
,
String
the encoding of the stream
encoding
,
FixedWidthWriterSettings
the fixed-width writer configuration
settings
)

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

public
FixedWidthWriter(OutputStream
the output stream that will be written with the fixed-width records produced by this class.
output
,
Charset
the encoding of the stream
encoding
,
FixedWidthWriterSettings
the fixed-width writer configuration
settings
)

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

Method Summary

Modifier and TypeMethod and Description
private void
append(String element, boolean allowTrim)

protected final void
initialize(FixedWidthWriterSettings
the Fixed-Width writer configuration
settings
)

Implements abstract com.univocity.parsers.common.AbstractWriter.initialize.

Initializes the Fixed-Width writer with CSV-specific configuration
private void
processElement(String element, boolean allowTrim)

protected void
processRow(Object[]
the data to be written to the output in the expected format.
row
)

Implements abstract com.univocity.parsers.common.AbstractWriter.processRow.

Format-specific implementation for writing a single record into the output.
Inherited from com.univocity.parsers.common.AbstractWriter:
addStringValuesaddValueaddValueaddValueaddValuesaddValuesallowTrimappendToRowappendToRowappendValueToRowclosecommentRowcommentRowToStringdiscardValuesenableNewlineAfterRecordexpandflushgetRecordCountgetStringValueprocessObjectRecordsprocessObjectRecordsAndCloseprocessObjectRecordsAndCloseprocessObjectRecordsToStringprocessObjectRecordsToStringprocessRecordprocessRecordprocessRecordprocessRecordprocessRecordprocessRecordsprocessRecordsprocessRecordsprocessRecordsprocessRecordsprocessRecordsAndCloseprocessRecordsAndCloseprocessRecordsAndCloseprocessRecordsAndCloseprocessRecordsToStringprocessRecordsToStringprocessRecordsToStringprocessRecordsToStringprocessRecordToStringprocessRecordToStringprocessRecordToStringprocessRecordToStringprocessRecordToStringprocessValuesToRowprocessValuesToStringskipLeadingWhitespaceupdateFieldExclusionupdateFieldExclusionupdateFieldSelectionupdateFieldSelectionwriteEmptyRowwriteHeaderswriteHeaderswriteHeaderswriteHeadersToStringwriteHeadersToStringwriteHeadersToStringwriteObjectRowswriteObjectRowsAndClosewriteObjectRowsAndClosewriteObjectRowsToStringwriteRecordwriteRecordswriteRecordswriteRecordsAndClosewriteRecordsAndClosewriteRecordsAndClosewriteRecordsToStringwriteRecordsToStringwriteRecordToStringwriteRowwriteRowwriteRowwriteRowwriteRowwriteRowwriteRowswriteRowswriteRowswriteRowswriteRowswriteRowsAndClosewriteRowsAndClosewriteRowsAndClosewriteRowsAndClosewriteRowsAndClosewriteRowsToStringwriteRowsToStringwriteRowsToStringwriteRowsToStringwriteRowsToStringwriteRowToStringwriteRowToStringwriteRowToStringwriteRowToStringwriteRowToStringwriteStringRowswriteStringRowswriteStringRowswriteStringRowsAndClosewriteStringRowsAndClosewriteStringRowsAndClosewriteStringRowsToStringwriteStringRowsToStringwriteStringRowsToStringwriteValuesToRowwriteValuesToString

Field Detail

alignmentback to summary
private FieldAlignment alignment
defaultHeaderAlignmentback to summary
private FieldAlignment defaultHeaderAlignment
defaultHeaderPaddingback to summary
private boolean defaultHeaderPadding
defaultPaddingback to summary
private char defaultPadding
fieldAlignmentsback to summary
private FieldAlignment[] fieldAlignments
fieldLengthsback to summary
private int[] fieldLengths
fieldPaddingsback to summary
private char[] fieldPaddings
ignoreback to summary
private boolean[] ignore
ignoreCountback to summary
private int ignoreCount
lengthback to summary
private int length
lookaheadFormatsback to summary
private Lookup[] lookaheadFormats
lookbehindFormatback to summary
private Lookup lookbehindFormat
lookbehindFormatsback to summary
private Lookup[] lookbehindFormats
lookupCharsback to summary
private char[] lookupChars
paddingback to summary
private char padding
rootAlignmentsback to summary
private FieldAlignment[] rootAlignments
rootIgnoreback to summary
private boolean[] rootIgnore
rootLengthsback to summary
private int[] rootLengths
rootPaddingsback to summary
private char[] rootPaddings

Constructor Detail

FixedWidthWriterback to summary
public FixedWidthWriter(FixedWidthWriterSettings settings)

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

Important Note

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

Parameters
settings:FixedWidthWriterSettings

the fixed-width writer configuration

FixedWidthWriterback to summary
public FixedWidthWriter(Writer writer, FixedWidthWriterSettings settings)

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

Parameters
writer:Writer

the output resource that will receive fixed-width records produced by this class.

settings:FixedWidthWriterSettings

the fixed-width writer configuration

FixedWidthWriterback to summary
public FixedWidthWriter(File file, FixedWidthWriterSettings settings)

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

Parameters
file:File

the output file that will receive fixed-width records produced by this class.

settings:FixedWidthWriterSettings

the fixed-width writer configuration

FixedWidthWriterback to summary
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:File

the output file that will receive fixed-width records produced by this class.

encoding:String

the encoding of the file

settings:FixedWidthWriterSettings

the fixed-width writer configuration

FixedWidthWriterback to summary
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:File

the output file that will receive fixed-width records produced by this class.

encoding:Charset

the encoding of the file

settings:FixedWidthWriterSettings

the fixed-width writer configuration

FixedWidthWriterback to summary
public FixedWidthWriter(OutputStream output, FixedWidthWriterSettings settings)

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

Parameters
output:OutputStream

the output stream that will be written with the fixed-width records produced by this class.

settings:FixedWidthWriterSettings

the fixed-width writer configuration

FixedWidthWriterback to summary
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:OutputStream

the output stream that will be written with the fixed-width records produced by this class.

encoding:String

the encoding of the stream

settings:FixedWidthWriterSettings

the fixed-width writer configuration

FixedWidthWriterback to summary
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:OutputStream

the output stream that will be written with the fixed-width records produced by this class.

encoding:Charset

the encoding of the stream

settings:FixedWidthWriterSettings

the fixed-width writer configuration

Method Detail

appendback to summary
private void append(String element, boolean allowTrim)
initializeback to summary
protected final void initialize(FixedWidthWriterSettings settings)

Implements abstract com.univocity.parsers.common.AbstractWriter.initialize.

Initializes the Fixed-Width writer with CSV-specific configuration

Parameters
settings:FixedWidthWriterSettings

the Fixed-Width writer configuration

processElementback to summary
private void processElement(String element, boolean allowTrim)
processRowback to summary
protected void processRow(Object[] row)

Implements abstract com.univocity.parsers.common.AbstractWriter.processRow.

Doc from com.univocity.parsers.common.AbstractWriter.processRow.

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

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, unless this is a com.univocity.parsers.fixed.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.
Parameters
row:Object[]

the data to be written to the output in the expected format.

Annotations
@Override