|
SOAP on a ROPE, by Wyn Easton
WSJ Vol 02 Issue 01 - pg.30
Listing 1
public byte[] ObjectToArray(Object obj) throws
Exception
{
ObjectOutputStream oos = null;
try
{
ByteArrayOutputStream bos = new ByteArrayOutputStream();
oos = new
ObjectOutputStream(bos);
// serialize
the object passed in
oos.writeObject(obj);
oos.flush();
return
bos.toByteArray();
}
catch (Exception e)
{
System.out.println("Exception in ObjToArray = " + e);
throw(e);
}
finally
{
oos.close();
}
}
Listing 2
try
{
ByteArrayInputStream bin = new
ByteArrayInputStream(Base64.decode(value));
ois = new
ObjectInputStream(bin); // Create an Object Input Stream
// return the
new object
Object object
= (Object)ois.readObject();
return new
Bean(Object.class, object);
}
catch (ClassNotFoundException cnfe)
{
System.out.println("Class Not Found Exception in unmarshall = " +
cnfe);
// this is
where I was getting the class file originally
}
|