Example usage for org.apache.commons.codec DecoderException DecoderException

List of usage examples for org.apache.commons.codec DecoderException DecoderException

Introduction

In this page you can find the example usage for org.apache.commons.codec DecoderException DecoderException.

Prototype

public DecoderException(final String message, final Throwable cause) 

Source Link

Document

Constructs a new exception with the specified detail message and cause.

Usage

From source file:com.anteam.demo.codec.cipher.symmetric.DESedeCoder.java

/**
 * Decodes a byte array and returns the results as a byte array.
 *
 * @param source A byte array which has been encoded with the appropriate encoder
 * @return ?byte.source, null//from  w  w  w.  j  a  v  a2 s.  co m
 * @throws org.apache.commons.codec.DecoderException A decoder exception is thrown if a Decoder encounters a failure condition during the decode process.
 */
@Override
public byte[] decode(byte[] source) throws DecoderException {
    if (source == null) {
        return null;
    }
    try {
        SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(ALGORITHM_NAME);
        SecretKey secretKey = keyFactory.generateSecret(keySpec);
        Cipher cipher = Cipher.getInstance(CIPHER_NAME);
        cipher.init(Cipher.DECRYPT_MODE, secretKey, IvParameters);
        return cipher.doFinal(source);
    } catch (Exception e) {
        LOG.error(":" + key + ":" + source, e);
        throw new DecoderException(":" + key + ":" + source, e);
    }
}

From source file:com.vinted.ab.security.Hex.java

/**
 * Converts a String or an array of character bytes representing hexadecimal values into an array of bytes of those
 * same values. The returned array will be half the length of the passed String or array, as it takes two characters
 * to represent any given byte. An exception is thrown if the passed char array has an odd number of elements.
 *
 * @param object// ww  w.  j a  va  2  s  . c  o m
 *            A String or, an array of character bytes containing hexadecimal digits
 * @return A byte array containing binary data decoded from the supplied byte array (representing characters).
 * @throws DecoderException
 *             Thrown if an odd number of characters is supplied to this function or the object is not a String or
 *             char[]
 * @see #decodeHex(char[])
 */
@Override
public Object decode(Object object) throws DecoderException {
    try {
        char[] charArray = object instanceof String ? ((String) object).toCharArray() : (char[]) object;
        return decodeHex(charArray);
    } catch (ClassCastException e) {
        throw new DecoderException(e.getMessage(), e);
    }
}

From source file:sample.tsc.util.Hex.java

/**
 * Converts an array of character bytes representing hexadecimal values into an array of bytes of those same values.
 * The returned array will be half the length of the passed array, as it takes two characters to represent any given
 * byte. An exception is thrown if the passed char array has an odd number of elements.
 * //w  ww.ja v  a2 s  . c o m
 * @param array
 *            An array of character bytes containing hexadecimal digits
 * @return A byte array containing binary data decoded from the supplied byte array (representing characters).
 * @throws DecoderException
 *             Thrown if an odd number of characters is supplied to this function
 * @see #decodeHex(char[])
 */
public byte[] decode(byte[] array) throws DecoderException {
    try {
        return decodeHex(new String(array, getCharsetName()).toCharArray());
    } catch (UnsupportedEncodingException e) {
        throw new DecoderException(e.getMessage(), e);
    }
}

From source file:sample.tsc.util.Hex.java

/**
 * Converts a String or an array of character bytes representing hexadecimal values into an array of bytes of those
 * same values. The returned array will be half the length of the passed String or array, as it takes two characters
 * to represent any given byte. An exception is thrown if the passed char array has an odd number of elements.
 * /*  ww  w.j a v  a 2s .com*/
 * @param object
 *            A String or, an array of character bytes containing hexadecimal digits
 * @return A byte array containing binary data decoded from the supplied byte array (representing characters).
 * @throws DecoderException
 *             Thrown if an odd number of characters is supplied to this function or the object is not a String or
 *             char[]
 * @see #decodeHex(char[])
 */
public Object decode(Object object) throws DecoderException {
    try {
        char[] charArray = object instanceof String ? ((String) object).toCharArray() : (char[]) object;
        return decodeHex(charArray);
    } catch (ClassCastException e) {
        throw new DecoderException(e.getMessage(), e);
    }
}