org.springframework.batch.item.file.transform
Class DelimitedLineTokenizer

java.lang.Object
  extended by org.springframework.batch.item.file.transform.AbstractLineTokenizer
      extended by org.springframework.batch.item.file.transform.DelimitedLineTokenizer
All Implemented Interfaces:
LineTokenizer

public class DelimitedLineTokenizer
extends AbstractLineTokenizer

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

Field Summary
static char DEFAULT_QUOTE_CHARACTER
          Convenient constant for the common case of a " character used to escape delimiters or line endings.
static char DELIMITER_COMMA
          Convenient constant for the common case of a comma delimiter.
static char DELIMITER_TAB
          Convenient constant for the common case of a tab delimiter.
 
Fields inherited from class org.springframework.batch.item.file.transform.AbstractLineTokenizer
names
 
Constructor Summary
DelimitedLineTokenizer()
          Create a new instance of the DelimitedLineTokenizer class for the common case where the delimiter is a comma.
DelimitedLineTokenizer(char delimiter)
          Create a new instance of the DelimitedLineTokenizer class.
 
Method Summary
protected  List<String> doTokenize(String line)
          Yields the tokens resulting from the splitting of the supplied line.
protected  boolean isQuoteCharacter(char c)
          Is the supplied character a quote character?
 void setDelimiter(char delimiter)
          Setter for the delimiter character.
 void setQuoteCharacter(char quoteCharacter)
          Public setter for the quoteCharacter.
 
Methods inherited from class org.springframework.batch.item.file.transform.AbstractLineTokenizer
hasNames, setFieldSetFactory, setNames, tokenize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DELIMITER_TAB

public static final char DELIMITER_TAB
Convenient constant for the common case of a tab delimiter.

See Also:
Constant Field Values

DELIMITER_COMMA

public static final char DELIMITER_COMMA
Convenient constant for the common case of a comma delimiter.

See Also:
Constant Field Values

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:
Constant Field Values
Constructor Detail

DelimitedLineTokenizer

public DelimitedLineTokenizer()
Create a new instance of the DelimitedLineTokenizer class for the common case where the delimiter is a comma.

See Also:
DelimitedLineTokenizer(char), DELIMITER_COMMA

DelimitedLineTokenizer

public DelimitedLineTokenizer(char delimiter)
Create a new instance of the DelimitedLineTokenizer class.

Parameters:
delimiter - the desired delimiter
Method Detail

setDelimiter

public void setDelimiter(char delimiter)
Setter for the delimiter character.

Parameters:
delimiter -

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:
DEFAULT_QUOTE_CHARACTER

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:
setQuoteCharacter(char)


Copyright © 2009 SpringSource. All Rights Reserved.