Code example for CharsetDecoder

Methods: decodeonMalformedInput

0
   * @param conf The configuration to do the setting on. 
   */ 
  private static void setBinaryConfSetting(String isValueBinaryEncodedSetting,
      String potentiallyEncodedSetting, byte[] data, Configuration conf) {
    CharsetDecoder decoder = UTF_8.newDecoder();
    decoder.onMalformedInput(CodingErrorAction.REPORT);
    try { 
      CharBuffer colFamString = decoder.decode(ByteBuffer.wrap(data));
      conf.setBoolean(isValueBinaryEncodedSetting, false);
      conf.set(potentiallyEncodedSetting, colFamString.toString());
    } catch (CharacterCodingException e) {
      conf.setBoolean(isValueBinaryEncodedSetting, true);
      conf.set(potentiallyEncodedSetting, new String(Base64.encodeBase64(data),
          UTF_8));
    } 
  } 
 
  /** 
   * Get the contents of a key that might be binary. 
   * @param isBinarySettingKey Tells us weather or not the field is binary. 
Experience pair programming with AI  Get Codota for Java