1. /*
  2. * @(#)EncapsInputStream.java 1.11 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.corba.se.internal.corba;
  8. import org.omg.CORBA.ORB;
  9. import org.omg.CORBA.MARSHAL;
  10. import org.omg.CORBA.CompletionStatus;
  11. import com.sun.org.omg.SendingContext.CodeBase;
  12. import com.sun.corba.se.internal.core.*;
  13. import com.sun.corba.se.internal.iiop.CDRInputStream;
  14. import com.sun.corba.se.internal.orbutil.MinorCodes;
  15. /**
  16. * Encapsulations are supposed to explicitly define their
  17. * code sets and GIOP version. The original resolution to issue 2784
  18. * said that the defaults were UTF-8 and UTF-16, but that was not
  19. * agreed upon.
  20. *
  21. * These streams currently use CDR 1.2 with ISO8859-1 for char/string and
  22. * UTF16 for wchar/wstring. If no byte order marker is available,
  23. * the endianness of the encapsulation is used.
  24. *
  25. * When more encapsulations arise that have their own special code
  26. * sets defined, we can make all constructors take such parameters.
  27. */
  28. public class EncapsInputStream extends CDRInputStream
  29. {
  30. // corba/EncapsOutputStream
  31. // corba/ORBSingleton
  32. // iiop/ORB
  33. public EncapsInputStream(ORB orb, byte[] buf, int size, boolean littleEndian) {
  34. // CDR 1.2 encoding UTF8/UTF16 (without a BOM) and grow strategy
  35. super(orb, buf, size, littleEndian, GIOPVersion.V1_2, false);
  36. performORBVersionSpecificInit();
  37. }
  38. // corba/ORBSingleton
  39. // iiop/ORB
  40. public EncapsInputStream(ORB orb) {
  41. super(orb, false, GIOPVersion.V1_2, false);
  42. performORBVersionSpecificInit();
  43. }
  44. // corba/AnyImpl
  45. public EncapsInputStream(EncapsInputStream eis) {
  46. super(eis);
  47. performORBVersionSpecificInit();
  48. }
  49. // corba/ORBSingleton
  50. // iiop/ORB
  51. public EncapsInputStream(ORB orb, byte[] data, int size) {
  52. super(orb, data, size, false, GIOPVersion.V1_2, false);
  53. performORBVersionSpecificInit();
  54. }
  55. // CDREncapsCodec
  56. public EncapsInputStream(ORB orb, byte[] data, int size, GIOPVersion version) {
  57. super(orb, data, size, false, version, false);
  58. performORBVersionSpecificInit();
  59. }
  60. /**
  61. * Full constructor with a CodeBase parameter useful for
  62. * unmarshaling RMI-IIOP valuetypes (technically against the
  63. * intention of an encapsulation, but necessary due to OMG
  64. * issue 4795. Used by ServiceContexts.
  65. */
  66. public EncapsInputStream(ORB orb,
  67. byte[] data,
  68. int size,
  69. GIOPVersion version,
  70. CodeBase codeBase) {
  71. super(orb, data, size, false, version, false);
  72. this.codeBase = codeBase;
  73. performORBVersionSpecificInit();
  74. }
  75. public CDRInputStream dup() {
  76. return new EncapsInputStream(this);
  77. }
  78. protected CodeSetConversion.BTCConverter createCharBTCConverter() {
  79. return CodeSetConversion.impl().getBTCConverter(OSFCodeSetRegistry.ISO_8859_1);
  80. }
  81. protected CodeSetConversion.BTCConverter createWCharBTCConverter() {
  82. // Wide characters don't exist in GIOP 1.0
  83. if (getGIOPVersion().equals(GIOPVersion.V1_0))
  84. throw new MARSHAL(MinorCodes.WCHAR_DATA_IN_GIOP_1_0,
  85. CompletionStatus.COMPLETED_MAYBE);
  86. // In GIOP 1.1, we shouldn't have byte order markers. Take the order
  87. // of the stream if we don't see them.
  88. if (getGIOPVersion().equals(GIOPVersion.V1_1))
  89. return CodeSetConversion.impl().getBTCConverter(OSFCodeSetRegistry.UTF_16,
  90. isLittleEndian());
  91. // Assume anything else adheres to GIOP 1.2 requirements.
  92. //
  93. // Our UTF_16 converter will work with byte order markers, and if
  94. // they aren't present, it will use the provided endianness.
  95. //
  96. // With no byte order marker, it's big endian in GIOP 1.2.
  97. // formal 00-11-03 15.3.16.
  98. return CodeSetConversion.impl().getBTCConverter(OSFCodeSetRegistry.UTF_16,
  99. false);
  100. }
  101. public CodeBase getCodeBase() {
  102. return codeBase;
  103. }
  104. private CodeBase codeBase;
  105. }