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; /*-// w w w . j a v a 2 s . co m * jFUSE - FUSE bindings for Java * Copyright (C) 2008-2009 Erik Larsson <erik82@kth.se> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ import java.io.UnsupportedEncodingException; public class Main { /** * Convenience method for encoding a UTF-8 byte string from a Java * {@link String}. * * @param str the string to encode. * @return a UTF-8 encoded sequence containing the contents of 'str'. */ public static byte[] encodeUTF8(String str) { try { // TODO: Encode properly and deal with errors. return str.getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException("UTF-8 charset not found! This should not happen...", e); } } }