1 7 8 package com.sun.corba.se.impl.copyobject ; 9 10 import java.util.logging.Level ; 11 import java.util.logging.Logger ; 12 13 import java.io.Serializable ; 14 import java.rmi.Remote ; 15 import java.rmi.MarshalException ; 16 17 import java.io.InputStream ; 18 import java.io.OutputStream ; 19 import java.io.ByteArrayInputStream ; 20 import java.io.ByteArrayOutputStream ; 21 import java.io.ObjectInputStream ; 22 import java.io.ObjectOutputStream ; 23 24 import org.omg.CORBA.ORB ; 25 26 import com.sun.corba.se.spi.copyobject.ObjectCopier ; 27 import com.sun.corba.se.impl.util.Utility; 28 29 public class JavaStreamObjectCopierImpl implements ObjectCopier { 30 31 public JavaStreamObjectCopierImpl( ORB orb ) 32 { 33 this.orb = orb ; 34 } 35 36 public Object copy(Object obj) { 37 if (obj instanceof Remote ) { 38 return Utility.autoConnect(obj,orb,true); 41 } 42 43 try { 44 ByteArrayOutputStream os = new ByteArrayOutputStream ( 10000 ) ; 45 ObjectOutputStream oos = new ObjectOutputStream ( os ) ; 46 oos.writeObject( obj ) ; 47 48 byte[] arr = os.toByteArray() ; 49 InputStream is = new ByteArrayInputStream ( arr ) ; 50 ObjectInputStream ois = new ObjectInputStream ( is ) ; 51 52 return ois.readObject(); 53 } catch (Exception exc) { 54 System.out.println( "Failed with exception:" + exc ) ; 55 return null ; 56 } 57 } 58 59 private ORB orb; 60 } 61 | Popular Tags |