public final class StringConverters extends Object
Modifier and Type | Method and Description |
---|---|
static String |
decodeBase64(String value)
Decodes
value as Base64 string. |
static String |
decodeBase64Mime(String value)
Decodes
value using the Base64 MIME type decoding scheme. |
static String |
decodeBase64Url(String value)
Decodes
value as Base64 URL and filename-safe string. |
static Csv |
decodeCsv(String data,
char separator,
char escaper)
Parses the CSV data given by
data . |
static String |
decodeUrl(String value)
Decodes an
application/x-www-form-urlencoded string. |
static String |
encodeBase64(String value)
Translates
value into Base64 format. |
static String |
encodeBase64Mime(String value)
Translates
value into Base64 MIME type encoding scheme. |
static String |
encodeBase64Url(String value)
Translates
value into Base64 URL and filename-safe format. |
static String |
encodeCsv(Collection<? extends Collection<String>> data,
char separator,
char escaper)
Encodes
data as CSV document. |
static String |
encodeCsvRow(Collection<? extends String> values,
char separator,
char escaper)
Encodes
values as one CSV row. |
static String |
encodeCsvValue(String value,
char separator,
char escaper)
Encodes
value into a single CSV value. |
static String |
encodeUrl(String value)
Translates a string into
application/x-www-form-urlencoded format
with the char set StandardCharsets.UTF_8 as the
World Wide Web Consortium Recommendation states that UTF-8 should be
used. |
public static String decodeBase64(String value)
value
as Base64 string.
This method is equivalent to using Base64.getDecoder()
with the char
set Strings.DEFAULT_CHARSET
.
value
- the value to be decodedpublic static String decodeBase64Mime(String value)
value
using the Base64 MIME type decoding scheme.
This method is equivalent to using Base64.getMimeDecoder()
with the
char set Strings.DEFAULT_CHARSET
.
value
- the value to be decodedpublic static String decodeBase64Url(String value)
value
as Base64 URL and filename-safe string.
This method is equivalent to using Base64.getUrlDecoder()
with the
char set Strings.DEFAULT_CHARSET
.
value
- the value to be decodedpublic static Csv decodeCsv(String data, char separator, char escaper)
data
.
To process Reader
input, refer to
Csv.parse(Reader, char, char)
.
data
- the CSV input dataseparator
- the CSV separator characterescaper
- the CSV escaping characterIllegalArgumentException
- on illegal separator
or
escaper
valuepublic static String decodeUrl(String value) throws StringParseException
application/x-www-form-urlencoded
string.
This method is equivalent to using URLDecoder.decode(String)
with the
char set StandardCharsets.UTF_8
as the
World Wide Web Consortium Recommendation states that UTF-8 should be
used.
value
- the value to be decodedStringParseException
- on illegal or incomplete hex characterspublic static String encodeBase64(String value)
value
into Base64 format.
This method is equivalent to using Base64.getEncoder()
with the char
set Strings.DEFAULT_CHARSET
.
value
- the value to be encodedpublic static String encodeBase64Mime(String value)
value
into Base64 MIME type encoding scheme.
This method is equivalent to using Base64.getMimeEncoder()
with the
char set Strings.DEFAULT_CHARSET
.
value
- the value to be encodedpublic static String encodeBase64Url(String value)
value
into Base64 URL and filename-safe format.
This method is equivalent to using Base64.getUrlEncoder()
with the
charset Strings.DEFAULT_CHARSET
.
value
- the value to be encodedpublic static String encodeCsv(Collection<? extends Collection<String>> data, char separator, char escaper)
data
as CSV document. Occurrences of special characters are
encoded using escaper
and values are separated using
separator
.
For more information on single value escaping see
encodeCsvValue(String, char, char)
.
data
- the data to be encodedseparator
- the CSV separator characterescaper
- the CSV escaping characterpublic static String encodeCsvRow(Collection<? extends String> values, char separator, char escaper)
values
as one CSV row. Occurrences of special characters are
encoded using escaper
and values are separated using
separator
.
For more information on single value escaping see
encodeCsvValue(String, char, char)
.
values
- the values to be encodedseparator
- the CSV separator characterescaper
- the CSV escaping characterpublic static String encodeCsvValue(String value, char separator, char escaper)
value
into a single CSV value. All occurrences of
escaper
are escaped (doubled). If value
contains
inappropriate characters, it is surrounded by escaper
.
Inappropriate characters are '\r'
, '\n'
, escaper
and
separator
. The latter is used for the list of inappropriate
characters only.
Examples:
Parameter | Return Value |
---|---|
EMPTY | EMPTY |
abc | abc |
abc"xyz | "abc""xyz" |
" | """" |
value
- the value to be encodedseparator
- the CSV separator characterescaper
- the CSV escaping characterpublic static String encodeUrl(String value)
application/x-www-form-urlencoded
format
with the char set StandardCharsets.UTF_8
as the
World Wide Web Consortium Recommendation states that UTF-8 should be
used.value
- the value to be encodedCopyright © 2025. All rights reserved.