1. /*
  2. * @(#)JavaStreamObjectCopierImpl.java 1.2 04/07/27
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.corba.se.impl.copyobject ;
  8. import java.util.logging.Level;
  9. import java.util.logging.Logger;
  10. import java.io.Serializable;
  11. import java.rmi.Remote;
  12. import java.rmi.MarshalException;
  13. import java.io.InputStream ;
  14. import java.io.OutputStream ;
  15. import java.io.ByteArrayInputStream ;
  16. import java.io.ByteArrayOutputStream ;
  17. import java.io.ObjectInputStream ;
  18. import java.io.ObjectOutputStream ;
  19. import org.omg.CORBA.ORB ;
  20. import com.sun.corba.se.spi.copyobject.ObjectCopier ;
  21. import com.sun.corba.se.impl.util.Utility;
  22. public class JavaStreamObjectCopierImpl implements ObjectCopier {
  23. public JavaStreamObjectCopierImpl( ORB orb )
  24. {
  25. this.orb = orb ;
  26. }
  27. public Object copy(Object obj) {
  28. if (obj instanceof Remote) {
  29. // Yes, so make sure it is connected and converted
  30. // to a stub (if needed)...
  31. return Utility.autoConnect(obj,orb,true);
  32. }
  33. try {
  34. ByteArrayOutputStream os = new ByteArrayOutputStream( 10000 ) ;
  35. ObjectOutputStream oos = new ObjectOutputStream( os ) ;
  36. oos.writeObject( obj ) ;
  37. byte[] arr = os.toByteArray() ;
  38. InputStream is = new ByteArrayInputStream( arr ) ;
  39. ObjectInputStream ois = new ObjectInputStream( is ) ;
  40. return ois.readObject();
  41. } catch (Exception exc) {
  42. System.out.println( "Failed with exception:" + exc ) ;
  43. return null ;
  44. }
  45. }
  46. private ORB orb;
  47. }