1. /*
  2. * @(#)EncapsInputStream.java 1.14 04/06/21
  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.nio.ByteBuffer;
  9. import org.omg.CORBA.CompletionStatus;
  10. import com.sun.org.omg.SendingContext.CodeBase;
  11. import com.sun.corba.se.spi.ior.iiop.GIOPVersion;
  12. import com.sun.corba.se.impl.encoding.CDRInputStream;
  13. import com.sun.corba.se.impl.encoding.BufferManagerFactory;
  14. import com.sun.corba.se.impl.encoding.CodeSetConversion;
  15. import com.sun.corba.se.impl.encoding.OSFCodeSetRegistry;
  16. import com.sun.corba.se.impl.protocol.giopmsgheaders.Message;
  17. import com.sun.corba.se.spi.orb.ORB;
  18. import com.sun.corba.se.spi.logging.CORBALogDomains;
  19. import com.sun.corba.se.impl.logging.ORBUtilSystemException;
  20. /**
  21. * Encapsulations are supposed to explicitly define their
  22. * code sets and GIOP version. The original resolution to issue 2784
  23. * said that the defaults were UTF-8 and UTF-16, but that was not
  24. * agreed upon.
  25. *
  26. * These streams currently use CDR 1.2 with ISO8859-1 for char/string and
  27. * UTF16 for wchar/wstring. If no byte order marker is available,
  28. * the endianness of the encapsulation is used.
  29. *
  30. * When more encapsulations arise that have their own special code
  31. * sets defined, we can make all constructors take such parameters.
  32. */
  33. public class EncapsInputStream extends CDRInputStream
  34. {
  35. private ORBUtilSystemException wrapper ;
  36. // corba/EncapsOutputStream
  37. // corba/ORBSingleton
  38. // iiop/ORB
  39. public EncapsInputStream(org.omg.CORBA.ORB orb, byte[] buf,
  40. int size, boolean littleEndian,
  41. GIOPVersion version) {
  42. super(orb, ByteBuffer.wrap(buf), size, littleEndian,
  43. version, Message.CDR_ENC_VERSION,
  44. BufferManagerFactory.newBufferManagerRead(
  45. BufferManagerFactory.GROW,
  46. Message.CDR_ENC_VERSION,
  47. (ORB)orb));
  48. wrapper = ORBUtilSystemException.get( (ORB)orb,
  49. CORBALogDomains.RPC_ENCODING ) ;
  50. performORBVersionSpecificInit();
  51. }
  52. public EncapsInputStream(org.omg.CORBA.ORB orb, ByteBuffer byteBuffer,
  53. int size, boolean littleEndian,
  54. GIOPVersion version) {
  55. super(orb, byteBuffer, size, littleEndian,
  56. version, Message.CDR_ENC_VERSION,
  57. BufferManagerFactory.newBufferManagerRead(
  58. BufferManagerFactory.GROW,
  59. Message.CDR_ENC_VERSION,
  60. (com.sun.corba.se.spi.orb.ORB)orb));
  61. performORBVersionSpecificInit();
  62. }
  63. // ior/IdentifiableBase
  64. // ior/IIOPProfile
  65. // corba/ORBSingleton
  66. // iiop/ORB
  67. public EncapsInputStream(org.omg.CORBA.ORB orb, byte[] data, int size)
  68. {
  69. this(orb, data, size, GIOPVersion.V1_2);
  70. }
  71. // corba/AnyImpl
  72. public EncapsInputStream(EncapsInputStream eis)
  73. {
  74. super(eis);
  75. wrapper = ORBUtilSystemException.get( (ORB)(eis.orb()),
  76. CORBALogDomains.RPC_ENCODING ) ;
  77. performORBVersionSpecificInit();
  78. }
  79. // CDREncapsCodec
  80. // ServiceContext
  81. //
  82. // Assumes big endian (can use consumeEndian to read and set
  83. // the endianness if it is an encapsulation with a byte order
  84. // mark at the beginning)
  85. public EncapsInputStream(org.omg.CORBA.ORB orb, byte[] data, int size, GIOPVersion version)
  86. {
  87. this(orb, data, size, false, version);
  88. }
  89. /**
  90. * Full constructor with a CodeBase parameter useful for
  91. * unmarshaling RMI-IIOP valuetypes (technically against the
  92. * intention of an encapsulation, but necessary due to OMG
  93. * issue 4795. Used by ServiceContexts.
  94. */
  95. public EncapsInputStream(org.omg.CORBA.ORB orb,
  96. byte[] data,
  97. int size,
  98. GIOPVersion version,
  99. CodeBase codeBase) {
  100. super(orb,
  101. ByteBuffer.wrap(data),
  102. size,
  103. false,
  104. version, Message.CDR_ENC_VERSION,
  105. BufferManagerFactory.newBufferManagerRead(
  106. BufferManagerFactory.GROW,
  107. Message.CDR_ENC_VERSION,
  108. (ORB)orb));
  109. this.codeBase = codeBase;
  110. performORBVersionSpecificInit();
  111. }
  112. public CDRInputStream dup() {
  113. return new EncapsInputStream(this);
  114. }
  115. protected CodeSetConversion.BTCConverter createCharBTCConverter() {
  116. return CodeSetConversion.impl().getBTCConverter(OSFCodeSetRegistry.ISO_8859_1);
  117. }
  118. protected CodeSetConversion.BTCConverter createWCharBTCConverter() {
  119. // Wide characters don't exist in GIOP 1.0
  120. if (getGIOPVersion().equals(GIOPVersion.V1_0))
  121. throw wrapper.wcharDataInGiop10( CompletionStatus.COMPLETED_MAYBE);
  122. // In GIOP 1.1, we shouldn't have byte order markers. Take the order
  123. // of the stream if we don't see them.
  124. if (getGIOPVersion().equals(GIOPVersion.V1_1))
  125. return CodeSetConversion.impl().getBTCConverter(OSFCodeSetRegistry.UTF_16,
  126. isLittleEndian());
  127. // Assume anything else adheres to GIOP 1.2 requirements.
  128. //
  129. // Our UTF_16 converter will work with byte order markers, and if
  130. // they aren't present, it will use the provided endianness.
  131. //
  132. // With no byte order marker, it's big endian in GIOP 1.2.
  133. // formal 00-11-03 15.3.16.
  134. return CodeSetConversion.impl().getBTCConverter(OSFCodeSetRegistry.UTF_16,
  135. false);
  136. }
  137. public CodeBase getCodeBase() {
  138. return codeBase;
  139. }
  140. private CodeBase codeBase;
  141. }