Java Byte Array to String by Charset isCharset(byte[] b, String inCharset)

Here you can find the source of isCharset(byte[] b, String inCharset)

Description

is Charset

License

LGPL

Declaration

public static boolean isCharset(byte[] b, String inCharset) 

Method Source Code

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

import java.nio.ByteBuffer;
import java.nio.charset.CharacterCodingException;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;

public class Main {
    public static boolean isCharset(byte[] b, String inCharset) {
        CharsetDecoder cd = Charset.availableCharsets().get(inCharset).newDecoder();
        try {/* w  w w . j av  a2  s.  c  om*/
            cd.decode(ByteBuffer.wrap(b));
        } catch (CharacterCodingException e) {
            return false;
        }
        return true;
    }
}

Related

  1. getString(@Nonnull byte[] b, @Nonnegative int bufferSize, @Nonnegative int offset, @Nonnull Charset charset)
  2. getString(byte[] bytes, String charset)
  3. getString(byte[] bytesIn, Charset cs)
  4. identify(byte[] bytes, CharsetDecoder decoder)
  5. inflate(byte[] bytes, Charset encoding)
  6. newString(byte[] bytes, Charset charset)
  7. newString(byte[] bytes, String charsetName)
  8. newString(final byte[] bytes, final Charset charset)
  9. newString(final byte[] bytes, final Charset charset)