public final class CSVUtils
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static java.lang.String |
buildCsvLine(java.util.Map fields,
char fieldSeparator,
char textSeparator,
java.lang.String lineBreak) |
static boolean |
escapeString(java.lang.StringBuilder unescaped,
char[] toEscape,
char[] specialChars,
boolean doubleCharacter)
It escapes the passed
toEscape char(s) within the given buffer. |
static boolean |
escapeString(java.lang.StringBuilder unescaped,
java.lang.String[] toEscape,
java.lang.String[] specialChars,
boolean doubleToEscape)
It escapes the passed
toEscape string(s) within the given buffer. |
static java.lang.String |
escapeString(java.lang.String unescaped,
char[] toEscape,
boolean doubleCharacter)
Escapes the passed
toEscape char(s) in the passed String. |
static boolean |
isSeparator(char[] tokenisers,
char actual)
Returns false is the actual char is not a separator.
|
static java.lang.String |
joinAndEscape(java.util.List<java.lang.String> cells,
char[] toEscape,
char delimiter,
boolean escapeByDoubling)
Escapes the given list of text fields and merges them to one single line using given delimiter.
|
static boolean |
lineStartsWith(java.lang.String line,
char[] prefixes,
java.lang.String appender)
Checks if given line starts with at least one of the given prefixes followed by given appender text.
|
static java.util.List<java.lang.String> |
splitAndUnescape(java.lang.String line,
char[] delimiters,
boolean escapedByDoubling)
Splits a given line in fields separated by given delimiters and unescapes the fields with usage of {
unescapeString(String, char[], boolean). |
static java.lang.String |
unescapeString(java.lang.String escaped,
char[] toUnEscape,
boolean doubleCharacter)
Unescapes the passed
toUnEscape char(s) in the passed String. |
public static java.lang.String unescapeString(java.lang.String escaped,
char[] toUnEscape,
boolean doubleCharacter)
toUnEscape char(s) in the passed String. If doubleCharacter is set
to true all double occurrence of the char(s) in toUnEscape will be reduced to one. Else all
'\' before the chars in toUnEscape are removed.
This method undo all changes to a String which are done by escapeString(String, char[], boolean )
escapeString( unEscapeString( String, char[], boolean ), char[], boolean )
== unEscapeString( escapeString( String, char[], boolean ), char[], boolean )
== String
for the same parameters (== means here equal strings)
escaped - the escaped stringtoUnEscape - the chars which are to unescapeddoubleCharacter - false: '\' is removed if char occurs in char[]; true: double occurrence of char from char[] is reduced
to onepublic static java.lang.String escapeString(java.lang.String unescaped,
char[] toEscape,
boolean doubleCharacter)
toEscape char(s) in the passed String. If doubleCharacter is set to
true all found toEscape char(s) are doubled, else the found characters will be escaped
with '\'.
Example:
textseparator chars are: '"', ';'
a,";"bc -> a,"";;""bc doubleCharacter=true
a,";"bc -> a,\"\;\"bc doubleCharacter=false
If you furthermore want to wrap the string only on demand dependent of occurrence of special characters see
escapeString(StringBuilder, char[], char[], boolean).
unescaped - the unescaped stringtoEscape - the char(s) to be escapeddoubleCharacter - if set to false all found characters are escaped with '\'public static boolean escapeString(java.lang.StringBuilder unescaped,
char[] toEscape,
char[] specialChars,
boolean doubleCharacter)
toEscape char(s) within the given buffer. If doubleCharacter is
set to true all found toEscape char(s) are doubled, else the found characters will be
escaped with '\'.
Difference to escapeString(String, char[], boolean) is, that it returns an boolean to indicate whether
special characters occur in buffer. So you can decide dependent on the return value whether you wrap the buffer
with text separators or not.
unescaped - the field contenttoEscape - the char(s) to be escapedspecialChars - char(s) checked for occurrence in given stringdoubleCharacter - if set to false all found characters are escaped with '\'escapeString(String, char[], boolean)public static boolean escapeString(java.lang.StringBuilder unescaped,
java.lang.String[] toEscape,
java.lang.String[] specialChars,
boolean doubleToEscape)
toEscape string(s) within the given buffer. If doubleToEscape is
set to true all found toEscape string(s) are doubled, else the found strings will be
escaped with '\'.
Difference to escapeString(String, char[], boolean) is, that it returns an boolean to indicate whether
special strings occur in buffer. So you can decide dependent on the return value whether you wrap the buffer with
text separators or not.
unescaped - the field contenttoEscape - the string(s) to be escapedspecialChars - string(s) checked for occurrence in given stringdoubleToEscape - if set to false all found strings are escaped with '\'escapeString(String, char[], boolean)public static boolean isSeparator(char[] tokenisers,
char actual)
tokenisers - an array of chars which are separatorsactual - the actual chartokeniserspublic static java.util.List<java.lang.String> splitAndUnescape(java.lang.String line,
char[] delimiters,
boolean escapedByDoubling)
unescapeString(String, char[], boolean).line - text to split and unescapedelimiters - the chars used for splitting and which have to be unescapedescapedByDoubling - if false '\' is removed if char occurs in given delimiters ,if true double occurrence of char from
delimiters is reduced to oneunescapeString(String, char[], boolean)public static java.lang.String joinAndEscape(java.util.List<java.lang.String> cells,
char[] toEscape,
char delimiter,
boolean escapeByDoubling)
cells - list of text fields for escaping and mergingtoEscape - char(s) which have to be escaped within fieldsdelimiter - delimiter char for merging the fields to one lineescapeByDoubling - if set to false all found characters are escaped with '\'public static boolean lineStartsWith(java.lang.String line,
char[] prefixes,
java.lang.String appender)
line - line to checkprefixes - list of line prefixes where the line has to start withappender - text which has to follow a found line prefix (can be null)public static java.lang.String buildCsvLine(java.util.Map fields,
char fieldSeparator,
char textSeparator,
java.lang.String lineBreak)
Copyright © 2018 SAP SE. All Rights Reserved.