if (usedDecoder == null) {
CharsetDetector detector = new CharsetDetector();
detector.enableInputFilter(filtered);
byte[] data = buffer.toByteArray();
detector.setText(data);
CharsetMatch cm = detector.detect();
try {
usedDecoder = Charset.forName(cm == null ? "ISO-8859-1" : cm.getName()).newDecoder();
} catch (UnsupportedCharsetException ex) {
usedDecoder = Charset.forName("ISO-8859-1").newDecoder();
}