Here you can find the source of identify(byte[] bytes, CharsetDecoder decoder)
private static boolean identify(byte[] bytes, CharsetDecoder decoder)
//package com.java2s; /*/*from ww w. jav a 2 s . c om*/ * License information at https://github.com/Caltech-IPAC/firefly/blob/master/License.txt */ import java.nio.ByteBuffer; import java.nio.charset.CharacterCodingException; import java.nio.charset.CharsetDecoder; public class Main { private static boolean identify(byte[] bytes, CharsetDecoder decoder) { try { decoder.decode(ByteBuffer.wrap(bytes)); } catch (CharacterCodingException e) { return false; } return true; } }