1. /*
  2. * @(#)EncapsOutputStream.java 1.12 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.corba.se.internal.core.*;
  12. import com.sun.corba.se.internal.iiop.CDROutputStream;
  13. import com.sun.corba.se.internal.orbutil.MinorCodes;
  14. /**
  15. * Encapsulations are supposed to explicitly define their
  16. * code sets and GIOP version. The original resolution to issue 2784
  17. * said that the defaults were UTF-8 and UTF-16, but that was not
  18. * agreed upon.
  19. *
  20. * These streams currently use CDR 1.2 with ISO8859-1 for char/string and
  21. * UTF16 for wchar/wstring. If no byte order marker is available,
  22. * the endianness of the encapsulation is used.
  23. *
  24. * When more encapsulations arise that have their own special code
  25. * sets defined, we can make all constructors take such parameters.
  26. */
  27. public class EncapsOutputStream extends CDROutputStream
  28. {
  29. // corba/ORB
  30. // corba/ORBSingleton
  31. // iiop/ORB
  32. // iiop/GIOPImpl
  33. // corba/AnyImpl
  34. public EncapsOutputStream(ORB orb) {
  35. // GIOP version 1.2 with no fragmentation, big endian,
  36. // UTF8 for char data and UTF-16 for wide char data;
  37. super(orb, GIOPVersion.V1_2, false);
  38. }
  39. // CDREncapsCodec
  40. //
  41. // REVISIT. A UTF-16 encoding with GIOP 1.1 will not work
  42. // with byte order markers.
  43. public EncapsOutputStream(ORB orb, GIOPVersion version) {
  44. super(orb, version, false);
  45. }
  46. // Used by IIOPProfileTemplate
  47. //
  48. public EncapsOutputStream(ORB orb, boolean isLittleEndian) {
  49. super(orb, GIOPVersion.V1_2, false, isLittleEndian);
  50. }
  51. public EncapsOutputStream(ORB orb, int size) {
  52. super(orb, GIOPVersion.V1_2, size, false);
  53. }
  54. public org.omg.CORBA.portable.InputStream create_input_stream() {
  55. freeInternalCaches();
  56. return new EncapsInputStream(orb(),
  57. getByteBuffer(),
  58. getSize(),
  59. isLittleEndian());
  60. }
  61. protected CodeSetConversion.CTBConverter createCharCTBConverter() {
  62. return CodeSetConversion.impl().getCTBConverter(OSFCodeSetRegistry.ISO_8859_1);
  63. }
  64. protected CodeSetConversion.CTBConverter createWCharCTBConverter() {
  65. if (getGIOPVersion().equals(GIOPVersion.V1_0))
  66. throw new MARSHAL(MinorCodes.WCHAR_DATA_IN_GIOP_1_0,
  67. CompletionStatus.COMPLETED_MAYBE);
  68. // In the case of GIOP 1.1, we take the byte order of the stream and don't
  69. // use byte order markers since we're limited to a 2 byte fixed width encoding.
  70. if (getGIOPVersion().equals(GIOPVersion.V1_1))
  71. return CodeSetConversion.impl().getCTBConverter(OSFCodeSetRegistry.UTF_16,
  72. isLittleEndian(),
  73. false);
  74. // Assume anything else meets GIOP 1.2 requirements
  75. //
  76. // Use byte order markers? If not, use big endian in GIOP 1.2.
  77. // (formal 00-11-03 15.3.16)
  78. com.sun.corba.se.internal.corba.ORB ourOrb
  79. = (com.sun.corba.se.internal.corba.ORB)orb();
  80. boolean useBOM = ourOrb.useByteOrderMarkersInEncapsulations();
  81. return CodeSetConversion.impl().getCTBConverter(OSFCodeSetRegistry.UTF_16,
  82. false,
  83. useBOM);
  84. }
  85. }