1 //==============================================================================
2 // file : Base64Utils.java
3 // project: Java Common Utility
4 //
5 // last change: date: $Date: 2003/09/10 09:22:14 $
6 // by: $Author: bitiboy $
7 // revision: $Revision: 1.1 $
8 //------------------------------------------------------------------------------
9 // copyright: GNU GPL Software License (see class documentation)
10 //==============================================================================
11 package com.justhis.util;
12
13
14 /*
15 * $Id: Base64Utils.java,v 1.1 2003/09/10 09:22:14 bitiboy Exp $
16 *
17 * Copyright 2003 Acai Software All Rights Reserved.
18 *
19 * This file Base64Utils.java is part of the Java Common Utility.
20
21 * The Java Common Utility is free software; you can redistribute it and/or modify
22 * it under the terms of the GNU General Public License as published by
23 * the Free Software Foundation; either version 2 of the License, or
24 * (at your option) any later version.
25
26 * Java Common Utility is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * GNU General Public License for more details.
30
31 * You should have received a copy of the GNU General Public License
32 * along with the Java Common Utility; if not, write to the Free Software
33 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34
35 * http://www.justhis.com http://ejb.cn
36 * CONTACT: email = webmaster@justhis.com superaxis@sohu.com
37 */
38 import com.justhis.util.exception.UtilException;
39
40 import java.io.ByteArrayInputStream;
41 import java.io.ByteArrayOutputStream;
42 import java.io.ObjectInputStream;
43 import java.io.ObjectOutputStream;
44
45
46 /***
47 * ????base64??????????
48 *
49 * @author <a href="http://blog.ejb.cn">acai</a>
50 * @version $Revision: 1.1 $
51 */
52 public class Base64Utils {
53 //~ Methods ----------------------------------------------------------------
54
55 /***
56 * ????base64??????????
57 *
58 * @param object ??????????????
59 *
60 * @return ????
61 *
62 * @throws UtilException ????????????????.
63 */
64 public static Object decode(char[] object) throws UtilException {
65 try {
66 return ((new ObjectInputStream(new ByteArrayInputStream(Base64
67 .decode(object)
68 )
69 )).readObject());
70 } catch (Exception e) {
71 throw new UtilException(e);
72 }
73 }
74
75 /***
76 * ??????????ojbect??????????????char ????
77 *
78 * @param object
79 *
80 * @return ??????????????
81 *
82 * @throws UtilException ????????????????
83 */
84 public static char[] encode(Object object) throws UtilException {
85 try {
86 ByteArrayOutputStream byteArray = new ByteArrayOutputStream();
87 ObjectOutputStream objectOutput = new ObjectOutputStream(byteArray);
88 objectOutput.writeObject(object);
89
90 return (Base64.encode(byteArray.toByteArray()));
91 } catch (Exception e) {
92 throw new UtilException(e);
93 }
94 }
95 }
96
97
98 /*
99 * $Log: Base64Utils.java,v $
100 * Revision 1.1 2003/09/10 09:22:14 bitiboy
101 * *** empty log message ***
102 *
103 *
104 */
This page was automatically generated by Maven