1 18 package org.apache.geronimo.interop.util; 19 20 import java.io.ByteArrayInputStream ; 21 import java.io.ByteArrayOutputStream ; 22 import java.io.ObjectInputStream ; 23 import java.io.ObjectOutputStream ; 24 25 import org.apache.geronimo.interop.SystemException; 26 27 28 public abstract class JavaObject { 29 public static byte[] toByteArray(Object object) { 30 if (object == null) { 31 return null; 32 } 33 try { 34 ByteArrayOutputStream bs = new ByteArrayOutputStream (); 35 ObjectOutputStream os = new ObjectOutputStream (bs); 36 os.writeObject(object); 37 os.writeByte((byte) '.'); 40 os.flush(); 41 byte[] buffer = bs.toByteArray(); 42 os.close(); 43 bs.close(); 44 return buffer; 45 } catch (Exception ex) { 46 throw new SystemException("JavaObject.toByteArray", ex); 47 } 48 } 49 50 public static java.lang.Object fromByteArray(byte[] buffer) { 51 if (buffer == null) { 52 return null; 53 } 54 try { 55 ByteArrayInputStream bs = new ByteArrayInputStream (buffer); 56 ObjectInputStream is = new ObjectInputStream (bs); 57 Object object = is.readObject(); 58 is.close(); 59 bs.close(); 60 return object; 61 } catch (Exception ex) { 62 throw new SystemException("JavaObject.fromByteArray", ex); 63 } 64 } 65 } 66 | Popular Tags |