use of org.codelibs.fess.crawler.exception.ExtractException in project fess-crawler by codelibs.
the class AbstractXmlExtractor method getEncoding.
protected String getEncoding(final BufferedInputStream bis) {
final byte[] b = new byte[preloadSizeForCharset];
try {
bis.mark(preloadSizeForCharset);
final int c = bis.read(b);
if (c == -1) {
return encoding;
}
final String head = new String(b, 0, c, encoding);
if (StringUtil.isBlank(head)) {
return encoding;
}
final Matcher matcher = getEncodingPattern().matcher(head);
if (matcher.find()) {
final String enc = matcher.group(1);
if (Charset.isSupported(enc)) {
return enc;
}
}
} catch (final Exception e) {
if (logger.isInfoEnabled()) {
logger.info("Use a default encoding: " + encoding, e);
}
} finally {
try {
bis.reset();
} catch (final IOException e) {
throw new ExtractException(e);
}
}
return encoding;
}
Aggregations