KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)CDRInputStream_1_2.java 1.14 04/03/01
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
9 import com.sun.corba.se.spi.ior.iiop.GIOPVersion;
10 import com.sun.corba.se.impl.orbutil.ORBConstants;
11
12 public class CDRInputStream_1_2 extends CDRInputStream_1_1
13 {
14     // Indicates whether the header is padded. In GIOP 1.2 and above,
15
// the body must be aligned on an 8-octet boundary, and so the header is
16
// padded appropriately. However, if there is no body to a request or reply
17
// message, there is no header padding, in the unfragmented case.
18
protected boolean headerPadding;
19     
20     // used to remember headerPadding flag when mark() and restore() are used.
21
protected boolean restoreHeaderPadding;
22
23     // Called by RequestMessage_1_2 or ReplyMessage_1_2 classes only.
24
void setHeaderPadding(boolean headerPadding) {
25         this.headerPadding = headerPadding;
26     }
27
28     // the mark and reset methods have been overridden to remember the
29
// headerPadding flag.
30

31     public void mark(int readlimit) {
32         super.mark(readlimit);
33         restoreHeaderPadding = headerPadding;
34     }
35
36     public void reset() {
37         super.reset();
38         headerPadding = restoreHeaderPadding;
39         restoreHeaderPadding = false;
40     }
41
42     // Template method
43
// This method has been overriden to ensure that the duplicated stream
44
// inherits the headerPadding flag, in case of GIOP 1.2 and above, streams.
45
public CDRInputStreamBase dup() {
46         CDRInputStreamBase result = super.dup();
47         ((CDRInputStream_1_2)result).headerPadding = this.headerPadding;
48         return result;
49     }
50     
51     protected void alignAndCheck(int align, int n) {
52
53         // headerPadding bit is set by read method of the RequestMessage_1_2
54
// or ReplyMessage_1_2 classes. When set, the very first body read
55
// operation (from the stub code) would trigger an alignAndCheck
56
// method call, that would in turn skip the header padding that was
57
// inserted during the earlier write operation by the sender. The
58
// padding ensures that the body is aligned on an 8-octet boundary,
59
// for GIOP versions 1.2 and beyond.
60
if (headerPadding == true) {
61             headerPadding = false;
62             alignOnBoundary(ORBConstants.GIOP_12_MSG_BODY_ALIGNMENT);
63         }
64       
65         checkBlockLength(align, n);
66
67         // WARNING: Must compute real alignment after calling
68
// checkBlockLength since it may move the position
69

70         // In GIOP 1.2, a fragment may end with some alignment
71
// padding (which leads to all fragments ending perfectly
72
// on evenly divisible 8 byte boundaries). A new fragment
73
// never requires alignment with the header since it ends
74
// on an 8 byte boundary.
75

76         int alignIncr = computeAlignment(bbwi.position(),align);
77         bbwi.position(bbwi.position() + alignIncr);
78
79         if (bbwi.position() + n > bbwi.buflen) {
80             grow(1, n);
81         }
82     }
83
84     public GIOPVersion getGIOPVersion() {
85         return GIOPVersion.V1_2;
86     }
87         
88     public char read_wchar() {
89         // In GIOP 1.2, a wchar is encoded as an unsigned octet length
90
// followed by the octets of the converted wchar.
91
int numBytes = read_octet();
92
93         char[] result = getConvertedChars(numBytes, getWCharConverter());
94
95         // Did the provided bytes convert to more than one
96
// character? This may come up as more unicode values are
97
// assigned, and a single 16 bit Java char isn't enough.
98
// Better to use strings for i18n purposes.
99
if (getWCharConverter().getNumChars() > 1)
100         throw wrapper.btcResultMoreThanOneChar() ;
101
102         return result[0];
103     }
104
105     public String JavaDoc read_wstring() {
106         // In GIOP 1.2, wstrings are not terminated by a null. The
107
// length is the number of octets in the converted format.
108
// A zero length string is represented with the 4 byte length
109
// value of 0.
110

111         int len = read_long();
112
113         //
114
// IMPORTANT: Do not replace 'new String("")' with "", it may result
115
// in a Serialization bug (See serialization.zerolengthstring) and
116
// bug id: 4728756 for details
117
if (len == 0)
118             return new String JavaDoc("");
119
120         checkForNegativeLength(len);
121
122         return new String JavaDoc(getConvertedChars(len, getWCharConverter()),
123                           0,
124                           getWCharConverter().getNumChars());
125     }
126 }
127
Popular Tags