1/* 2 * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26package com.sun.corba.se.impl.encoding; 27 28import java.util.HashMap; 29import java.util.Map; 30import java.util.Iterator; 31import java.util.List; 32import java.util.Collections; 33import java.util.ArrayList; 34import java.io.IOException; 35import java.io.PrintStream; 36import java.io.ByteArrayOutputStream; 37import java.math.BigDecimal; 38import java.math.BigInteger; 39 40import org.omg.CORBA.TypeCode ; 41import org.omg.CORBA.StructMember ; 42import org.omg.CORBA.UnionMember ; 43import org.omg.CORBA.ValueMember ; 44import org.omg.CORBA.TCKind ; 45import org.omg.CORBA.Any ; 46import org.omg.CORBA.Principal ; 47import org.omg.CORBA.BAD_TYPECODE ; 48import org.omg.CORBA.BAD_PARAM ; 49import org.omg.CORBA.BAD_OPERATION ; 50import org.omg.CORBA.INTERNAL ; 51import org.omg.CORBA.MARSHAL ; 52 53import org.omg.CORBA.TypeCodePackage.BadKind ; 54 55import org.omg.CORBA_2_3.portable.InputStream; 56import org.omg.CORBA_2_3.portable.OutputStream; 57 58import com.sun.corba.se.spi.ior.iiop.GIOPVersion; 59import com.sun.corba.se.impl.corba.TypeCodeImpl; 60import com.sun.corba.se.spi.orb.ORB; 61import com.sun.corba.se.impl.encoding.OSFCodeSetRegistry; 62import com.sun.corba.se.impl.encoding.MarshalInputStream; 63import com.sun.corba.se.impl.encoding.CodeSetConversion; 64import com.sun.corba.se.impl.encoding.CDRInputStream; 65import com.sun.corba.se.impl.encoding.CDROutputStream; 66 67public class WrapperInputStream extends org.omg.CORBA_2_3.portable.InputStream implements TypeCodeReader 68{ 69 private CDRInputStream stream; 70 private Map typeMap = null; 71 private int startPos = 0; 72 73 public WrapperInputStream(CDRInputStream s) { 74 super(); 75 stream = s; 76 startPos = stream.getPosition(); 77 } 78 79 public int read() throws IOException { return stream.read(); } 80 public int read(byte b[]) throws IOException { return stream.read(b); } 81 public int read(byte b[], int off, int len) throws IOException { 82 return stream.read(b, off, len); 83 } 84 public long skip(long n) throws IOException { return stream.skip(n); } 85 public int available() throws IOException { return stream.available(); } 86 public void close() throws IOException { stream.close(); } 87 public void mark(int readlimit) { stream.mark(readlimit); } 88 public void reset() { stream.reset(); } 89 public boolean markSupported() { return stream.markSupported(); } 90 public int getPosition() { return stream.getPosition(); } 91 public void consumeEndian() { stream.consumeEndian(); } 92 public boolean read_boolean() { return stream.read_boolean(); } 93 public char read_char() { return stream.read_char(); } 94 public char read_wchar() { return stream.read_wchar(); } 95 public byte read_octet() { return stream.read_octet(); } 96 public short read_short() { return stream.read_short(); } 97 public short read_ushort() { return stream.read_ushort(); } 98 public int read_long() { return stream.read_long(); } 99 public int read_ulong() { return stream.read_ulong(); } 100 public long read_longlong() { return stream.read_longlong(); } 101 public long read_ulonglong() { return stream.read_ulonglong(); } 102 public float read_float() { return stream.read_float(); } 103 public double read_double() { return stream.read_double(); } 104 public String read_string() { return stream.read_string(); } 105 public String read_wstring() { return stream.read_wstring(); } 106 107 public void read_boolean_array(boolean[] value, int offset, int length) { 108 stream.read_boolean_array(value, offset, length); 109 } 110 public void read_char_array(char[] value, int offset, int length) { 111 stream.read_char_array(value, offset, length); 112 } 113 public void read_wchar_array(char[] value, int offset, int length) { 114 stream.read_wchar_array(value, offset, length); 115 } 116 public void read_octet_array(byte[] value, int offset, int length) { 117 stream.read_octet_array(value, offset, length); 118 } 119 public void read_short_array(short[] value, int offset, int length) { 120 stream.read_short_array(value, offset, length); 121 } 122 public void read_ushort_array(short[] value, int offset, int length) { 123 stream.read_ushort_array(value, offset, length); 124 } 125 public void read_long_array(int[] value, int offset, int length) { 126 stream.read_long_array(value, offset, length); 127 } 128 public void read_ulong_array(int[] value, int offset, int length) { 129 stream.read_ulong_array(value, offset, length); 130 } 131 public void read_longlong_array(long[] value, int offset, int length) { 132 stream.read_longlong_array(value, offset, length); 133 } 134 public void read_ulonglong_array(long[] value, int offset, int length) { 135 stream.read_ulonglong_array(value, offset, length); 136 } 137 public void read_float_array(float[] value, int offset, int length) { 138 stream.read_float_array(value, offset, length); 139 } 140 public void read_double_array(double[] value, int offset, int length) { 141 stream.read_double_array(value, offset, length); 142 } 143 144 public org.omg.CORBA.Object read_Object() { return stream.read_Object(); } 145 public java.io.Serializable read_value() {return stream.read_value();} 146 public TypeCode read_TypeCode() { return stream.read_TypeCode(); } 147 public Any read_any() { return stream.read_any(); } 148 public Principal read_Principal() { return stream.read_Principal(); } 149 public java.math.BigDecimal read_fixed() { return stream.read_fixed(); } 150 public org.omg.CORBA.Context read_Context() { return stream.read_Context(); } 151 152 public org.omg.CORBA.ORB orb() { return stream.orb(); } 153 154 public void addTypeCodeAtPosition(TypeCodeImpl tc, int position) { 155 if (typeMap == null) { 156 //if (TypeCodeImpl.debug) System.out.println("Creating typeMap"); 157 typeMap = new HashMap(16); 158 } 159 //if (TypeCodeImpl.debug) System.out.println(this + " adding tc " + tc + " at position " + position); 160 typeMap.put(new Integer(position), tc); 161 } 162 163 public TypeCodeImpl getTypeCodeAtPosition(int position) { 164 if (typeMap == null) 165 return null; 166 //if (TypeCodeImpl.debug) System.out.println("Getting tc " + (TypeCodeImpl)typeMap.get(new Integer(position)) + 167 //" at position " + position); 168 return (TypeCodeImpl)typeMap.get(new Integer(position)); 169 } 170 171 public void setEnclosingInputStream(InputStream enclosure) { 172 // WrapperInputStream has no enclosure 173 } 174 175 public TypeCodeReader getTopLevelStream() { 176 // WrapperInputStream has no enclosure 177 return this; 178 } 179 180 public int getTopLevelPosition() { 181 //if (TypeCodeImpl.debug) System.out.println("WrapperInputStream.getTopLevelPosition " + 182 //"returning getPosition " + getPosition() + " - startPos " + startPos + 183 //" = " + (getPosition() - startPos)); 184 return getPosition() - startPos; 185 } 186 187 public void performORBVersionSpecificInit() { 188 // This is never actually called on a WrapperInputStream, but 189 // exists to satisfy the interface requirement. 190 stream.performORBVersionSpecificInit(); 191 } 192 193 public void resetCodeSetConverters() { 194 stream.resetCodeSetConverters(); 195 } 196 197 //public void printBuffer() { stream.printBuffer(); } 198 199 public void printTypeMap() { 200 System.out.println("typeMap = {"); 201 List sortedKeys = new ArrayList(typeMap.keySet()); 202 Collections.sort(sortedKeys); 203 Iterator i = sortedKeys.iterator(); 204 while (i.hasNext()) { 205 Integer pos = (Integer)i.next(); 206 TypeCodeImpl tci = (TypeCodeImpl)typeMap.get(pos); 207 System.out.println(" key = " + pos.intValue() + ", value = " + tci.description()); 208 } 209 System.out.println("}"); 210 } 211} 212