UniversalDetector detector = new UniversalDetector(null);
detector.handleData(buf, 0, nrRead);
detector.dataEnd();
String encoding = detector.getDetectedCharset();
detector.reset();
if (encoding != null) {
if (!encoding.equals(ENCODING)) {
Log.error(Log.JEEVES,"Detected character set "+encoding+", converting to UTF-8");
return convertByteArrayToUTF8ByteArray(buf, encoding);
}