KickJava   Java API By Example, From Geeks To Geeks.

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


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 SimpleObjectInputStream extends ObjectInputStream
26 {
27     public static ObjectInputStream getInstance()
28     {
29         return getInstance(CdrInputStream.getInstance());
30     }
31
32     public static ObjectInputStream getInstance(byte[] bytes)
33     {
34         return getInstance(CdrInputStream.getInstance(bytes));
35     }
36
37     public static ObjectInputStream getInstance(gcc.rmi.iiop.CdrInputStream cdrInput)
38     {
39         ObjectInputStream input = null;
40         try
41         {
42             input = new SimpleObjectInputStream();
43         }
44         catch( Exception ex )
45         {
46             throw new SystemException(ex);
47         }
48
49         input.init(cdrInput);
50         return input;
51     }
52
53     // -----------------------------------------------------------------------
54
// private data
55
// -----------------------------------------------------------------------
56

57     // -----------------------------------------------------------------------
58
// public methods
59
// -----------------------------------------------------------------------
60

61     public SimpleObjectInputStream() throws IOException
62     {
63         super();
64     }
65
66     public void $reset()
67     {
68         _cdrInput.reset();
69     }
70
71     public void recycle()
72     {
73         $reset();
74     }
75
76     public Object readObject(ValueType type)
77     {
78         ObjectHelper h = type.helper;
79         if (h != null)
80         {
81             return h.read(this);
82         }
83         byte[] bytes = _cdrInput.read_octet_sequence();
84         Object value = bytes.length == 0 ? null : JavaObject.fromByteArray(bytes);
85         return value;
86     }
87
88     // -----------------------------------------------------------------------
89
// protected methods
90
// -----------------------------------------------------------------------
91

92     protected void init(gcc.rmi.iiop.CdrInputStream cdrInput)
93     {
94         super.init(cdrInput);
95     }
96 }
97
Popular Tags