code: protected String getCharsetFromBytes(byte buffer[], int len) 
  	throws IOException {
  		String charsetName = null;
  	    UniversalDetector detector = new UniversalDetector(null);
  		detector.handleData(buffer, 0, len);
  		detector.dataEnd();
  	    charsetName = detector.getDetectedCharset();
  	    detector.reset();
  	    if(isCharsetSupported(charsetName)) {
  	    	return mapCharset(charsetName);
  	    }
  	    return null;
  	}
docs: Attempts to figure out the character set of the document using
  the excellent juniversalchardet library.
  
  @param resource
  @return String character encoding found, or null if nothing looked good.
  @throws IOException