try {
final String result = charset.newDecoder().onMalformedInput(CodingErrorAction.REPORT).onUnmappableCharacter(CodingErrorAction.REPORT).decode(buffer).toString();
return result;
} catch (IllegalStateException e) {
throw new DecodingException(HumanReadableText.BAD_IO_ENCODING, "Bad character encoding", e);
} catch (MalformedInputException e) {
throw new DecodingException(HumanReadableText.BAD_IO_ENCODING, "Bad character encoding", e);
} catch (UnmappableCharacterException e) {
throw new DecodingException(HumanReadableText.BAD_IO_ENCODING, "Bad character encoding", e);
} catch (CharacterCodingException e) {
throw new DecodingException(HumanReadableText.BAD_IO_ENCODING, "Bad character encoding", e);
}
}