Java Utililty Methods UTF8 From

List of utility methods to do UTF8 From

Description

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

Method

byte[]getUtf8Bytes(String str)
Returns the passed string as a byte array containing the string in UTF-8 representation.
try {
    return str.getBytes("UTF-8");
} catch (UnsupportedEncodingException uee) {
    return str.getBytes();
byte[]getUtf8Bytes(String str)
get Utf Bytes
if (hasLength(str)) {
    try {
        return str.getBytes("UTF-8");
    } catch (UnsupportedEncodingException e) {
        ;
return null;
...
InputStreamgetUTF8Stream(String s)
get UTF Stream
try {
    ByteArrayOutputStream bas = new ByteArrayOutputStream();
    Writer w = new OutputStreamWriter(bas, "utf-8");
    w.write(s);
    w.close();
    byte[] ba = bas.toByteArray();
    ByteArrayInputStream bis = new ByteArrayInputStream(ba);
    return bis;
...
StringgetUTF8String(byte[] bytes)
Converts string into an UTF8 String and handles the unlikely case where UTF-8 is not supported.
try {
    return new String(bytes, "UTF-8");
} catch (UnsupportedEncodingException exc) {
    return new String(bytes);
StringgetUTF8String(byte[] bytes)
Utility wrapper for getting a String object out of byte [] using the UTF-8 encoding.
return getEncodedString(bytes, "UTF-8");
StringgetUTF8String(String input)
get UTF String
try {
    return new String(input.getBytes(), "UTF-8");
} catch (UnsupportedEncodingException e) {
    e.printStackTrace();
    return input;