private static String getCharsetFromBOM ( final byte [ ] byteData ) { BOMInputStream bomIn = new BOMInputStream ( new ByteArrayInputStream ( byteData ) ) ; try { ByteOrderMark bom = bomIn . getBOM ( ) ; if ( bom != null ) { return bom . getCharsetName ( ) ; } } catch ( IOException e ) { return null ; } return null ; }
Detects any BOMs and returns the corresponding charset