public class CsvOperator extends Object
csv("one", "two", "three").on("1;2;3").into([result]);
produces
result = {"one" : "1", "two" : "2", "three" : "3"}
If you provide no or not enough field names, field names will be automatically added. I.e
csv("a", "b").on("abc;def;hij").into([result]);
produces
result = {"a" : "abc", "b" : "def", "field2" : "hij"}
You can provide the separator as a char, it will be escaped before being used as regex pattern for the split. Use it if your separator is a regexp special character.
Constructor and Description |
---|
CsvOperator(List<String> fieldNames)
Create a csv operator with a list of field names.
|
CsvOperator(String... fieldNames)
Create a csv operator with a list of field names.
|
Modifier and Type | Method and Description |
---|---|
CsvOperator |
debug()
Turn debugging to true.
|
CsvOperator |
delim(char delimiter)
Set the separator.
|
CsvOperator |
delim(String delimiter)
Set the default separator.
|
CsvOperator |
delim(String delimiter,
boolean isRegexDelimiter)
Set the default separator and the separator type (regex or string).
|
CsvOperator |
escapeCharacter(char escapeCharacter)
Allows to escape quote delimiters.
|
CsvOperator |
escapeCharacter(String escapeCharacter)
Allows to escape quote delimiters.
|
CsvOperator |
escapeDelimiters(String quoteDelimiters)
Alias for quoteDelimiters.
|
CsvOperator |
inferTypes()
Make the csv operator generate typed results.
|
boolean |
into(Tuple tuple)
Fire the operator and put the result inside a destination tuple
|
CsvOperator |
keepEmpty()
Use this method to make the CSV operator keep empty values, if any, in your
|
CsvOperator |
on(String input)
Make the operator work on an input String
|
CsvOperator |
on(Tuple input)
Make the operator work on an input Tuple.
|
CsvOperator |
quoteDelimiters(String quoteDelimiters)
Allows to specify quote delimiters.
|
CsvOperator |
separator(char delimiter)
Set the separator.
|
CsvOperator |
separator(String delimiter)
Set the default separator.
|
CsvOperator |
trim()
Trim the values, removing any leading or ending white spaces.
|
CsvOperator |
trimQuotes(boolean b)
If true (the default) make the Csv operator remove leading or trailing quotes or single quotes.
|
public CsvOperator(String... fieldNames)
fieldNames
- an ordered array of field names.public CsvOperator escapeDelimiters(String quoteDelimiters)
quoteDelimiters
- the quoting delimiterspublic CsvOperator quoteDelimiters(String quoteDelimiters)
quoteDelimiters
- the quoting delimiterspublic CsvOperator escapeCharacter(char escapeCharacter)
escapeCharacter
- Character to use.public CsvOperator escapeCharacter(String escapeCharacter)
escapeCharacter
- Character to use. First character only is taken.public CsvOperator inferTypes()
public CsvOperator trimQuotes(boolean b)
b
- the boolean value you needpublic CsvOperator keepEmpty()
public CsvOperator trim()
public CsvOperator debug()
public CsvOperator delim(String delimiter)
delimiter
- the new delimiterpublic CsvOperator delim(String delimiter, boolean isRegexDelimiter)
delimiter
- the new delimiterisRegexDelimiter
- true if delimiter must be interpreted as regex otherwise string. Default is true.public CsvOperator separator(String delimiter)
delimiter
- the new delimiterpublic CsvOperator delim(char delimiter)
delimiter
- the new delimiterpublic CsvOperator separator(char delimiter)
delimiter
- the new delimiterpublic CsvOperator on(String input)
input
- the input Stringpublic CsvOperator on(Tuple input)
input
- the input Tuplepublic boolean into(Tuple tuple)
tuple
- the destination tupleCopyright © 2022. All rights reserved.