stream = new BufferedInputStream(stream);
}
detector.setText(stream);
CharsetMatch match = detector.detect();
if (match == null) {
throw new TikaException("Unable to detect character encoding");
}
metadata.set(Metadata.CONTENT_ENCODING, match.getName());
String language = match.getLanguage();
if (language != null) {
metadata.set(Metadata.CONTENT_LANGUAGE, match.getLanguage());
metadata.set(Metadata.LANGUAGE, match.getLanguage());
}
return match.getReader();
}