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