KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > interop > rmi > iiop > SimpleObjectInputStream


1 /**
2  *
3  * Copyright 2004-2005 The Apache Software Foundation
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 implied.
14  *
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.geronimo.interop.rmi.iiop;
19
20 import java.io.IOException JavaDoc;
21
22 import org.apache.geronimo.interop.util.JavaObject;
23
24 public class SimpleObjectInputStream extends ObjectInputStream
25 {
26     public static ObjectInputStream getInstance()
27     {
28         ObjectInputStream ois = null;
29         try {
30             ois = new SimpleObjectInputStream();
31         } catch (IOException JavaDoc e) {
32             e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
33
}
34         return ois;
35     }
36
37     public static ObjectInputStream getInstance(byte[] bytes)
38     {
39         return getInstance(CdrInputStream.getInstance(bytes));
40     }
41
42     public static ObjectInputStream getInstance(org.apache.geronimo.interop.rmi.iiop.CdrInputStream cdrInput)
43     {
44         ObjectInputStream input = getInstance();
45         input.init(cdrInput);
46         return input;
47     }
48
49     public static ObjectInputStream getPooledInstance()
50     {
51         ObjectInputStream input = null;
52         if (input == null)
53         {
54             input = getInstance();
55         }
56         return input;
57     }
58
59     // -----------------------------------------------------------------------
60
// private data
61
// -----------------------------------------------------------------------
62

63     // -----------------------------------------------------------------------
64
// public methods
65
// -----------------------------------------------------------------------
66

67     public SimpleObjectInputStream() throws IOException JavaDoc
68     {
69         super();
70     }
71
72     public void $reset()
73     {
74         _cdrInput.reset();
75     }
76
77     public void recycle()
78     {
79         $reset();
80     }
81
82     public Exception JavaDoc readException(ValueType type)
83     {
84         return (Exception JavaDoc)readObject(type);
85     }
86
87     public Object JavaDoc readObject(ValueType type)
88     {
89         ObjectHelper h = type.helper;
90         if (h != null)
91         {
92             return h.read(this);
93         }
94         byte[] bytes = _cdrInput.read_octet_sequence();
95         Object JavaDoc value = bytes.length == 0 ? null : JavaObject.fromByteArray(bytes);
96         return value;
97     }
98
99     // -----------------------------------------------------------------------
100
// protected methods
101
// -----------------------------------------------------------------------
102

103     protected void init(org.apache.geronimo.interop.rmi.iiop.CdrInputStream cdrInput)
104     {
105         super.init(cdrInput);
106     }
107 }
108
Popular Tags