protected String getCharsetFromMeta ( byte buffer [ ] , int len ) throws IOException { String charsetName = null ; // convert to UTF-8 String -- which hopefully will not mess up the // characters we're interested in... String sample = new String ( buffer , 0 , len , DEFAULT_CHARSET ) ; String metaContentType = findMetaContentType ( sample ) ; if ( metaContentType != null ) { charsetName = contentTypeToCharset ( metaContentType ) ; } return charsetName ; }
Attempt to find a META tag in the HTML that hints at the character set used to write the document .