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
ALineTokenizer
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
Field Summary
Fields Modifier and Type Field Description static char
DEFAULT_QUOTE_CHARACTER
Convenient constant for the common case of a " character used to escape delimiters or line endings.static java.lang.String
DELIMITER_COMMA
Convenient constant for the common case of a comma delimiter.static java.lang.String
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
Constructors Constructor Description DelimitedLineTokenizer()
Create a new instance of theDelimitedLineTokenizer
class for the common case where the delimiter is acomma
.DelimitedLineTokenizer(java.lang.String delimiter)
Create a new instance of theDelimitedLineTokenizer
class.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
afterPropertiesSet()
protected java.util.List<java.lang.String>
doTokenize(java.lang.String line)
Yields the tokens resulting from the splitting of the suppliedline
.protected boolean
isQuoteCharacter(char c)
Is the supplied character a quote character?void
setDelimiter(java.lang.String delimiter)
Setter for the delimiter character.void
setIncludedFields(int... includedFields)
The fields to include in the output by position (starting at 0).void
setQuoteCharacter(char quoteCharacter)
Public setter for the quoteCharacter.Methods inherited from class org.springframework.batch.item.file.transform.AbstractLineTokenizer
hasNames, isStrict, setFieldSetFactory, setNames, setStrict, tokenize
Field Detail
DELIMITER_TAB
public static final java.lang.String DELIMITER_TAB
Convenient constant for the common case of a tab delimiter.- See Also:
- Constant Field Values
DELIMITER_COMMA
public static final java.lang.String 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 theDelimitedLineTokenizer
class for the common case where the delimiter is acomma
.
DelimitedLineTokenizer
public DelimitedLineTokenizer(java.lang.String delimiter)
Create a new instance of theDelimitedLineTokenizer
class.- Parameters:
delimiter
- the desired delimiter. This is required
Method Detail
setDelimiter
public void setDelimiter(java.lang.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:
DEFAULT_QUOTE_CHARACTER
doTokenize
protected java.util.List<java.lang.String> doTokenize(java.lang.String line)
Yields the tokens resulting from the splitting of the suppliedline
.- Specified by:
doTokenize
in classAbstractLineTokenizer
- 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)
afterPropertiesSet
public void afterPropertiesSet() throws java.lang.Exception
- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
- Throws:
java.lang.Exception