Class FixedWidthWriterSettings

    • Field Detail

      • lookaheadFormats

        private java.util.Map<java.lang.String,​FixedWidthFields> lookaheadFormats
      • lookbehindFormats

        private java.util.Map<java.lang.String,​FixedWidthFields> lookbehindFormats
      • useDefaultPaddingForHeaders

        private boolean useDefaultPaddingForHeaders
      • defaultAlignmentForHeaders

        private FieldAlignment defaultAlignmentForHeaders
      • writeLineSeparatorAfterRecord

        private boolean writeLineSeparatorAfterRecord
    • 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
    • Method Detail

      • setFieldLengths

        final void setFieldLengths​(FixedWidthFields fieldLengths)
      • getFieldLengths

        int[] getFieldLengths()
        Returns the sequence of field lengths to be written to form a record.
        Returns:
        the sequence of field lengths to be written to form a record.
      • getAllLengths

        int[] getAllLengths()
        Returns the sequence of field lengths to be written to form a record.
        Returns:
        the sequence of field lengths to be written to form a record.
      • getFieldAlignments

        FieldAlignment[] getFieldAlignments()
        Returns the sequence of field alignments to apply to each field in the record.
        Returns:
        the sequence of field alignments to apply to each field in the record.
      • getFieldPaddings

        char[] getFieldPaddings()
        Returns the sequence of paddings used by each field of each record.
        Returns:
        the sequence of paddings used by each field of each record.
      • getFieldsToIgnore

        boolean[] getFieldsToIgnore()
        Returns the sequence of fields to ignore.
        Returns:
        the sequence of fields to ignore.
      • 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​(java.lang.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​(java.lang.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.
      • getLookaheadFormats

        Lookup[] getLookaheadFormats()
      • getLookbehindFormats

        Lookup[] getLookbehindFormats()
      • 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​(java.lang.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.
      • 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.