Java UTF8 From getUTF8(String string)

Here you can find the source of getUTF8(String string)

Description

Encodes a string as an array of UTF-8 bytes.

License

Open Source License

Parameter

Parameter Description
string Java string

Return

UTF-8 byte array

Declaration

public static byte[] getUTF8(String string) 

Method Source Code

//package com.java2s;
/*/*from w w  w  .  j  a  v  a 2 s  .co m*/
 * Copyright 2009 Tim Krajcar <allegro@conmolto.org>.
 *
 * This file is part of Koom, a BattleTech MUX graphical HUD client.
 *
 * Koom is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Koom 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Koom.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.io.UnsupportedEncodingException;

public class Main {
    /**
     * Encodes a string as an array of UTF-8 bytes. Mostly used to pre-encode
     * constants.
     * 
     * @param string
     *            Java string
     * 
     * @return UTF-8 byte array
     */
    public static byte[] getUTF8(String string) {
        try {
            return string.getBytes("UTF-8");
        } catch (UnsupportedEncodingException ex) {
            // All JVMs should support UTF-8.
            throw new AssertionError(ex);
        }
    }
}

Related

  1. getUTF8(byte[] bytes)
  2. getUTF8(String data)
  3. getUTF8(String s)
  4. getUTF8Bytes(String data)
  5. getUTF8Bytes(String s)
  6. getUtf8Bytes(String s)
  7. getUtf8Bytes(String s)