1 package org.apache.ojb.otm.copy; 2 3 17 18 import java.io.*; 19 import org.apache.ojb.broker.PersistenceBroker; 20 21 27 public final class SerializeObjectCopyStrategy implements ObjectCopyStrategy 28 { 29 34 public Object copy(final Object obj, PersistenceBroker broker) 35 throws ObjectCopyException 36 { 37 ObjectOutputStream oos = null; 38 ObjectInputStream ois = null; 39 try 40 { 41 final ByteArrayOutputStream bos = new ByteArrayOutputStream(); 42 oos = new ObjectOutputStream(bos); 43 oos.writeObject(obj); 45 oos.flush(); 46 final ByteArrayInputStream bin = 47 new ByteArrayInputStream(bos.toByteArray()); 48 ois = new ObjectInputStream(bin); 49 return ois.readObject(); 51 } 52 catch (Exception e) 53 { 54 throw new ObjectCopyException(e); 55 } 56 finally 57 { 58 try 59 { 60 if (oos != null) 61 { 62 oos.close(); 63 } 64 if (ois != null) 65 { 66 ois.close(); 67 } 68 } 69 catch (IOException ioe) 70 { 71 } 73 } 74 } 75 } 76 | Popular Tags |