Java UTF8 From getUtf8Bytes(String str)

Here you can find the source of getUtf8Bytes(String str)

Description

get Utf Bytes

License

Apache License

Declaration

public static byte[] getUtf8Bytes(String str) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.UnsupportedEncodingException;

public class Main {
    public static byte[] getUtf8Bytes(String str) {
        if (hasLength(str)) {
            try {
                return str.getBytes("UTF-8");
            } catch (UnsupportedEncodingException e) {
                ;//from  w  w w  . j  a  va2  s .c o  m
            }
        }
        return null;
    }

    public static boolean hasLength(CharSequence str) {
        return (str != null && str.length() > 0);
    }

    public static boolean hasLength(String str) {
        return hasLength((CharSequence) str);
    }
}

Related

  1. getUTF8Bytes(String s)
  2. getUtf8Bytes(String s)
  3. getUTF8Bytes(String s)
  4. getUtf8Bytes(String s)
  5. getUTF8Bytes(String str)
  6. getUtf8Bytes(String str)
  7. getUTF8Stream(String s)
  8. getUTF8String(byte[] bytes)
  9. getUTF8String(byte[] bytes)