Here you can find the source of isCharset(byte[] b, String inCharset)
public static boolean isCharset(byte[] b, String inCharset)
//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; } }