1 18 package org.apache.geronimo.interop.rmi.iiop; 19 20 import java.io.IOException ; 21 22 import org.apache.geronimo.interop.util.ArrayUtil; 23 import org.apache.geronimo.interop.util.JavaObject; 24 25 public class SimpleObjectOutputStream extends ObjectOutputStream 26 { 27 public static ObjectOutputStream getInstance() 28 { 29 ObjectOutputStream oos = null; 30 try { 31 oos = new SimpleObjectOutputStream(); 32 } catch (IOException e) { 33 e.printStackTrace(); } 35 return oos; 36 } 37 38 public static ObjectOutputStream getInstance(CdrOutputStream cdrOutput) 39 { 40 ObjectOutputStream output = getInstance(); 41 output.init(cdrOutput); 42 return output; 43 } 44 45 public static ObjectOutputStream getPooledInstance() 46 { 47 ObjectOutputStream output = null; 48 if (output == null) 49 { 50 output = getInstance(); 51 } 52 return output; 53 } 54 55 59 63 public SimpleObjectOutputStream() throws IOException 64 { 65 super(); 66 } 67 68 public void $reset() 69 { 70 _cdrOutput.reset(); 71 } 72 73 public void recycle() 74 { 75 $reset(); 76 } 77 78 public void writeException(ValueType type, Exception value) 79 { 80 String repositoryID = "IDL:" + type._class.getName().replace('.', '/') + ":1.0"; 81 _cdrOutput.write_string(repositoryID); 82 writeObject(type, value); 83 _hasException = true; 84 } 85 86 public void writeObject(ValueType type, Object value) 87 { 88 ObjectHelper h = type.helper; 89 if (h != null) 90 { 91 h.write(this, value); 92 return; 93 } 94 byte[] bytes = JavaObject.toByteArray(value); 95 if (bytes == null) bytes = ArrayUtil.EMPTY_BYTE_ARRAY; 96 _cdrOutput.write_octet_sequence(bytes); 97 } 98 99 103 protected void init(CdrOutputStream cdrOutput) 104 { 105 super.init(cdrOutput); 106 } 107 } 108 | Popular Tags |