Java UTF8 Convert To fromUTF8Bytes(byte[] bytes)

Here you can find the source of fromUTF8Bytes(byte[] bytes)

Description

from UTF Bytes

License

LGPL

Declaration

public static String fromUTF8Bytes(byte[] bytes) 

Method Source Code


//package com.java2s;
/*/*  www . j ava  2s . c om*/
 * Copyright (C) 2009 by Eric Herman <eric@freesa.org>
 * Use and distribution licensed under the
 * GNU Lesser General Public License (LGPL) version 2.1.
 * See the COPYING file in the parent directory for full text.
 */

import java.io.UnsupportedEncodingException;

public class Main {
    public static final String CHARSET_UTF_8 = "UTF-8";

    public static String fromUTF8Bytes(byte[] bytes) {
        return fromBytes(bytes, CHARSET_UTF_8);
    }

    public static String fromBytes(byte[] bytes, String encoding) {
        if (bytes == null) {
            return null;
        }
        try {
            return new String(bytes, encoding);
        } catch (UnsupportedEncodingException e) {
            throw new IllegalArgumentException("Runtime does not support" + " encoding " + encoding, e);
        }
    }
}

Related

  1. fromUTF8(byte[] b)
  2. fromUTF8(byte[] bytes)
  3. fromUTF8(byte[] bytes)
  4. fromUTF8(byte[] bytes)
  5. fromUTF8Bytes(byte[] bytes)
  6. getBytesUtf8(String str)
  7. getBytesUtf8(String string)
  8. getBytesUtf8(String string)