Java Byte Array to String by Charset parseBytes(byte[] encoded, Charset charset)

Here you can find the source of parseBytes(byte[] encoded, Charset charset)

Description

parse Bytes

License

Open Source License

Declaration

public static String parseBytes(byte[] encoded, Charset charset) throws UnsupportedEncodingException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

public class Main {

    public static String parseBytes(byte[] encoded) throws UnsupportedEncodingException {

        assert encoded != null : "encoded byte array should not be null";

        String decoded = parseBytes(encoded, StandardCharsets.UTF_8);
        return decoded;
    }//from  w  w w . ja  va 2  s.  c om

    public static String parseBytes(byte[] encoded, Charset charset) throws UnsupportedEncodingException {

        String decoded = new String(encoded, charset.name());
        return decoded;
    }
}

Related

  1. newString(byte[] bytes, Charset charset)
  2. newString(byte[] bytes, String charsetName)
  3. newString(final byte[] bytes, final Charset charset)
  4. newString(final byte[] bytes, final Charset charset)
  5. newStringFromSplit(CharsetDecoder decoder, CharsetDecoder utf8Decoder, String encoding, byte[] fieldBytes, int length)
  6. str(byte[] bytes, String charset)
  7. stringToByteArray(String str, Charset charsetForEncoding, int lenOfByteArray, byte filler)
  8. toBytes(CharSequence str, String charsetName)
  9. toBytes(String string, Charset charset)