KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > transformers > simple > HexStringToByteArray


1 /*
2  * $Id: HexStringToByteArray.java 3798 2006-11-04 04:07:14Z aperepel $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.transformers.simple;
12
13 import org.apache.commons.lang.ArrayUtils;
14 import org.mule.transformers.AbstractTransformer;
15 import org.mule.umo.transformer.TransformerException;
16 import org.mule.util.StringUtils;
17
18 /**
19  * Converts a Hex String to a Byte array
20  *
21  * @author <a HREF="mailto:holger@codehaus.org">Holger Hoffstaette</a>
22  * @version $Revision: 3798 $
23  */

24 public class HexStringToByteArray extends AbstractTransformer
25 {
26
27     /**
28      * Serial version
29      */

30     private static final long serialVersionUID = 8266145248111508046L;
31
32     public HexStringToByteArray()
33     {
34         registerSourceType(String JavaDoc.class);
35         setReturnClass(byte[].class);
36     }
37
38     protected Object JavaDoc doTransform(Object JavaDoc src, String JavaDoc encoding) throws TransformerException
39     {
40         if (src == null)
41         {
42             return ArrayUtils.EMPTY_BYTE_ARRAY;
43         }
44
45         try
46         {
47             return StringUtils.hexStringToByteArray((String JavaDoc)src);
48         }
49         catch (Exception JavaDoc ex)
50         {
51             throw new TransformerException(this, ex);
52         }
53     }
54
55 }
56
Popular Tags