1. /*
  2. * @(#)EncapsOutputStream.java 1.15 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 org.omg.CORBA.CompletionStatus;
  9. import com.sun.corba.se.spi.orb.ORB;
  10. import com.sun.corba.se.spi.ior.iiop.GIOPVersion;
  11. import com.sun.corba.se.impl.encoding.CodeSetConversion;
  12. import com.sun.corba.se.impl.encoding.OSFCodeSetRegistry;
  13. import com.sun.corba.se.impl.encoding.CDROutputStream;
  14. import com.sun.corba.se.impl.encoding.BufferManagerWrite;
  15. import com.sun.corba.se.impl.encoding.BufferManagerFactory;
  16. import com.sun.corba.se.impl.protocol.giopmsgheaders.Message;
  17. import com.sun.corba.se.impl.orbutil.ORBConstants;
  18. /**
  19. * Encapsulations are supposed to explicitly define their
  20. * code sets and GIOP version. The original resolution to issue 2784
  21. * said that the defaults were UTF-8 and UTF-16, but that was not
  22. * agreed upon.
  23. *
  24. * These streams currently use CDR 1.2 with ISO8859-1 for char/string and
  25. * UTF16 for wchar/wstring. If no byte order marker is available,
  26. * the endianness of the encapsulation is used.
  27. *
  28. * When more encapsulations arise that have their own special code
  29. * sets defined, we can make all constructors take such parameters.
  30. */
  31. public class EncapsOutputStream extends CDROutputStream
  32. {
  33. // REVISIT - Right now, EncapsOutputStream's do not use
  34. // pooled byte buffers. This is controlled by the following
  35. // static constant. This should be re-factored such that
  36. // the EncapsOutputStream doesn't know it's using pooled
  37. // byte buffers.
  38. final static boolean usePooledByteBuffers = false;
  39. // REVISIT - Right now, valuetypes in encapsulations will
  40. // only use stream format version 1, which may create problems
  41. // for service contexts or codecs (?).
  42. // corba/ORB
  43. // corba/ORBSingleton
  44. // iiop/ORB
  45. // iiop/GIOPImpl
  46. // corba/AnyImpl
  47. public EncapsOutputStream(ORB orb) {
  48. // GIOP version 1.2 with no fragmentation, big endian,
  49. // UTF8 for char data and UTF-16 for wide char data;
  50. this(orb, GIOPVersion.V1_2);
  51. }
  52. // CDREncapsCodec
  53. //
  54. // REVISIT. A UTF-16 encoding with GIOP 1.1 will not work
  55. // with byte order markers.
  56. public EncapsOutputStream(ORB orb, GIOPVersion version) {
  57. this(orb, version, false);
  58. }
  59. // Used by IIOPProfileTemplate
  60. //
  61. public EncapsOutputStream(ORB orb, boolean isLittleEndian) {
  62. this(orb, GIOPVersion.V1_2, isLittleEndian);
  63. }
  64. public EncapsOutputStream(ORB orb,
  65. GIOPVersion version,
  66. boolean isLittleEndian)
  67. {
  68. super(orb, version, Message.CDR_ENC_VERSION, isLittleEndian,
  69. BufferManagerFactory.newBufferManagerWrite(
  70. BufferManagerFactory.GROW,
  71. Message.CDR_ENC_VERSION,
  72. orb),
  73. ORBConstants.STREAM_FORMAT_VERSION_1,
  74. usePooledByteBuffers);
  75. }
  76. public org.omg.CORBA.portable.InputStream create_input_stream() {
  77. freeInternalCaches();
  78. return new EncapsInputStream(orb(),
  79. getByteBuffer(),
  80. getSize(),
  81. isLittleEndian(),
  82. getGIOPVersion());
  83. }
  84. protected CodeSetConversion.CTBConverter createCharCTBConverter() {
  85. return CodeSetConversion.impl().getCTBConverter(OSFCodeSetRegistry.ISO_8859_1);
  86. }
  87. protected CodeSetConversion.CTBConverter createWCharCTBConverter() {
  88. if (getGIOPVersion().equals(GIOPVersion.V1_0))
  89. throw wrapper.wcharDataInGiop10(CompletionStatus.COMPLETED_MAYBE);
  90. // In the case of GIOP 1.1, we take the byte order of the stream and don't
  91. // use byte order markers since we're limited to a 2 byte fixed width encoding.
  92. if (getGIOPVersion().equals(GIOPVersion.V1_1))
  93. return CodeSetConversion.impl().getCTBConverter(OSFCodeSetRegistry.UTF_16,
  94. isLittleEndian(),
  95. false);
  96. // Assume anything else meets GIOP 1.2 requirements
  97. //
  98. // Use byte order markers? If not, use big endian in GIOP 1.2.
  99. // (formal 00-11-03 15.3.16)
  100. boolean useBOM = ((ORB)orb()).getORBData().useByteOrderMarkersInEncapsulations();
  101. return CodeSetConversion.impl().getCTBConverter(OSFCodeSetRegistry.UTF_16,
  102. false,
  103. useBOM);
  104. }
  105. }