Java UTF8 Encode encodeUtf8(byte[] bytes)

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

Description

encode Utf

License

Apache License

Return

bytes converted to UTF-8 string, catching UnsupportedEncodingException since this is a pretty basic encoding

Declaration

public static String encodeUtf8(byte[] bytes) 

Method Source Code


//package com.java2s;
/*/*from  w  w w  .j  ava  2s.  c  o m*/
 *  Copyright Gergely Nagy <greg@webhejj.hu>
 *
 *  Licensed under the Apache License, Version 2.0; 
 *  you may obtain a copy of the License at:
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 */

import java.io.UnsupportedEncodingException;

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

    /** @return bytes converted to UTF-8 string, catching 
     * UnsupportedEncodingException since this is a pretty basic encoding
     */
    public static String encodeUtf8(byte[] bytes) {
        try {
            return bytes == null ? null : new String(bytes, UTF8);
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException("Could not convert bytes to UTF-8 string", e);
        }
    }
}

Related

  1. encodeSignatureUtf8(byte[] sig)
  2. encodeStringUtf8(String text)
  3. encodeToUTF8(String str)
  4. encodeUTF8(byte[] bytes)
  5. encodeUTF8(String str)
  6. encodeUTF8(String str)
  7. encodeUtf8(String string)