KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > encoding > EncapsOutputStream


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
8 package com.sun.corba.se.impl.encoding;
9
10 import org.omg.CORBA.CompletionStatus JavaDoc;
11
12 import com.sun.corba.se.spi.orb.ORB;
13
14 import com.sun.corba.se.spi.ior.iiop.GIOPVersion;
15
16 import com.sun.corba.se.impl.encoding.CodeSetConversion;
17 import com.sun.corba.se.impl.encoding.OSFCodeSetRegistry;
18 import com.sun.corba.se.impl.encoding.CDROutputStream;
19 import com.sun.corba.se.impl.encoding.BufferManagerWrite;
20 import com.sun.corba.se.impl.encoding.BufferManagerFactory;
21 import com.sun.corba.se.impl.protocol.giopmsgheaders.Message;
22 import com.sun.corba.se.impl.orbutil.ORBConstants;
23
24 /**
25  * Encapsulations are supposed to explicitly define their
26  * code sets and GIOP version. The original resolution to issue 2784
27  * said that the defaults were UTF-8 and UTF-16, but that was not
28  * agreed upon.
29  *
30  * These streams currently use CDR 1.2 with ISO8859-1 for char/string and
31  * UTF16 for wchar/wstring. If no byte order marker is available,
32  * the endianness of the encapsulation is used.
33  *
34  * When more encapsulations arise that have their own special code
35  * sets defined, we can make all constructors take such parameters.
36  */

37 public class EncapsOutputStream extends CDROutputStream
38 {
39
40     // REVISIT - Right now, EncapsOutputStream's do not use
41
// pooled byte buffers. This is controlled by the following
42
// static constant. This should be re-factored such that
43
// the EncapsOutputStream doesn't know it's using pooled
44
// byte buffers.
45
final static boolean usePooledByteBuffers = false;
46
47     // REVISIT - Right now, valuetypes in encapsulations will
48
// only use stream format version 1, which may create problems
49
// for service contexts or codecs (?).
50

51     // corba/ORB
52
// corba/ORBSingleton
53
// iiop/ORB
54
// iiop/GIOPImpl
55
// corba/AnyImpl
56
public EncapsOutputStream(ORB orb) {
57         // GIOP version 1.2 with no fragmentation, big endian,
58
// UTF8 for char data and UTF-16 for wide char data;
59
this(orb, GIOPVersion.V1_2);
60     }
61
62     // CDREncapsCodec
63
//
64
// REVISIT. A UTF-16 encoding with GIOP 1.1 will not work
65
// with byte order markers.
66
public EncapsOutputStream(ORB orb, GIOPVersion version) {
67         this(orb, version, false);
68     }
69
70     // Used by IIOPProfileTemplate
71
//
72
public EncapsOutputStream(ORB orb, boolean isLittleEndian) {
73         this(orb, GIOPVersion.V1_2, isLittleEndian);
74     }
75
76     public EncapsOutputStream(ORB orb,
77                   GIOPVersion version,
78                   boolean isLittleEndian)
79     {
80         super(orb, version, Message.CDR_ENC_VERSION, isLittleEndian,
81           BufferManagerFactory.newBufferManagerWrite(
82                                         BufferManagerFactory.GROW,
83                     Message.CDR_ENC_VERSION,
84                     orb),
85           ORBConstants.STREAM_FORMAT_VERSION_1,
86               usePooledByteBuffers);
87     }
88
89     public org.omg.CORBA.portable.InputStream JavaDoc create_input_stream() {
90         freeInternalCaches();
91
92         return new EncapsInputStream(orb(),
93                                      getByteBuffer(),
94                                      getSize(),
95                                      isLittleEndian(),
96                                      getGIOPVersion());
97     }
98     
99     protected CodeSetConversion.CTBConverter createCharCTBConverter() {
100         return CodeSetConversion.impl().getCTBConverter(OSFCodeSetRegistry.ISO_8859_1);
101     }
102
103     protected CodeSetConversion.CTBConverter createWCharCTBConverter() {
104         if (getGIOPVersion().equals(GIOPVersion.V1_0))
105         throw wrapper.wcharDataInGiop10(CompletionStatus.COMPLETED_MAYBE);
106
107         // In the case of GIOP 1.1, we take the byte order of the stream and don't
108
// use byte order markers since we're limited to a 2 byte fixed width encoding.
109
if (getGIOPVersion().equals(GIOPVersion.V1_1))
110             return CodeSetConversion.impl().getCTBConverter(OSFCodeSetRegistry.UTF_16,
111                                                             isLittleEndian(),
112                                                             false);
113
114         // Assume anything else meets GIOP 1.2 requirements
115
//
116
// Use byte order markers? If not, use big endian in GIOP 1.2.
117
// (formal 00-11-03 15.3.16)
118

119         boolean useBOM = ((ORB)orb()).getORBData().useByteOrderMarkersInEncapsulations();
120
121         return CodeSetConversion.impl().getCTBConverter(OSFCodeSetRegistry.UTF_16,
122                                                         false,
123                                                         useBOM);
124     }
125 }
126
Popular Tags