in src/main/java/org/apache/maven/doxia/DefaultConverter.java [690:715]
static String autoDetectEncoding(File f) {
if (!f.isFile()) {
throw new IllegalArgumentException(
"The file '" + f.getAbsolutePath() + "' is not a file, could not detect encoding.");
}
try {
if (XmlUtil.isXml(f)) {
try (XmlStreamReader reader = new XmlStreamReader(f)) {
return reader.getEncoding();
}
}
try (InputStream is = new BufferedInputStream(new FileInputStream(f))) {
CharsetDetector detector = new CharsetDetector();
detector.setText(is);
CharsetMatch match = detector.detect();
return match.getName().toUpperCase(Locale.ENGLISH);
}
} catch (IOException e) {
// nop
}
throw new UnsupportedOperationException(format(
"Could not detect the encoding for file: %s\n" + "Specify explicitly the encoding.",
f.getAbsolutePath()));
}