KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > encoding > WrapperInputStream


1 /*
2  * @(#)WrapperInputStream.java 1.7 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.corba.se.impl.encoding;
9
10 import java.util.HashMap JavaDoc;
11 import java.util.Map JavaDoc;
12 import java.util.Iterator JavaDoc;
13 import java.util.List JavaDoc;
14 import java.util.Collections JavaDoc;
15 import java.util.ArrayList JavaDoc;
16 import java.io.IOException JavaDoc;
17 import java.io.PrintStream JavaDoc;
18 import java.io.ByteArrayOutputStream JavaDoc;
19 import java.math.BigDecimal JavaDoc;
20 import java.math.BigInteger JavaDoc;
21
22 import org.omg.CORBA.TypeCode JavaDoc ;
23 import org.omg.CORBA.StructMember JavaDoc ;
24 import org.omg.CORBA.UnionMember JavaDoc ;
25 import org.omg.CORBA.ValueMember JavaDoc ;
26 import org.omg.CORBA.TCKind JavaDoc ;
27 import org.omg.CORBA.Any JavaDoc ;
28 import org.omg.CORBA.Principal JavaDoc ;
29 import org.omg.CORBA.BAD_TYPECODE JavaDoc ;
30 import org.omg.CORBA.BAD_PARAM JavaDoc ;
31 import org.omg.CORBA.BAD_OPERATION JavaDoc ;
32 import org.omg.CORBA.INTERNAL JavaDoc ;
33 import org.omg.CORBA.MARSHAL JavaDoc ;
34
35 import org.omg.CORBA.TypeCodePackage.BadKind JavaDoc ;
36
37 import org.omg.CORBA_2_3.portable.InputStream JavaDoc;
38 import org.omg.CORBA_2_3.portable.OutputStream JavaDoc;
39
40 import com.sun.corba.se.spi.ior.iiop.GIOPVersion;
41 import com.sun.corba.se.impl.corba.TypeCodeImpl;
42 import com.sun.corba.se.spi.orb.ORB;
43 import com.sun.corba.se.impl.encoding.OSFCodeSetRegistry;
44 import com.sun.corba.se.impl.encoding.MarshalInputStream;
45 import com.sun.corba.se.impl.encoding.CodeSetConversion;
46 import com.sun.corba.se.impl.encoding.CDRInputStream;
47 import com.sun.corba.se.impl.encoding.CDROutputStream;
48
49 public class WrapperInputStream extends org.omg.CORBA_2_3.portable.InputStream JavaDoc implements TypeCodeReader
50 {
51     private CDRInputStream stream;
52     private Map JavaDoc typeMap = null;
53     private int startPos = 0;
54
55     public WrapperInputStream(CDRInputStream s) {
56         super();
57         stream = s;
58         startPos = stream.getPosition();
59     }
60
61     public int read() throws IOException JavaDoc { return stream.read(); }
62     public int read(byte b[]) throws IOException JavaDoc { return stream.read(b); }
63     public int read(byte b[], int off, int len) throws IOException JavaDoc {
64     return stream.read(b, off, len);
65     }
66     public long skip(long n) throws IOException JavaDoc { return stream.skip(n); }
67     public int available() throws IOException JavaDoc { return stream.available(); }
68     public void close() throws IOException JavaDoc { stream.close(); }
69     public void mark(int readlimit) { stream.mark(readlimit); }
70     public void reset() { stream.reset(); }
71     public boolean markSupported() { return stream.markSupported(); }
72     public int getPosition() { return stream.getPosition(); }
73     public void consumeEndian() { stream.consumeEndian(); }
74     public boolean read_boolean() { return stream.read_boolean(); }
75     public char read_char() { return stream.read_char(); }
76     public char read_wchar() { return stream.read_wchar(); }
77     public byte read_octet() { return stream.read_octet(); }
78     public short read_short() { return stream.read_short(); }
79     public short read_ushort() { return stream.read_ushort(); }
80     public int read_long() { return stream.read_long(); }
81     public int read_ulong() { return stream.read_ulong(); }
82     public long read_longlong() { return stream.read_longlong(); }
83     public long read_ulonglong() { return stream.read_ulonglong(); }
84     public float read_float() { return stream.read_float(); }
85     public double read_double() { return stream.read_double(); }
86     public String JavaDoc read_string() { return stream.read_string(); }
87     public String JavaDoc read_wstring() { return stream.read_wstring(); }
88
89     public void read_boolean_array(boolean[] value, int offset, int length) {
90     stream.read_boolean_array(value, offset, length);
91     }
92     public void read_char_array(char[] value, int offset, int length) {
93     stream.read_char_array(value, offset, length);
94     }
95     public void read_wchar_array(char[] value, int offset, int length) {
96     stream.read_wchar_array(value, offset, length);
97     }
98     public void read_octet_array(byte[] value, int offset, int length) {
99     stream.read_octet_array(value, offset, length);
100     }
101     public void read_short_array(short[] value, int offset, int length) {
102     stream.read_short_array(value, offset, length);
103     }
104     public void read_ushort_array(short[] value, int offset, int length) {
105     stream.read_ushort_array(value, offset, length);
106     }
107     public void read_long_array(int[] value, int offset, int length) {
108     stream.read_long_array(value, offset, length);
109     }
110     public void read_ulong_array(int[] value, int offset, int length) {
111     stream.read_ulong_array(value, offset, length);
112     }
113     public void read_longlong_array(long[] value, int offset, int length) {
114     stream.read_longlong_array(value, offset, length);
115     }
116     public void read_ulonglong_array(long[] value, int offset, int length) {
117     stream.read_ulonglong_array(value, offset, length);
118     }
119     public void read_float_array(float[] value, int offset, int length) {
120     stream.read_float_array(value, offset, length);
121     }
122     public void read_double_array(double[] value, int offset, int length) {
123     stream.read_double_array(value, offset, length);
124     }
125
126     public org.omg.CORBA.Object JavaDoc read_Object() { return stream.read_Object(); }
127     public java.io.Serializable JavaDoc read_value() {return stream.read_value();}
128     public TypeCode JavaDoc read_TypeCode() { return stream.read_TypeCode(); }
129     public Any JavaDoc read_any() { return stream.read_any(); }
130     public Principal JavaDoc read_Principal() { return stream.read_Principal(); }
131     public java.math.BigDecimal JavaDoc read_fixed() { return stream.read_fixed(); }
132     public org.omg.CORBA.Context JavaDoc read_Context() { return stream.read_Context(); }
133
134     public org.omg.CORBA.ORB JavaDoc orb() { return stream.orb(); }
135
136     public void addTypeCodeAtPosition(TypeCodeImpl tc, int position) {
137         if (typeMap == null) {
138             //if (TypeCodeImpl.debug) System.out.println("Creating typeMap");
139
typeMap = new HashMap JavaDoc(16);
140         }
141         //if (TypeCodeImpl.debug) System.out.println(this + " adding tc " + tc + " at position " + position);
142
typeMap.put(new Integer JavaDoc(position), tc);
143     }
144
145     public TypeCodeImpl getTypeCodeAtPosition(int position) {
146         if (typeMap == null)
147         return null;
148         //if (TypeCodeImpl.debug) System.out.println("Getting tc " + (TypeCodeImpl)typeMap.get(new Integer(position)) +
149
//" at position " + position);
150
return (TypeCodeImpl)typeMap.get(new Integer JavaDoc(position));
151     }
152
153     public void setEnclosingInputStream(InputStream JavaDoc enclosure) {
154         // WrapperInputStream has no enclosure
155
}
156
157     public TypeCodeReader getTopLevelStream() {
158         // WrapperInputStream has no enclosure
159
return this;
160     }
161
162     public int getTopLevelPosition() {
163         //if (TypeCodeImpl.debug) System.out.println("WrapperInputStream.getTopLevelPosition " +
164
//"returning getPosition " + getPosition() + " - startPos " + startPos +
165
//" = " + (getPosition() - startPos));
166
return getPosition() - startPos;
167     }
168
169     public void performORBVersionSpecificInit() {
170         // This is never actually called on a WrapperInputStream, but
171
// exists to satisfy the interface requirement.
172
stream.performORBVersionSpecificInit();
173     }
174
175     public void resetCodeSetConverters() {
176         stream.resetCodeSetConverters();
177     }
178
179     //public void printBuffer() { stream.printBuffer(); }
180

181     public void printTypeMap() {
182         System.out.println("typeMap = {");
183         List JavaDoc sortedKeys = new ArrayList JavaDoc(typeMap.keySet());
184         Collections.sort(sortedKeys);
185         Iterator JavaDoc i = sortedKeys.iterator();
186         while (i.hasNext()) {
187             Integer JavaDoc pos = (Integer JavaDoc)i.next();
188             TypeCodeImpl tci = (TypeCodeImpl)typeMap.get(pos);
189             System.out.println(" key = " + pos.intValue() + ", value = " + tci.description());
190         }
191         System.out.println("}");
192     }
193 }
194
Popular Tags