Class DelimitedLineTokenizer

java.lang.Object
org.springframework.batch.item.file.transform.AbstractLineTokenizer
org.springframework.batch.item.file.transform.DelimitedLineTokenizer
All Implemented Interfaces:
LineTokenizer, org.springframework.beans.factory.InitializingBean

public class DelimitedLineTokenizer extends AbstractLineTokenizer implements org.springframework.beans.factory.InitializingBean
A LineTokenizer implementation that splits the input String on a configurable delimiter. This implementation also supports the use of an escape character to escape delimiters and line endings.
Author:
Rob Harrop, Dave Syer, Michael Minella, Olivier Bourgain, Mahmoud Ben Hassine
  • Field Details

    • DELIMITER_TAB

      public static final String DELIMITER_TAB
      Convenient constant for the common case of a tab delimiter.
      See Also:
    • DELIMITER_COMMA

      public static final String DELIMITER_COMMA
      Convenient constant for the common case of a comma delimiter.
      See Also:
    • DEFAULT_QUOTE_CHARACTER

      public static final char DEFAULT_QUOTE_CHARACTER
      Convenient constant for the common case of a " character used to escape delimiters or line endings.
      See Also:
  • Constructor Details

  • Method Details

    • setDelimiter

      public void setDelimiter(String delimiter)
      Setter for the delimiter character.
      Parameters:
      delimiter - the String used as a delimiter
    • setIncludedFields

      public void setIncludedFields(int... includedFields)
      The fields to include in the output by position (starting at 0). By default all fields are included, but this property can be set to pick out only a few fields from a larger set. Note that if field names are provided, their number must match the number of included fields.
      Parameters:
      includedFields - the included fields to set
    • setQuoteCharacter

      public void setQuoteCharacter(char quoteCharacter)
      Public setter for the quoteCharacter. The quote character can be used to extend a field across line endings or to enclose a String which contains the delimiter. Inside a quoted token the quote character can be used to escape itself, thus "a""b""c" is tokenized to a"b"c.
      Parameters:
      quoteCharacter - the quoteCharacter to set
      See Also:
    • doTokenize

      protected List<String> doTokenize(String line)
      Yields the tokens resulting from the splitting of the supplied line.
      Specified by:
      doTokenize in class AbstractLineTokenizer
      Parameters:
      line - the line to be tokenized
      Returns:
      the resulting tokens
    • isQuoteCharacter

      protected boolean isQuoteCharacter(char c)
      Is the supplied character a quote character?
      Parameters:
      c - the character to be checked
      Returns:
      true if the supplied character is an quote character
      See Also:
    • afterPropertiesSet

      public void afterPropertiesSet() throws Exception
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
      Throws:
      Exception