0N/A/*
157N/A * Copyright (c) 2001, 2004, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
157N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
157N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
157N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
157N/A * or visit www.oracle.com if you need additional information or have any
157N/A * questions.
0N/A */
0N/A
0N/Apackage com.sun.corba.se.impl.encoding;
0N/A
0N/Aimport org.omg.CORBA.CompletionStatus;
0N/A
0N/Aimport com.sun.corba.se.spi.orb.ORB;
0N/A
0N/Aimport com.sun.corba.se.spi.ior.iiop.GIOPVersion;
0N/A
0N/Aimport com.sun.corba.se.impl.encoding.CodeSetConversion;
0N/Aimport com.sun.corba.se.impl.encoding.OSFCodeSetRegistry;
0N/Aimport com.sun.corba.se.impl.encoding.CDROutputStream;
0N/Aimport com.sun.corba.se.impl.encoding.BufferManagerWrite;
0N/Aimport com.sun.corba.se.impl.encoding.BufferManagerFactory;
0N/Aimport com.sun.corba.se.impl.protocol.giopmsgheaders.Message;
0N/Aimport com.sun.corba.se.impl.orbutil.ORBConstants;
0N/A
0N/A/**
0N/A * Encapsulations are supposed to explicitly define their
0N/A * code sets and GIOP version. The original resolution to issue 2784
0N/A * said that the defaults were UTF-8 and UTF-16, but that was not
0N/A * agreed upon.
0N/A *
0N/A * These streams currently use CDR 1.2 with ISO8859-1 for char/string and
0N/A * UTF16 for wchar/wstring. If no byte order marker is available,
0N/A * the endianness of the encapsulation is used.
0N/A *
0N/A * When more encapsulations arise that have their own special code
0N/A * sets defined, we can make all constructors take such parameters.
0N/A */
0N/Apublic class EncapsOutputStream extends CDROutputStream
0N/A{
0N/A
0N/A // REVISIT - Right now, EncapsOutputStream's do not use
0N/A // pooled byte buffers. This is controlled by the following
0N/A // static constant. This should be re-factored such that
0N/A // the EncapsOutputStream doesn't know it's using pooled
0N/A // byte buffers.
0N/A final static boolean usePooledByteBuffers = false;
0N/A
0N/A // REVISIT - Right now, valuetypes in encapsulations will
0N/A // only use stream format version 1, which may create problems
0N/A // for service contexts or codecs (?).
0N/A
0N/A // corba/ORB
0N/A // corba/ORBSingleton
0N/A // iiop/ORB
0N/A // iiop/GIOPImpl
0N/A // corba/AnyImpl
0N/A public EncapsOutputStream(ORB orb) {
0N/A // GIOP version 1.2 with no fragmentation, big endian,
0N/A // UTF8 for char data and UTF-16 for wide char data;
0N/A this(orb, GIOPVersion.V1_2);
0N/A }
0N/A
0N/A // CDREncapsCodec
0N/A //
0N/A // REVISIT. A UTF-16 encoding with GIOP 1.1 will not work
0N/A // with byte order markers.
0N/A public EncapsOutputStream(ORB orb, GIOPVersion version) {
0N/A this(orb, version, false);
0N/A }
0N/A
0N/A // Used by IIOPProfileTemplate
0N/A //
0N/A public EncapsOutputStream(ORB orb, boolean isLittleEndian) {
0N/A this(orb, GIOPVersion.V1_2, isLittleEndian);
0N/A }
0N/A
0N/A public EncapsOutputStream(ORB orb,
0N/A GIOPVersion version,
0N/A boolean isLittleEndian)
0N/A {
0N/A super(orb, version, Message.CDR_ENC_VERSION, isLittleEndian,
0N/A BufferManagerFactory.newBufferManagerWrite(
0N/A BufferManagerFactory.GROW,
0N/A Message.CDR_ENC_VERSION,
0N/A orb),
0N/A ORBConstants.STREAM_FORMAT_VERSION_1,
0N/A usePooledByteBuffers);
0N/A }
0N/A
0N/A public org.omg.CORBA.portable.InputStream create_input_stream() {
0N/A freeInternalCaches();
0N/A
0N/A return new EncapsInputStream(orb(),
0N/A getByteBuffer(),
0N/A getSize(),
0N/A isLittleEndian(),
0N/A getGIOPVersion());
0N/A }
0N/A
0N/A protected CodeSetConversion.CTBConverter createCharCTBConverter() {
0N/A return CodeSetConversion.impl().getCTBConverter(OSFCodeSetRegistry.ISO_8859_1);
0N/A }
0N/A
0N/A protected CodeSetConversion.CTBConverter createWCharCTBConverter() {
0N/A if (getGIOPVersion().equals(GIOPVersion.V1_0))
0N/A throw wrapper.wcharDataInGiop10(CompletionStatus.COMPLETED_MAYBE);
0N/A
0N/A // In the case of GIOP 1.1, we take the byte order of the stream and don't
0N/A // use byte order markers since we're limited to a 2 byte fixed width encoding.
0N/A if (getGIOPVersion().equals(GIOPVersion.V1_1))
0N/A return CodeSetConversion.impl().getCTBConverter(OSFCodeSetRegistry.UTF_16,
0N/A isLittleEndian(),
0N/A false);
0N/A
0N/A // Assume anything else meets GIOP 1.2 requirements
0N/A //
0N/A // Use byte order markers? If not, use big endian in GIOP 1.2.
0N/A // (formal 00-11-03 15.3.16)
0N/A
0N/A boolean useBOM = ((ORB)orb()).getORBData().useByteOrderMarkersInEncapsulations();
0N/A
0N/A return CodeSetConversion.impl().getCTBConverter(OSFCodeSetRegistry.UTF_16,
0N/A false,
0N/A useBOM);
0N/A }
0N/A}