KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: ByteArrayToHexString.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.mule.transformers.AbstractTransformer;
14 import org.mule.umo.transformer.TransformerException;
15 import org.mule.util.StringUtils;
16
17 /**
18  * Converts a Byte array to a Hex String
19  *
20  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
21  * @version $Revision: 3798 $
22  */

23 public class ByteArrayToHexString extends AbstractTransformer
24 {
25
26     /**
27      * Serial version
28      */

29     private static final long serialVersionUID = -7444711426569720031L;
30
31     private volatile boolean upperCase = false;
32
33     public ByteArrayToHexString()
34     {
35         registerSourceType(byte[].class);
36         setReturnClass(String JavaDoc.class);
37     }
38
39     public boolean getUpperCase()
40     {
41         return upperCase;
42     }
43
44     public void setUpperCase(boolean value)
45     {
46         upperCase = value;
47     }
48
49     protected Object JavaDoc doTransform(Object JavaDoc src, String JavaDoc encoding) throws TransformerException
50     {
51         if (src == null)
52         {
53             return StringUtils.EMPTY;
54         }
55
56         try
57         {
58             return StringUtils.toHexString((byte[])src, upperCase);
59         }
60         catch (Exception JavaDoc ex)
61         {
62             throw new TransformerException(this, ex);
63         }
64     }
65
66 }
67
Popular Tags