Here you can find the source of encodeUTF8(String str)
Parameter | Description |
---|---|
str | the string to encode |
public static byte[] encodeUTF8(String str)
//package com.java2s; /*//from ww w. j ava 2 s . c om * Copyright (c) 2004, PostgreSQL Global Development Group * See the LICENSE file in the project root for more information. */ import java.nio.charset.Charset; public class Main { /** * Keep a local copy of the UTF-8 Charset so we can avoid synchronization overhead from looking up * the Charset by name as String.getBytes(String) requires. */ private final static Charset utf8Charset = Charset.forName("UTF-8"); /** * Encode a string as UTF-8. * * @param str the string to encode * @return the UTF-8 representation of {@code str} */ public static byte[] encodeUTF8(String str) { // See org.postgresql.benchmark.encoding.UTF8Encoding#string_getBytes // for performance measurements. // In OracleJDK 6u65, 7u55, and 8u40 String.getBytes(Charset) is // 3 times faster than other JDK approaches. return str.getBytes(utf8Charset); } }