public class StringUtils extends Object
Modifier and Type | Field and Description |
---|---|
static String |
LINE_SEPARATOR
Line separator to use for this OS, i.e.
|
Modifier and Type | Method and Description |
---|---|
static byte[] |
getBytesUtf8(String string)
Encodes the given string into a sequence of bytes using the UTF-8 charset, storing the result
into a new byte array.
|
static String |
newStringUtf8(byte[] bytes)
Constructs a new
String by decoding the specified array of bytes using the UTF-8
charset. |
public static final String LINE_SEPARATOR
"\n"
or "\r\n"
.public static byte[] getBytesUtf8(String string)
string
- the String to encode, may be null
null
if the input string was null
IllegalStateException
- Thrown when the charset is missing, which should be never
according the Java specification.public static String newStringUtf8(byte[] bytes)
String
by decoding the specified array of bytes using the UTF-8
charset.bytes
- The bytes to be decoded into charactersString
decoded from the specified array of bytes using the UTF-8
charset, or null
if the input byte array was null
.IllegalStateException
- Thrown when a UnsupportedEncodingException
is caught,
which should never happen since the charset is required.Copyright © 2011–2021 Google. All rights reserved.