ws-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Elvio Fernandez <elvio.fernan...@gmail.com>
Subject Re: How do you convert a base64 object to original object?
Date Fri, 04 Nov 2005 03:37:22 GMT
I have the same problem Rudi. Instead of your code I try something more
naive like this:

Base64.encodeBase64("bla, bla".getBytes());

but does not work. :)

Heeeeeeeeellllppp!!!

Elvis



2005/11/3, Starsscream Desepticon <kastanienreis@yahoo.co.uk>:
>
> Hi
>
> I serialize objects and then encode them using base64, which the server
> returns to the client. The
> client receives a byte array object, but I cannot decode it using
> org.apache.commons.codec.binary.Base64. When I do Base64.decodeBase64() it
> says res is not a byte
> array. However the code below says the object is a byte array. How do you
> convert res to the
> original object (in my case it's a object implementing SecretKey)?
>
> Thanks, Rudi
>
> Object res = xmlrpcclient.execute("method", params);
> Class clazz = res.getClass();
> if (clazz.isArray() && clazz.getComponentType().equals(byte.class)) {
> System.out.println("TRUE"); // res is a base64 encoded array
> }
>
>
> Code for serializing and encoding:
>
> public static byte[] encode(Object obj) {
> try {
> ByteArrayOutputStream baos = new ByteArrayOutputStream();
> ObjectOutputStream oos = new ObjectOutputStream(baos);
> oos.writeObject(obj);
> oos.close();
> byte[] bytearray = baos.toByteArray();
> return Base64.encodeBase64(bytearray);
> } catch (IOException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> return null;
> }
>
> public static Object decode(byte[] encoded) {
> try {
> byte[] decoded = Base64.decodeBase64(encoded);
> ByteArrayInputStream bais = new ByteArrayInputStream(decoded);
> ObjectInputStream ois = new ObjectInputStream(bais);
> return ois.readObject();
> } catch (IOException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> } catch (ClassNotFoundException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> return null;
> }
>
>
>
>
> ___________________________________________________________
> How much free photo storage do you get? Store your holiday
> snaps for FREE with Yahoo! Photos http://uk.photos.yahoo.com
>

Mime
View raw message