List of usage examples for org.apache.commons.codec DecoderException getMessage
public String getMessage()
From source file:com.lehman.ic9.common.hex.java
/** * Decodes the provided data and returns a byte[] with the * decoded data.// w w w . ja v a2 s .c om * @param str is a hex encoded String. * @return A byte[] with the decoded bytes. * @throws ic9exception Exception */ public static byte[] decode(String str) throws ic9exception { try { return Hex.decodeHex(str.toCharArray()); } catch (DecoderException e) { throw new ic9exception("hex.decode(): " + e.getMessage()); } }
From source file:info.bonjean.beluga.util.CryptoUtil.java
public static String pandoraDecrypt(String text) { try {//from ww w . j a v a 2 s . c o m return new String(decryptBlowfish(Hex.decodeHex(text.toCharArray()), DECRYPT_KEY)).trim(); } catch (DecoderException e) { log.error(e.getMessage(), e); return null; } }
From source file:com.jfrog.bintray.client.impl.util.URIUtil.java
/** * Unescape and decode a given string regarded as an escaped string with the * default protocol charset./*from w ww.j av a 2s. c om*/ * * @param escaped a string * @return the unescaped string * @throws HttpException if the string cannot be decoded (invalid) */ public static String decode(String escaped) throws HttpException { try { byte[] rawdata = URLCodec.decodeUrl(EncodingUtils.getAsciiBytes(escaped)); return EncodingUtils.getString(rawdata, UTF8_CHARSET_NAME); } catch (DecoderException e) { throw new HttpException(e.getMessage()); } }
From source file:be.fedict.eid.applet.service.impl.UserIdentifierUtil.java
/** * Gives back a non-reversible citizen identifier (NRCID). * //from w w w . j a v a 2s. c om * @param userId * the primary user identifier, i.e. the national registry * number. * @param orgId * the optional organization identifier. * @param appId * the optional application identifier. * @param secret * the application specific secret. Should be at least 128 bit * long. Encoded in hexadecimal format. * @return */ public static String getNonReversibleCitizenIdentifier(String userId, String orgId, String appId, String secret) { if (null == secret) { throw new IllegalArgumentException("secret key is null"); } /* * Avoid XML formatting issues introduced by some web.xml XML editors. */ secret = secret.trim(); if (null != orgId) { orgId = orgId.trim(); } else { LOG.warn("it is advised to use an orgId"); } if (null != appId) { appId = appId.trim(); } else { LOG.warn("it is advised to use an appId"); } /* * Decode the secret key. */ byte[] secretKey; try { secretKey = Hex.decodeHex(secret.toCharArray()); } catch (DecoderException e) { LOG.error("secret is not hexadecimal encoded: " + e.getMessage()); throw new IllegalArgumentException("secret is not hexadecimal encoded"); } if ((128 / 8) > secretKey.length) { /* * 128 bit is seen as secure these days. */ LOG.warn("secret key is too short"); throw new IllegalArgumentException("secret key is too short"); } /* * Construct the HMAC input sequence. */ String input = userId; if (null != appId) { input += appId; } if (null != orgId) { input += orgId; } byte[] inputData = input.getBytes(); SecretKey macKey = new SecretKeySpec(secretKey, HMAC_ALGO); Mac mac; try { mac = Mac.getInstance(macKey.getAlgorithm()); } catch (NoSuchAlgorithmException e) { throw new RuntimeException("HMAC algo not available: " + e.getMessage()); } try { mac.init(macKey); } catch (InvalidKeyException e) { LOG.error("invalid secret key: " + e.getMessage(), e); throw new RuntimeException("invalid secret"); } mac.update(inputData); byte[] resultHMac = mac.doFinal(); String resultHex = new String(Hex.encodeHex(resultHMac)).toUpperCase(); return resultHex; }
From source file:com.moz.fiji.schema.util.JsonEntityIdParser.java
/** * Gets byte array from string entity id given in "hbase=" or "hbase_hex" format. * * @param stringEntityId representing the row to acquire byte array for. * @return byte array of entity id./*from w ww . ja v a2s . c om*/ * @throws IOException if the ASCII-encoded hex was improperly formed. */ private static byte[] parseBytes(final String stringEntityId) throws IOException { if (stringEntityId.startsWith(HBASE_ROW_KEY_PREFIX)) { final String rowKeySubstring = stringEntityId.substring(HBASE_ROW_KEY_PREFIX.length()); return Bytes.toBytesBinary(rowKeySubstring); } else if (stringEntityId.startsWith(HBASE_HEX_ROW_KEY_PREFIX)) { final String rowKeySubstring = stringEntityId.substring(HBASE_HEX_ROW_KEY_PREFIX.length()); try { return Hex.decodeHex(rowKeySubstring.toCharArray()); } catch (DecoderException de) { // Re-wrap decoder exception as IOException. throw new IOException(de.getMessage()); } } else { throw new IllegalArgumentException("Passed string must be prefixed by hbase= or hbase_hex=."); } }
From source file:com.silverpeas.util.StringUtil.java
/** * Decodes the specified text with hexadecimal values in bytes of those same values. The text is * considered to be in the UTF-8 charset. */*from www .j av a 2 s .c om*/ * @param hexText the text with hexadecimal-based characters. * @return the binary representation of the text. * @throws ParseException if an odd number or illegal of characters is supplied. */ public static byte[] fromHex(String hexText) throws ParseException { try { return Hex.decodeHex(hexText.toCharArray()); } catch (DecoderException ex) { throw new ParseException(ex.getMessage(), -1); } }
From source file:com.microsoft.tfs.core.httpclient.util.URIUtil.java
/** * Unescape and decode a given string regarded as an escaped string with the * default protocol charset./* ww w .j a v a2 s. c o m*/ * * @param escaped * a string * @return the unescaped string * * @throws URIException * if the string cannot be decoded (invalid) * * @see URI#getDefaultProtocolCharset */ public static String decode(final String escaped) throws URIException { try { final byte[] rawdata = URLCodec.decodeUrl(EncodingUtil.getAsciiBytes(escaped)); return EncodingUtil.getString(rawdata, URI.getDefaultProtocolCharset()); } catch (final DecoderException e) { throw new URIException(e.getMessage()); } }
From source file:com.xqdev.jam.MLJAM.java
public static byte[] hexDecode(String s) { try {//from w w w .j a v a2 s.c om return Hex.decodeHex(s.toCharArray()); } catch (DecoderException e) { throw new ClientProblemException("Hex content is not valid hex: " + e.getMessage() + ": " + s); } }
From source file:com.jfrog.bintray.client.impl.util.URI.java
/** * Decodes URI encoded string.//from w ww. j a v a 2 s .c o m * <p/> * This is a two mapping, one from URI characters to octets, and * subsequently a second from octets to original characters: * <p><blockquote><pre> * URI character sequence->octet sequence->original character sequence * </pre></blockquote><p> * <p/> * A URI must be separated into its components before the escaped * characters within those components can be allowedly decoded. * <p/> * Notice that there is a chance that URI characters that are non UTF-8 * may be parsed as valid UTF-8. A recent non-scientific analysis found * that EUC encoded Japanese words had a 2.7% false reading; SJIS had a * 0.0005% false reading; other encoding such as ASCII or KOI-8 have a 0% * false reading. * <p/> * The percent "%" character always has the reserved purpose of being * the escape indicator, it must be escaped as "%25" in order to be used * as data within a URI. * <p/> * The unescape method is internally performed within this method. * * @param component the URI character sequence * @param charset the protocol charset * @return original character sequence * @throws HttpException incomplete trailing escape pattern or unsupported * character encoding * @since 3.0 */ protected static String decode(String component, String charset) throws HttpException { if (component == null) { throw new IllegalArgumentException("Component array of chars may not be null"); } byte[] rawdata = null; try { rawdata = URLCodec.decodeUrl(EncodingUtils.getAsciiBytes(component)); } catch (DecoderException e) { throw new HttpException(e.getMessage()); } return EncodingUtils.getString(rawdata, charset); }
From source file:com.mac.hazewinkel.plist.datamodel.PListData.java
@Override public void setAsString(String newValue) throws IllegalArgumentException { if (newValue == null) { throw new IllegalArgumentException("value cannot be Null"); }//from w w w. java 2 s . c o m try { value = Hex.decodeHex(newValue.toCharArray()); } catch (DecoderException e) { throw new IllegalArgumentException("Cannot parse data: " + e.getMessage()); } }