KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gcc > rmi > iiop > SimpleObjectOutputStream


1 /*
2  * Copyright 2004 The Apache Software Foundation or its licensors, as
3  * applicable.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14  * implied.
15  *
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */

19 package gcc.rmi.iiop;
20
21 import gcc.*;
22 import gcc.util.*;
23 import java.io.*;
24
25 public class SimpleObjectOutputStream extends ObjectOutputStream
26 {
27     public static ObjectOutputStream getInstance()
28     {
29         return getInstance(CdrOutputStream.getInstance());
30     }
31
32     public static ObjectOutputStream getInstance(CdrOutputStream cdrOutput)
33     {
34         ObjectOutputStream output = null;
35         try
36         {
37             output = new SimpleObjectOutputStream();
38         }
39         catch( Exception ex )
40         {
41             throw new SystemException(ex);
42         }
43
44         output.init(cdrOutput);
45         return output;
46     }
47
48     // -----------------------------------------------------------------------
49
// private data
50
// -----------------------------------------------------------------------
51

52     // -----------------------------------------------------------------------
53
// public methods
54
// -----------------------------------------------------------------------
55

56     public SimpleObjectOutputStream() throws IOException
57     {
58         super();
59     }
60
61     public void $reset()
62     {
63         _cdrOutput.reset();
64     }
65
66     public void recycle()
67     {
68         $reset();
69     }
70
71     public void writeObject(ValueType type, Object value)
72     {
73         ObjectHelper h = type.helper;
74         if (h != null)
75         {
76             h.write(this, value);
77             return;
78         }
79         byte[] bytes = JavaObject.toByteArray(value);
80         if (bytes == null) bytes = ArrayUtil.EMPTY_BYTE_ARRAY;
81         _cdrOutput.write_octet_sequence(bytes);
82     }
83
84     // -----------------------------------------------------------------------
85
// protected methods
86
// -----------------------------------------------------------------------
87

88     protected void init(CdrOutputStream cdrOutput)
89     {
90         super.init(cdrOutput);
91     }
92 }
93
Popular Tags