Class FieldDelimiterSettings

  • All Implemented Interfaces:
    FieldDelimiterSpecifier, RecordSeparatorSpecifier

    public class FieldDelimiterSettings
    extends RecordSeparatorSettings
    implements FieldDelimiterSpecifier
    A container for structural information about a text file containing delimited records. The default settings are:
    • Records are separated by "newlines", where this may be either Windows-style (CRLF) or Unix-style (LF). On read, the style will automatically be detected. On write, the system appropriate style will be used.
    • Fields are separated by commas (the ',' character).
    • Field values are optionally delimited with double quotes (the '"' character).
    • Field Detail

      • DEFAULT_FIELD_DELIMITER

        public static final String DEFAULT_FIELD_DELIMITER
        The default field delimiter
        See Also:
        Constant Field Values
      • DEFAULT_FIELD_SEPARATOR

        public static final String DEFAULT_FIELD_SEPARATOR
        The default field separator
        See Also:
        Constant Field Values
    • Constructor Detail

      • FieldDelimiterSettings

        public FieldDelimiterSettings()
        Creates a new container with default settings.
      • FieldDelimiterSettings

        public FieldDelimiterSettings​(String separator)
        Creates a new container with using the specified field separator and the default field delimiter.
        Parameters:
        separator - string used to separate fields
        Throws:
        InvalidPropertyValueException - if the separator is null or the empty string
      • FieldDelimiterSettings

        public FieldDelimiterSettings​(String separator,
                                      String delimiter)
        Creates a new container with using the specified field separator and field delimiter.
        Parameters:
        separator - string used to separate fields
        delimiter - string used to mark the start and end of a field value An empty string indicates field values are not delimited.
        Throws:
        InvalidPropertyValueException - if the delimiter is null or the separator is null or empty
      • FieldDelimiterSettings

        public FieldDelimiterSettings​(FieldDelimiterSpecifier source)
        Creates a container initialized using the given structural information.
        Parameters:
        source - field specifier data from which to initialize the settings
    • Method Detail

      • setAutoDiscoverSeparator

        public void setAutoDiscoverSeparator​(boolean enabled)
        Description copied from interface: FieldDelimiterSpecifier
        Sets whether automated field separator discovery is configured. When set, the source file should be analyzed to determine the most likely candidate for the field separator. The decision is based on the consistency on the number of fields produces across all sampled records.

        Only a small set of common separators are considered when attempting to discover the field separator. Those considered are: comma (','), semi-colon (';'), tab ('\t'), pipe ('|'), and space (' ').

        This option is enabled by default. If a field separator is explicitly specified, separator discovery is disabled.

        Specified by:
        setAutoDiscoverSeparator in interface FieldDelimiterSpecifier
        Parameters:
        enabled - indicates whether to discover the field separator character.
        See Also:
        FieldDelimiterSpecifier.setFieldSeparator(String)
      • setFieldDelimiter

        public void setFieldDelimiter​(String delimiter)
        Description copied from interface: FieldDelimiterSpecifier
        Sets the delimiter used to denote the boundaries of a data field.

        This method is generally equivalent to calling setFieldStartDelimiter() and setFieldEndDelimiter() with the same parameter values. However, those methods do not allow the empty string as a parameter.

        Specified by:
        setFieldDelimiter in interface FieldDelimiterSpecifier
        Parameters:
        delimiter - string used to optionally mark the start and end of a field value. An empty string indicates field values are not delimited.
      • setAutoDiscoverDelimiter

        public void setAutoDiscoverDelimiter​(boolean enabled)
        Description copied from interface: FieldDelimiterSpecifier
        Sets whether automated field delimiter discovery is configured. When set, the source file should be analyzed to determine the most likely candidate for the field delimiter. The decision is based on whether candidates produce consistent parsing behavior on the sample.

        Only double quote (") and single quote (') are considered as possible delimiters. To be chosen, the delimiter must appear in the sample. If neither is appropriate (or if both seem appropriate) for the sample, the text is assumed to be undelimited.

        This option is enabled by default. If a field delimiter is explicitly specified, delimiter discovery is disabled.

        Specified by:
        setAutoDiscoverDelimiter in interface FieldDelimiterSpecifier
        Parameters:
        enabled - indicates whether to discover the field delimiter character.
        See Also:
        FieldDelimiterSpecifier.setFieldDelimiter(String)