1
2
3
4
5
6
7
8
9
10
11 package org.mule.transformer.simple;
12
13 import org.mule.api.transformer.TransformerException;
14 import org.mule.transformer.AbstractTransformer;
15 import org.mule.util.ArrayUtils;
16 import org.mule.util.StringUtils;
17
18
19
20
21 public class HexStringToByteArray extends AbstractTransformer
22 {
23
24 public HexStringToByteArray()
25 {
26 registerSourceType(String.class);
27 setReturnClass(byte[].class);
28 }
29
30 protected Object doTransform(Object src, String encoding) throws TransformerException
31 {
32 if (src == null)
33 {
34 return ArrayUtils.EMPTY_BYTE_ARRAY;
35 }
36
37 try
38 {
39 return StringUtils.hexStringToByteArray((String) src);
40 }
41 catch (Exception ex)
42 {
43 throw new TransformerException(this, ex);
44 }
45 }
46
47 }