Android UTF8 Encode utf8encode(String str)

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

Description

utfencode

Declaration

public static byte[] utf8encode(String str) 

Method Source Code

//package com.java2s;

import java.nio.CharBuffer;
import java.nio.charset.CharacterCodingException;
import java.nio.charset.Charset;

import java.nio.charset.CharsetEncoder;

public class Main {
    private static final CharsetEncoder UTF8_ENCODER = Charset.forName(
            "UTF-8").newEncoder();

    public static byte[] utf8encode(String str) {
        try {/*from   www .j  ava 2 s  . c  om*/
            return UTF8_ENCODER.encode(CharBuffer.wrap(str)).array();
        } catch (CharacterCodingException ex) {
            throw new RuntimeException(ex);
        }
    }
}

Related

  1. bytes2charsUTF8(byte[] buf, int bufOffset, int bufLength, char[] cbuf, boolean bigEndian)
  2. bytesUTF8len(byte[] buf, int bufOffset, int bufLength)
  3. char2ByteUTF8(String input, int inOff, int inEnd, byte[] output, int outOff, int outEnd, boolean getLengthFlag)
  4. getStringInUtf8(final String str)
  5. stringToUtf8Bytes(String string)
  6. isValidUTF8(byte[] input)
  7. string2BytesUTF8(String str)
  8. toUtf8Bytes(String data)
  9. toUtf8String(byte[] data)