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

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

Introduction

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

Prototype

public EncoderException(final Throwable cause) 

Source Link

Document

Constructs a new exception with the specified cause and a detail message of (cause==null ?

Usage

From source file:imgb64.BinaryCodec.java

/**
 * Converts an array of raw binary data into an array of ASCII 0 and 1 chars.
 *
 * @param raw/*from  w w w.jav  a  2  s .  com*/
 *                  the raw binary data to convert
 * @return 0 and 1 ASCII character chars one for each bit of the argument
 * @throws EncoderException
 *                  if the argument is not a byte[]
 * @see org.apache.commons.codec.Encoder#encode(Object)
 */
@Override
public Object encode(final Object raw) throws EncoderException {
    if (!(raw instanceof byte[])) {
        throw new EncoderException("argument not a byte array");
    }
    return toAsciiChars((byte[]) raw);
}

From source file:com.softlayer.objectstorage.Container.java

/**
 * create this container on the server//from   w  w w.  ja  va  2 s. c o  m
 * 
 * @throws EncoderException
 * @throws IOException
 */
public void create() throws EncoderException, IOException {
    Hashtable<String, String> params = super.createAuthParams();
    if (super.isValidName(this.name)) {
        String uName = super.saferUrlEncode(this.name);
        super.put(params, null, super.storageurl + "/" + uName);
    } else {
        throw new EncoderException("Invalid Container Name");
    }
}

From source file:com.fatwire.dta.sscrawler.util.SSUriHelper.java

protected String encode(String value) throws EncoderException {
    try {//from  w  w w . ja  v  a2  s.  c  o  m
        return urlCodec.encode(value, getCharSet());
    } catch (UnsupportedEncodingException e) {
        EncoderException t = new EncoderException(e.getMessage());
        t.initCause(e);
        throw t;
    }

}

From source file:es.jamisoft.comun.codec.B64Codec.java

/**
 * Encodes an object into its Base64 form using the default charset. Unsafe characters are escaped.
 *
 * @param value//from   w  w w.j  a  v  a 2  s  .c  om
 *                  object to convert to Base64 form
 * @return Base64 object
 *
 * @throws EncoderException
 *                  thrown if a failure condition is encountered during the encoding process.
 */
public Object encode(Object value) throws EncoderException {
    if (value == null) {
        return null;
    } else if (value instanceof String) {
        return encode((String) value);
    } else {
        throw new EncoderException(
                "Objects of type " + value.getClass().getName() + " cannot be encoded using BCodec");
    }
}

From source file:com.softlayer.objectstorage.ObjectFile.java

/**
 * upload this file from a local file copy to the objectstorage server
 * /*from w w  w .j  a  v  a  2  s .c  om*/
 * @param localFileLocation
 *            string representation of the path of the local file
 * @param tags
 *            Map of tags to attach to this file
 * @return etag value of this upload
 * @throws EncoderException
 * @throws IOException
 */
public String uploadFile(String localFileLocation, Map<String, String> tags)
        throws EncoderException, IOException {
    if (super.isValidName(this.name)) {
        File file = new File(localFileLocation);
        bytes = new byte[(int) file.length()];
        FileInputStream fis = new FileInputStream(file);
        fis.read(bytes);
        Hashtable<String, String> params = super.createAuthParams();
        Iterator<Map.Entry<String, String>> it = tags.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry<String, String> pairs = (Map.Entry<String, String>) it.next();
            params.put(Client.X_OBJECT_META + pairs.getKey(), pairs.getValue());
            it.remove();
        }

        String uName = super.saferUrlEncode(this.containerName);
        String fName = super.saferUrlEncode(this.name);
        Representation representation = new InputRepresentation(new ByteArrayInputStream(bytes), MediaType.ALL);
        ClientResource client = super.put(params, representation, super.storageurl + "/" + uName + "/" + fName);
        this.headers = client.getResponseAttributes();
        Form head = (Form) this.headers.get("org.restlet.http.headers");
        return head.getFirstValue("Etag");
    } else {
        throw new EncoderException("invalid file name");
    }

}

From source file:com.example.phonetic.Nysiis.java

/**
 * Encodes an Object using the NYSIIS algorithm. This method is provided in
 * order to satisfy the requirements of the Encoder interface, and will
 * throw an {@link EncoderException} if the supplied object is not of type
 * {@link String}./* w  w w. j  a  v  a 2 s.  com*/
 *
 * @param obj Object to encode
 * @return An object (or a {@link String}) containing the NYSIIS code which
 * corresponds to the given String.
 * @throws EncoderException if the parameter supplied is not of a {@link String}
 * @throws IllegalArgumentException if a character is not mapped
 */
@Override
public Object encode(Object obj) throws EncoderException {
    if (!(obj instanceof String)) {
        throw new EncoderException("Parameter supplied to Nysiis encode is not of type java.lang.String");
    }
    return this.nysiis((String) obj);
}

From source file:com.app.framework.utilities.map.BaseNCodec.java

/**
 * Encodes an Object using the Base-N algorithm. This method is provided in order to satisfy the requirements of
 * the Encoder interface, and will throw an EncoderException if the supplied object is not of type byte[].
 *
 * @param obj Object to encode//from w ww .ja v  a2 s.  com
 * @return An object (of type byte[]) containing the Base-N encoded data which corresponds to the byte[] supplied.
 * @throws EncoderException if the parameter supplied is not of type byte[]
 */
@Override
public Object encode(final Object obj) throws EncoderException {
    if (!(obj instanceof byte[])) {
        throw new EncoderException("Parameter supplied to Base-N encode is not a byte[]");
    }
    return encode((byte[]) obj);
}

From source file:com.ibc.util.BaseNCodec.java

/**
 * Encodes an Object using the Base-N algorithm. This method is provided in order to satisfy the requirements of the
 * Encoder interface, and will throw an EncoderException if the supplied object is not of type byte[].
 *
 * @param pObject//from   w  ww .  j  a v  a2 s . c om
 *            Object to encode
 * @return An object (of type byte[]) containing the Base-N encoded data which corresponds to the byte[] supplied.
 * @throws EncoderException
 *             if the parameter supplied is not of type byte[]
 */
public Object encode(Object pObject) throws EncoderException {
    if (!(pObject instanceof byte[])) {
        throw new EncoderException("Parameter supplied to Base-N encode is not a byte[]");
    }
    return encode((byte[]) pObject);
}

From source file:com.niki.normalizer.Metaphone.java

/**
 * Encodes an Object using the metaphone algorithm.  This method
 * is provided in order to satisfy the requirements of the
 * Encoder interface, and will throw an EncoderException if the
 * supplied object is not of type java.lang.String.
 *
 * @param pObject Object to encode/*from   www  .j  a v a  2  s  . c o  m*/
 * @return An object (or type java.lang.String) containing the 
 *         metaphone code which corresponds to the String supplied.
 * @throws EncoderException if the parameter supplied is not
 *                          of type java.lang.String
 */
public Object encode(Object pObject) throws EncoderException {
    if (!(pObject instanceof String)) {
        throw new EncoderException("Parameter supplied to Metaphone encode is not of type java.lang.String");
    }
    return metaphone((String) pObject);
}

From source file:com.android.email.codec.binary.Base64.java

/**
 * Encodes an Object using the base64 algorithm. This method is provided in order to satisfy the requirements of the
 * Encoder interface, and will throw an EncoderException if the supplied object is not of type byte[].
 *
 * @param pObject//from  www  .  j av  a 2  s  .c  o m
 *            Object to encode
 * @return An object (of type byte[]) containing the base64 encoded data which corresponds to the byte[] supplied.
 * @throws EncoderException
 *             if the parameter supplied is not of type byte[]
 */
public Object encode(Object pObject) throws EncoderException {
    if (!(pObject instanceof byte[])) {
        throw new EncoderException("Parameter supplied to Base64 encode is not a byte[]");
    }
    return encode((byte[]) pObject);
}