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

public Class FixedWidthWriterSettings

extends CommonWriterSettings<FixedWidthFormat>
Class Inheritance
Imports
com.univocity.parsers.annotations.*, com.univocity.parsers.annotations.helpers.*, com.univocity.parsers.common.*, .Format, java.util.*

This is the configuration class used by the Fixed-Width writer (FixedWidthWriter)

The FixedWidthWriterSettings provides all configuration options in CommonWriterSettings and currently does not require any additional setting.

The FixedWidthParserSettings requires a definition of the field lengths of each record in the input. This must provided using an instance of FixedWidthFields.

Author
Univocity Software Pty Ltd - [email protected]
See Also
com.univocity.parsers.fixed.FixedWidthWriter, com.univocity.parsers.fixed.FixedWidthFormat, FixedWidthFields, com.univocity.parsers.common.CommonWriterSettings

Field Summary

Modifier and TypeField and Description
private FieldAlignment
private FixedWidthFields
private Map<String, FixedWidthFields>
private Map<String, FixedWidthFields>
private boolean
private boolean

Constructor Summary

AccessConstructor and Description
public
FixedWidthWriterSettings(FixedWidthFields
the instance of FixedWidthFields which provides the lengths of each field in the fixed-width records to be parsed
fieldLengths
)

You can only create an instance of this class by providing a definition of the field lengths of each record in the input.

public
FixedWidthWriterSettings()

Creates a basic configuration object for the Fixed-Width writer with no field length configuration.

Method Summary

Modifier and TypeMethod and Description
protected void
public void
addFormatForLookahead(String
the lookahead value that when found in the output row, will notify the writer to switch to a new record format, with different field lengths
lookahead
,
FixedWidthFields
the field lengths of the record format identified by the given lookahead symbol.
lengths
)

Defines the format of records identified by a lookahead symbol.

public void
addFormatForLookbehind(String
the lookbehind value that when present in the previous output row, will notify the writer to switch to a new record format, with different field lengths
lookbehind
,
FixedWidthFields
the field lengths of the record format identified by the given lookbehind symbol.
lengths
)

Defines the format of records identified by a lookbehind symbol.

public final FixedWidthWriterSettings

Returns:

a copy of all configurations applied to the current instance.
clone
()

Overrides com.univocity.parsers.common.CommonWriterSettings.clone.

Clones this configuration object to reuse all user-provided settings, including the fixed-width field configuration.
protected final FixedWidthWriterSettings

Returns:

a copy of all configurations applied to the current instance.
clone
(boolean
flag indicating whether to clear settings that are likely to be associated with a given input.
clearInputSpecificSettings
)

Overrides com.univocity.parsers.common.CommonWriterSettings.clone.

Deprecated doesn't really make sense for fixed-width.
Clones this configuration object to reuse most user-provided settings.
public final FixedWidthWriterSettings

Returns:

a copy of the general configurations applied to the current instance.
clone
(FixedWidthFields
the fixed-width field configuration to be used by the cloned settings object.
fields
)

Clones this configuration object to reuse most user-provided settings.

private FixedWidthWriterSettings
clone(boolean clearInputSpecificSettings, FixedWidthFields fields)

protected void
configureFromAnnotations(Class<?>
the classes whose annotations will be processed to derive configurations for writing.
beanClass
)

Overrides com.univocity.parsers.common.CommonWriterSettings.configureFromAnnotations.

Configures the writer based on the annotations provided in a given class
protected FixedWidthFormat

Returns:

and instance of FixedWidthFormat configured to handle Fixed-Width outputs
createDefaultFormat
()

Implements abstract com.univocity.parsers.common.CommonSettings.createDefaultFormat.

Returns the default FixedWidthFormat configured to handle Fixed-Width outputs
pack-priv int[]

Returns:

the sequence of field lengths to be written to form a record.
getAllLengths
()

Returns the sequence of field lengths to be written to form a record.

public FieldAlignment

Returns:

the default alignment for headers, or null if the headers should be aligned according to the column alignment.
getDefaultAlignmentForHeaders
()

Returns the default alignment to use when writing headers.

pack-priv FieldAlignment[]

Returns:

the sequence of field alignments to apply to each field in the record.
getFieldAlignments
()

Returns the sequence of field alignments to apply to each field in the record.

pack-priv int[]

Returns:

the sequence of field lengths to be written to form a record.
getFieldLengths
()

Returns the sequence of field lengths to be written to form a record.

pack-priv char[]

Returns:

the sequence of paddings used by each field of each record.
getFieldPaddings
()

Returns the sequence of paddings used by each field of each record.

pack-priv boolean[]

Returns:

the sequence of fields to ignore.
getFieldsToIgnore
()

Returns the sequence of fields to ignore.

pack-priv Lookup[]
pack-priv Lookup[]
public int
getMaxColumns()

Overrides com.univocity.parsers.common.CommonSettings.getMaxColumns.

Returns the hard limit of how many columns a record can have (defaults to 512).
public boolean

Returns:

true if the default padding is to be used when writing headers, otherwise false
getUseDefaultPaddingForHeaders
()

Indicates whether headers should be written using the default padding specified in FixedWidthFormat#getPadding() instead of any custom padding associated with a given field (in FixedWidthFields#setPadding(char, int...)) Defaults to true

public boolean

Returns:

whether the writer should add a line separator after a record is written to the output.
getWriteLineSeparatorAfterRecord
()

Returns a flag indicating whether each record, when written, should be followed by a line separator (as specified in Format#getLineSeparator().

public void
setDefaultAlignmentForHeaders(FieldAlignment
the alignment to use when writing headers. null indicates that headers should be aligned according to the column alignment.
defaultAlignmentForHeaders
)

Defines the default alignment to use when writing headers.

pack-priv final void
public void
setUseDefaultPaddingForHeaders(boolean
flag indicating whether the default padding is to be used when writing headers
useDefaultPaddingForHeaders
)

Defines whether headers should be written using the default padding specified in FixedWidthFormat#getPadding() instead of any custom padding associated with a given field (in FixedWidthFields#setPadding(char, int...))

public void
setWriteLineSeparatorAfterRecord(boolean
flag indicating whether the writer should add a line separator after a record is written to the output.
writeLineSeparatorAfterRecord
)

Defines whether each record, when written, should be followed by a line separator (as specified in Format#getLineSeparator().

Inherited from com.univocity.parsers.common.CommonWriterSettings:
clearInputSpecificSettingsgetEmptyValuegetExpandIncompleteRowsgetRowWriterProcessorisColumnReorderingEnabledisHeaderWritingEnabledsetColumnReorderingEnabledsetEmptyValuesetExpandIncompleteRowssetHeaderWritingEnabledsetRowWriterProcessor

Field Detail

defaultAlignmentForHeadersback to summary
private FieldAlignment defaultAlignmentForHeaders
fieldLengthsback to summary
private FixedWidthFields fieldLengths
lookaheadFormatsback to summary
private Map<String, FixedWidthFields> lookaheadFormats
lookbehindFormatsback to summary
private Map<String, FixedWidthFields> lookbehindFormats
useDefaultPaddingForHeadersback to summary
private boolean useDefaultPaddingForHeaders
writeLineSeparatorAfterRecordback to summary
private boolean writeLineSeparatorAfterRecord

Constructor Detail

FixedWidthWriterSettingsback to summary
public FixedWidthWriterSettings(FixedWidthFields fieldLengths)

You can only create an instance of this class by providing a definition of the field lengths of each record in the input.

This must provided using an instance of FixedWidthFields.

Parameters
fieldLengths:FixedWidthFields

the instance of FixedWidthFields which provides the lengths of each field in the fixed-width records to be parsed

See Also
FixedWidthFields
FixedWidthWriterSettingsback to summary
public FixedWidthWriterSettings()

Creates a basic configuration object for the Fixed-Width writer with no field length configuration. This constructor is intended to be used when the record length varies depending of the input row. Refer to addFormatForLookahead(String, FixedWidthFields), addFormatForLookbehind(String, FixedWidthFields)

Method Detail

addConfigurationback to summary
protected void addConfiguration(Map<String, Object> out)

Overrides com.univocity.parsers.common.CommonWriterSettings.addConfiguration.

Annotations
@Override
addFormatForLookaheadback to summary
public void addFormatForLookahead(String lookahead, FixedWidthFields lengths)

Defines the format of records identified by a lookahead symbol.

Parameters
lookahead:String

the lookahead value that when found in the output row, will notify the writer to switch to a new record format, with different field lengths

lengths:FixedWidthFields

the field lengths of the record format identified by the given lookahead symbol.

addFormatForLookbehindback to summary
public void addFormatForLookbehind(String lookbehind, FixedWidthFields lengths)

Defines the format of records identified by a lookbehind symbol.

Parameters
lookbehind:String

the lookbehind value that when present in the previous output row, will notify the writer to switch to a new record format, with different field lengths

lengths:FixedWidthFields

the field lengths of the record format identified by the given lookbehind symbol.

cloneback to summary
public final FixedWidthWriterSettings clone()

Overrides com.univocity.parsers.common.CommonWriterSettings.clone.

Clones this configuration object to reuse all user-provided settings, including the fixed-width field configuration.

Returns:FixedWidthWriterSettings

a copy of all configurations applied to the current instance.

Annotations
@Override
cloneback to summary
protected final FixedWidthWriterSettings clone(boolean clearInputSpecificSettings)

Overrides com.univocity.parsers.common.CommonWriterSettings.clone.

Deprecated

doesn't really make sense for fixed-width. . Use alternative method clone(FixedWidthFields).

Clones this configuration object to reuse most user-provided settings. This includes the fixed-width field configuration, but doesn't include other input-specific settings. This method is meant to be used internally only.

Parameters
clearInputSpecificSettings:boolean

Doc from com.univocity.parsers.common.CommonSettings.clone.

flag indicating whether to clear settings that are likely to be associated with a given input.

Returns:FixedWidthWriterSettings

a copy of all configurations applied to the current instance.

Annotations
@Deprecated
cloneback to summary
public final FixedWidthWriterSettings clone(FixedWidthFields fields)

Clones this configuration object to reuse most user-provided settings. Properties that are specific to a given input (such as header names and selection of fields) will be reset to their defaults. To obtain a full copy, use clone().

Parameters
fields:FixedWidthFields

the fixed-width field configuration to be used by the cloned settings object.

Returns:FixedWidthWriterSettings

a copy of the general configurations applied to the current instance.

cloneback to summary
private FixedWidthWriterSettings clone(boolean clearInputSpecificSettings, FixedWidthFields fields)
configureFromAnnotationsback to summary
protected void configureFromAnnotations(Class<?> beanClass)

Overrides com.univocity.parsers.common.CommonWriterSettings.configureFromAnnotations.

Doc from com.univocity.parsers.common.CommonWriterSettings.configureFromAnnotations.

Configures the writer based on the annotations provided in a given class

Parameters
beanClass:Class<?>

the classes whose annotations will be processed to derive configurations for writing.

Annotations
@Override
createDefaultFormatback to summary
protected FixedWidthFormat createDefaultFormat()

Implements abstract com.univocity.parsers.common.CommonSettings.createDefaultFormat.

Returns the default FixedWidthFormat configured to handle Fixed-Width outputs

Returns:FixedWidthFormat

and instance of FixedWidthFormat configured to handle Fixed-Width outputs

Annotations
@Override
getAllLengthsback to summary
pack-priv int[] getAllLengths()

Returns the sequence of field lengths to be written to form a record.

Returns:int[]

the sequence of field lengths to be written to form a record.

getDefaultAlignmentForHeadersback to summary
public FieldAlignment getDefaultAlignmentForHeaders()

Returns the default alignment to use when writing headers. If none is specified (i.e. null), the headers will be aligned according to the corresponding field alignment in FixedWidthFields#getAlignment(String). Defaults to null.

Returns:FieldAlignment

the default alignment for headers, or null if the headers should be aligned according to the column alignment.

getFieldAlignmentsback to summary
pack-priv FieldAlignment[] getFieldAlignments()

Returns the sequence of field alignments to apply to each field in the record.

Returns:FieldAlignment[]

the sequence of field alignments to apply to each field in the record.

getFieldLengthsback to summary
pack-priv int[] getFieldLengths()

Returns the sequence of field lengths to be written to form a record.

Returns:int[]

the sequence of field lengths to be written to form a record.

getFieldPaddingsback to summary
pack-priv char[] getFieldPaddings()

Returns the sequence of paddings used by each field of each record.

Returns:char[]

the sequence of paddings used by each field of each record.

getFieldsToIgnoreback to summary
pack-priv boolean[] getFieldsToIgnore()

Returns the sequence of fields to ignore.

Returns:boolean[]

the sequence of fields to ignore.

getLookaheadFormatsback to summary
pack-priv Lookup[] getLookaheadFormats()
getLookbehindFormatsback to summary
pack-priv Lookup[] getLookbehindFormats()
getMaxColumnsback to summary
public int getMaxColumns()

Overrides com.univocity.parsers.common.CommonSettings.getMaxColumns.

Doc from com.univocity.parsers.common.CommonSettings.getMaxColumns.

Returns the hard limit of how many columns a record can have (defaults to 512). You need this to avoid OutOfMemory errors in case of inputs that might be inconsistent with the format you are dealing with .

Returns:int

The maximum number of columns a record can have.

Annotations
@Override
getUseDefaultPaddingForHeadersback to summary
public boolean getUseDefaultPaddingForHeaders()

Indicates whether headers should be written using the default padding specified in FixedWidthFormat#getPadding() instead of any custom padding associated with a given field (in FixedWidthFields#setPadding(char, int...)) Defaults to true

Returns:boolean

true if the default padding is to be used when writing headers, otherwise false

getWriteLineSeparatorAfterRecordback to summary
public boolean getWriteLineSeparatorAfterRecord()

Returns a flag indicating whether each record, when written, should be followed by a line separator (as specified in Format#getLineSeparator(). Consider the records [a,b] and [c,d], with field lengths [2, 2], and line separator = \n:

Defaults to true.
Returns:boolean

whether the writer should add a line separator after a record is written to the output.

setDefaultAlignmentForHeadersback to summary
public void setDefaultAlignmentForHeaders(FieldAlignment defaultAlignmentForHeaders)

Defines the default alignment to use when writing headers. If none is specified (i.e. null), the headers will be aligned according to the corresponding field alignment in FixedWidthFields#getAlignment(String). Defaults to null.

Parameters
defaultAlignmentForHeaders:FieldAlignment

the alignment to use when writing headers. null indicates that headers should be aligned according to the column alignment.

setFieldLengthsback to summary
pack-priv final void setFieldLengths(FixedWidthFields fieldLengths)
setUseDefaultPaddingForHeadersback to summary
public void setUseDefaultPaddingForHeaders(boolean useDefaultPaddingForHeaders)

Defines whether headers should be written using the default padding specified in FixedWidthFormat#getPadding() instead of any custom padding associated with a given field (in FixedWidthFields#setPadding(char, int...))

Parameters
useDefaultPaddingForHeaders:boolean

flag indicating whether the default padding is to be used when writing headers

setWriteLineSeparatorAfterRecordback to summary
public void setWriteLineSeparatorAfterRecord(boolean writeLineSeparatorAfterRecord)

Defines whether each record, when written, should be followed by a line separator (as specified in Format#getLineSeparator(). Consider the records [a,b] and [c,d], with field lengths [2, 2], and line separator = \n:

Defaults to true.
Parameters
writeLineSeparatorAfterRecord:boolean

flag indicating whether the writer should add a line separator after a record is written to the output.