Java Byte Array to String by Charset newString(byte[] bytes, Charset charset)

Here you can find the source of newString(byte[] bytes, Charset charset)

Description

new String

License

Apache License

Declaration

private static String newString(byte[] bytes, Charset charset) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

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

public class Main {
    private static String newString(byte[] bytes, Charset charset) {
        return bytes == null ? null : new String(bytes, charset);
    }/* w ww.  j  av a 2  s  .co m*/

    public static String newString(byte[] bytes, String charsetName) {
        if (bytes == null) {
            return null;
        } else {
            try {
                return new String(bytes, charsetName);
            } catch (UnsupportedEncodingException var3) {
                throw newIllegalStateException(charsetName, var3);
            }
        }
    }

    private static IllegalStateException newIllegalStateException(String charsetName,
            UnsupportedEncodingException e) {
        return new IllegalStateException(charsetName + ": " + e);
    }
}

Related

  1. getString(byte[] bytes, String charset)
  2. getString(byte[] bytesIn, Charset cs)
  3. identify(byte[] bytes, CharsetDecoder decoder)
  4. inflate(byte[] bytes, Charset encoding)
  5. isCharset(byte[] b, String inCharset)
  6. newString(byte[] bytes, String charsetName)
  7. newString(final byte[] bytes, final Charset charset)
  8. newString(final byte[] bytes, final Charset charset)
  9. newStringFromSplit(CharsetDecoder decoder, CharsetDecoder utf8Decoder, String encoding, byte[] fieldBytes, int length)