Java Byte Array Decode decode(String encoding, byte[] data)

Here you can find the source of decode(String encoding, byte[] data)

Description

Decodes a byte array from specified encoding to a unicode String.

License

Open Source License

Parameter

Parameter Description
encoding a parameter
text a parameter

Return

byte[]

Declaration

public static String decode(String encoding, byte[] data) 

Method Source Code


//package com.java2s;
import java.io.UnsupportedEncodingException;

public class Main {
    /**//ww w  .j av  a 2  s  .  co m
     * Decodes a byte array from specified encoding to a unicode String. This
     * method returns null if the encoding is not supported
     * 
     * @param encoding
     * @param text
     * @return byte[]
     */
    public static String decode(String encoding, byte[] data) {
        if (data != null) {
            if (encoding == null)
                return new String(data);

            try {
                return new String(data, encoding);
            } catch (UnsupportedEncodingException e) {
            }
        }

        return null;
    }
}

Related

  1. decode(byte[] source, int off, int len)
  2. decode(byte[] src, String charset)
  3. decode(Byte[] wrap)
  4. decode(final byte[] source, final int off, final int len)
  5. decode(String encoding, byte[] bytes)
  6. decodeBytes(byte[] data, String encoding)
  7. decodeObject(byte[] bytes)
  8. decodeObject(final byte[] bytes)
  9. decodeRequestParameter(String string, String encoding, byte[] buffer)