1 34 35 36 package com.micronova.util.codec; 37 38 import com.micronova.util.*; 39 40 public class CodecBase64 extends Codec 41 { 42 public static Object encode(Object object, Object encoding) throws Exception 43 { 44 if (object != null) 45 { 46 byte[] b = null; 47 48 if (object instanceof byte[]) 49 { 50 b = (byte[])object; 51 } 52 else 53 { 54 b = object.toString().getBytes(encoding.toString()); 55 } 56 57 object = StringUtil.encodeBase64(b); 58 } 59 60 return object; 61 } 62 63 public static Object encode(Object object) throws Exception 64 { 65 return encode(object, "iso-8859-1"); 66 } 67 68 public static Object decode(Object object, Object encoding) throws Exception 69 { 70 if (object != null) 71 { 72 byte[] b = StringUtil.decodeBase64(object.toString()); 73 74 if (encoding == null) 75 { 76 object = b; 77 } 78 else 79 { 80 object = new String (b, encoding.toString()); 81 } 82 } 83 84 return object; 85 } 86 87 public static Object decode(Object object) throws Exception 88 { 89 return decode(object, "iso-8859-1"); 90 } 91 } 92 | Popular Tags |