Java Utililty Methods UTF8 Encode

List of utility methods to do UTF8 Encode

Description

The list of methods to do UTF8 Encode are organized into topic(s).

Method

StringencodeSignatureUtf8(byte[] sig)
Encodes the signature using charset UTF-8.
return new String(sig, SIGNATURE_CHARSET);
StringencodeStringUtf8(String text)
encode String Utf
return new String(Charset.forName("UTF-8").encode(text).array());
StringencodeToUTF8(String str)
encode To UTF
return encode(str, StandardCharsets.UTF_8.name());
StringencodeUtf8(byte[] bytes)
encode Utf
try {
    return bytes == null ? null : new String(bytes, UTF8);
} catch (UnsupportedEncodingException e) {
    throw new RuntimeException("Could not convert bytes to UTF-8 string", e);
StringencodeUTF8(byte[] bytes)
encode UTF
return new String(bytes, CHARSET_UTF8);
byte[]encodeUTF8(String str)
Encode a string as UTF-8.
return str.getBytes(utf8Charset);
byte[]encodeUTF8(String str)
Convenience method for encoding a UTF-8 byte string from a Java String .
try {
    return str.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
    throw new RuntimeException("UTF-8 charset not found! This should not happen...", e);
byte[]encodeUtf8(String string)
encode Utf
if (string == null)
    return null;
return string.getBytes(CharsetUTF8);
StringencodeUtf8(String target)
encode Utf
String result = null;
try {
    result = new String(target.getBytes(), "UTF-8");
} catch (UnsupportedEncodingException e) {
    System.err.println("ERROR! encode utf8 failed - " + e);
return result;
byte[]encodeUTF8(String text)
encode UTF
try {
    return text.getBytes(UTF_8.name());
} catch (UnsupportedEncodingException e) {
    throw new AssertionError(e);