KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > transformers > codec > UUEncoder


1 /*
2  * $Id: UUEncoder.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.codec;
12
13 import org.mule.transformers.AbstractTransformer;
14 import org.mule.umo.transformer.TransformerException;
15
16 /**
17  * <code>Base64Encoder</code> transforms strings or byte arrays into UU encoded
18  * string
19  *
20  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
21  * @version $Revision: 3798 $
22  */

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

28     private static final long serialVersionUID = 4074142466316499186L;
29
30     private sun.misc.UUEncoder encoder;
31
32     public UUEncoder()
33     {
34         registerSourceType(String JavaDoc.class);
35         registerSourceType(byte[].class);
36         setReturnClass(String JavaDoc.class);
37         encoder = new sun.misc.UUEncoder();
38     }
39
40     /*
41      * (non-Javadoc)
42      *
43      * @see org.mule.umo.transformer.UMOTransformer#transform(java.lang.Object)
44      */

45     public Object JavaDoc doTransform(Object JavaDoc src, String JavaDoc encoding) throws TransformerException
46     {
47         byte[] buf;
48         if (src instanceof String JavaDoc)
49         {
50             buf = src.toString().getBytes();
51         }
52         else
53         {
54             buf = (byte[])src;
55         }
56         String JavaDoc result = encoder.encode(buf);
57         if (getReturnClass().equals(byte[].class))
58         {
59             return result.getBytes();
60         }
61         return result;
62     }
63 }
64
Popular Tags