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

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

Description

convert To String

License

Open Source License

Declaration

public static String convertToString(final byte[] bytes, final Charset charset) 

Method Source Code

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

import java.nio.charset.Charset;
import java.text.DateFormat;

import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
    public static String convertToString(final byte[] bytes, final Charset charset) {
        return new String(bytes, charset);
    }//from   www  . ja  v a 2  s. com

    public static String convertToString(final byte[] bytes, final String charsetName) {
        return convertToString(bytes, Charset.forName(charsetName));
    }

    public static String convertToString(final byte[] bytes) {
        return convertToString(bytes, Charset.defaultCharset());
    }

    public static String convertToString(final char[] chars) {
        return new String(chars);
    }

    public static String convertToString(final short s) {
        return String.valueOf(s);
    }

    public static String convertToString(final int i) {
        return String.valueOf(i);
    }

    public static String convertToString(final long l) {
        return String.valueOf(l);
    }

    public static String convertToString(final float f) {
        return String.valueOf(f);
    }

    public static String convertToString(final double d) {
        return String.valueOf(d);
    }

    public static String convertToString(final Date date, final DateFormat dateFormat) {
        return dateFormat.format(date);
    }

    public static String convertToString(final Date date, final String format) {
        return convertToString(date, new SimpleDateFormat(format));
    }
}

Related

  1. charSetForBOM(byte[] buffer, int offset)
  2. convertCharset(byte[] content, Charset fromCharset, Charset toCharset)
  3. convertToBytes(final String str, final Charset charset)
  4. convertToChars(final byte[] bytes, final Charset charset)
  5. convertToString(byte[] bytes, Charset charset)
  6. decode(CharsetDecoder decoder, byte[] in)
  7. decode(final byte[] binaryValue, final Charset charset)
  8. decode(final byte[] binaryValue, final Charset charset)
  9. decode(final byte[] pData, final int pOffset, final int pLength, final String pCharset)