use of org.codice.ddf.libs.klv.data.Klv in project ddf by codice.
the class KlvEncodingDetectedString method decodeValue.
@Override
protected void decodeValue(Klv klv) {
byte[] bytes = klv.getValue();
CharsetDetector charsetDetector = new CharsetDetector();
charsetDetector.setText(bytes);
CharsetMatch[] charsetMatches = charsetDetector.detectAll();
Optional<CharsetMatch> charsetMatch = Arrays.stream(charsetMatches).filter(match -> possibleCharsets.contains(match.getName())).findFirst();
Charset charset = utf8;
if (charsetMatch.isPresent()) {
try {
charset = Charset.forName(charsetMatch.get().getName());
} catch (IllegalArgumentException e) {
LOGGER.trace("Unsupported encoding, falling back to default encoding");
}
}
value = new String(bytes, charset);
}
Aggregations