com.univocity.parsers.fixed
Class FixedWidthWriterSettings

java.lang.Object
  extended by com.univocity.parsers.common.CommonSettings<F>
      extended by com.univocity.parsers.common.CommonWriterSettings<FixedWidthFormat>
          extended by com.univocity.parsers.fixed.FixedWidthWriterSettings
All Implemented Interfaces:
Cloneable

public class FixedWidthWriterSettings
extends CommonWriterSettings<FixedWidthFormat>

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 - parsers@univocity.com
See Also:
FixedWidthWriter, FixedWidthFormat, FixedWidthFields, CommonWriterSettings

Constructor Summary
FixedWidthWriterSettings()
          Creates a basic configuration object for the Fixed-Width writer with no field length configuration.
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.
 
Method Summary
protected  void addConfiguration(Map<String,Object> out)
           
 void addFormatForLookahead(String lookahead, FixedWidthFields lengths)
          Defines the format of records identified by a lookahead symbol.
 void addFormatForLookbehind(String lookbehind, FixedWidthFields lengths)
          Defines the format of records identified by a lookbehind symbol.
 FixedWidthWriterSettings clone()
          Clones this configuration object to reuse all user-provided settings, including the fixed-width field configuration.
protected  FixedWidthWriterSettings clone(boolean clearInputSpecificSettings)
          Deprecated. doesn't really make sense for fixed-width. . Use alternative method clone(FixedWidthFields).
 FixedWidthWriterSettings clone(FixedWidthFields fields)
          Clones this configuration object to reuse most user-provided settings.
protected  void configureFromAnnotations(Class<?> beanClass)
          Configures the writer based on the annotations provided in a given class
protected  FixedWidthFormat createDefaultFormat()
          Returns the default FixedWidthFormat configured to handle Fixed-Width outputs
 FieldAlignment getDefaultAlignmentForHeaders()
          Returns the default alignment to use when writing headers.
 int getMaxColumns()
          Returns the hard limit of how many columns a record can have (defaults to 512).
 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
 boolean getWriteLineSeparatorAfterRecord()
          Returns a flag indicating whether each record, when written, should be followed by a line separator (as specified in Format.getLineSeparator().
 void setDefaultAlignmentForHeaders(FieldAlignment defaultAlignmentForHeaders)
          Defines the default alignment to use when writing headers.
 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...))
 void setWriteLineSeparatorAfterRecord(boolean writeLineSeparatorAfterRecord)
          Defines whether each record, when written, should be followed by a line separator (as specified in Format.getLineSeparator().
 
Methods inherited from class com.univocity.parsers.common.CommonWriterSettings
clearInputSpecificSettings, getEmptyValue, getExpandIncompleteRows, getRowWriterProcessor, isColumnReorderingEnabled, isHeaderWritingEnabled, setColumnReorderingEnabled, setEmptyValue, setExpandIncompleteRows, setHeaderWritingEnabled, setRowWriterProcessor
 
Methods inherited from class com.univocity.parsers.common.CommonSettings
excludeFields, excludeFields, excludeIndexes, getErrorContentLength, getFormat, getHeaders, getIgnoreLeadingWhitespaces, getIgnoreTrailingWhitespaces, getMaxCharsPerColumn, getNullValue, getProcessorErrorHandler, getRowProcessorErrorHandler, getSkipBitsAsWhitespace, getSkipEmptyLines, getWhitespaceRangeStart, isAutoConfigurationEnabled, isProcessorErrorHandlerDefined, selectFields, selectFields, selectIndexes, setAutoConfigurationEnabled, setErrorContentLength, setFormat, setHeaders, setIgnoreLeadingWhitespaces, setIgnoreTrailingWhitespaces, setMaxCharsPerColumn, setMaxColumns, setNullValue, setProcessorErrorHandler, setRowProcessorErrorHandler, setSkipBitsAsWhitespace, setSkipEmptyLines, toString, trimValues
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FixedWidthWriterSettings

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 - the instance of FixedWidthFields which provides the lengths of each field in the fixed-width records to be parsed
See Also:
FixedWidthFields

FixedWidthWriterSettings

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

createDefaultFormat

protected FixedWidthFormat createDefaultFormat()
Returns the default FixedWidthFormat configured to handle Fixed-Width outputs

Specified by:
createDefaultFormat in class CommonSettings<FixedWidthFormat>
Returns:
and instance of FixedWidthFormat configured to handle Fixed-Width outputs

getMaxColumns

public int getMaxColumns()
Description copied from class: CommonSettings
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 .

Overrides:
getMaxColumns in class CommonSettings<FixedWidthFormat>
Returns:
The maximum number of columns a record can have.

addFormatForLookahead

public void addFormatForLookahead(String lookahead,
                                  FixedWidthFields lengths)
Defines the format of records identified by a lookahead symbol.

Parameters:
lookahead - 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 - the field lengths of the record format identified by the given lookahead symbol.

addFormatForLookbehind

public void addFormatForLookbehind(String lookbehind,
                                   FixedWidthFields lengths)
Defines the format of records identified by a lookbehind symbol.

Parameters:
lookbehind - 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 - the field lengths of the record format identified by the given lookbehind symbol.

getUseDefaultPaddingForHeaders

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:
true if the default padding is to be used when writing headers, otherwise false

setUseDefaultPaddingForHeaders

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 - flag indicating whether the default padding is to be used when writing headers

getDefaultAlignmentForHeaders

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:
the default alignment for headers, or null if the headers should be aligned according to the column alignment.

setDefaultAlignmentForHeaders

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 - the alignment to use when writing headers. null indicates that headers should be aligned according to the column alignment.

getWriteLineSeparatorAfterRecord

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:
whether the writer should add a line separator after a record is written to the output.

setWriteLineSeparatorAfterRecord

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 - flag indicating whether the writer should add a line separator after a record is written to the output.

configureFromAnnotations

protected void configureFromAnnotations(Class<?> beanClass)
Description copied from class: CommonWriterSettings
Configures the writer based on the annotations provided in a given class

Overrides:
configureFromAnnotations in class CommonWriterSettings<FixedWidthFormat>
Parameters:
beanClass - the classes whose annotations will be processed to derive configurations for writing.

addConfiguration

protected void addConfiguration(Map<String,Object> out)
Overrides:
addConfiguration in class CommonWriterSettings<FixedWidthFormat>

clone

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

Overrides:
clone in class CommonWriterSettings<FixedWidthFormat>
Returns:
a copy of all configurations applied to the current instance.

clone

@Deprecated
protected final FixedWidthWriterSettings clone(boolean clearInputSpecificSettings)
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.

Overrides:
clone in class CommonWriterSettings<FixedWidthFormat>
Parameters:
clearInputSpecificSettings - flag indicating whether to clear settings that are likely to be associated with a given input.
Returns:
a copy of all configurations applied to the current instance.

clone

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 - the fixed-width field configuration to be used by the cloned settings object.
Returns:
a copy of the general configurations applied to the current instance.


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