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 Summary
Modifier and TypeFieldDescriptionstatic final char
Convenient constant for the common case of a " character used to escape delimiters or line endings.static final String
Convenient constant for the common case of a comma delimiter.static final String
Convenient constant for the common case of a tab delimiter.Fields inherited from class org.springframework.batch.item.file.transform.AbstractLineTokenizer
names
-
Constructor Summary
ConstructorDescriptionCreate a new instance of theDelimitedLineTokenizer
class for the common case where the delimiter is acomma
.DelimitedLineTokenizer
(String delimiter) Create a new instance of theDelimitedLineTokenizer
class. -
Method Summary
Modifier and TypeMethodDescriptionvoid
doTokenize
(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
(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 Details
-
DELIMITER_TAB
Convenient constant for the common case of a tab delimiter.- See Also:
-
DELIMITER_COMMA
Convenient constant for the common case of a comma delimiter.- See Also:
-
DEFAULT_QUOTE_CHARACTER
public static final char DEFAULT_QUOTE_CHARACTERConvenient constant for the common case of a " character used to escape delimiters or line endings.- See Also:
-
-
Constructor Details
-
DelimitedLineTokenizer
public DelimitedLineTokenizer()Create a new instance of theDelimitedLineTokenizer
class for the common case where the delimiter is acomma
. -
DelimitedLineTokenizer
Create a new instance of theDelimitedLineTokenizer
class.- Parameters:
delimiter
- the desired delimiter. This is required
-
-
Method Details
-
setDelimiter
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
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:
-
afterPropertiesSet
- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
- Throws:
Exception
-