1 7 package com.sun.corba.se.impl.encoding; 8 9 import org.omg.CORBA.BAD_PARAM ; 10 import org.omg.CORBA.INTERNAL ; 11 import org.omg.CORBA.CompletionStatus ; 12 import com.sun.corba.se.spi.ior.iiop.GIOPVersion; 13 import com.sun.corba.se.impl.encoding.CodeSetConversion; 14 import com.sun.corba.se.impl.orbutil.ORBConstants; 15 16 public class CDROutputStream_1_2 extends CDROutputStream_1_1 17 { 18 protected boolean primitiveAcrossFragmentedChunk = false; 43 44 62 protected boolean specialChunk = false; 63 64 private boolean headerPadding; 69 70 protected void handleSpecialChunkBegin(int requiredSize) 71 { 72 if (inBlock && requiredSize + bbwi.position() > bbwi.buflen) { 74 75 78 int oldSize = bbwi.position(); 79 bbwi.position(blockSizeIndex - 4); 80 81 writeLongWithoutAlign((oldSize - blockSizeIndex) + requiredSize); 83 bbwi.position(oldSize); 84 85 specialChunk = true; 88 } 89 } 90 91 protected void handleSpecialChunkEnd() 92 { 93 if (inBlock && specialChunk) { 95 96 inBlock = false; 100 blockSizeIndex = -1; 101 blockSizePosition = -1; 102 103 start_block(); 106 107 specialChunk = false; 111 } 112 } 113 114 private void checkPrimitiveAcrossFragmentedChunk() 116 { 117 if (primitiveAcrossFragmentedChunk) { 118 primitiveAcrossFragmentedChunk = false; 119 120 inBlock = false; 121 122 blockSizeIndex = -1; 126 blockSizePosition = -1; 127 128 start_block(); 130 } 131 } 132 133 134 public void write_octet(byte x) { 135 super.write_octet(x); 136 checkPrimitiveAcrossFragmentedChunk(); 137 } 138 139 public void write_short(short x) { 140 super.write_short(x); 141 checkPrimitiveAcrossFragmentedChunk(); 142 } 143 144 public void write_long(int x) { 145 super.write_long(x); 146 checkPrimitiveAcrossFragmentedChunk(); 147 } 148 149 public void write_longlong(long x) { 150 super.write_longlong(x); 151 checkPrimitiveAcrossFragmentedChunk(); 152 } 153 154 void setHeaderPadding(boolean headerPadding) { 156 this.headerPadding = headerPadding; 157 } 158 159 protected void alignAndReserve(int align, int n) { 160 161 if (headerPadding == true) { 168 headerPadding = false; 169 alignOnBoundary(ORBConstants.GIOP_12_MSG_BODY_ALIGNMENT); 170 } 171 172 179 bbwi.position(bbwi.position() + computeAlignment(align)); 180 181 if (bbwi.position() + n > bbwi.buflen) 182 grow(align, n); 183 } 184 185 protected void grow(int align, int n) { 186 187 int oldSize = bbwi.position(); 189 190 boolean handleChunk = (inBlock && !specialChunk); 200 if (handleChunk) { 201 int oldIndex = bbwi.position(); 202 203 bbwi.position(blockSizeIndex - 4); 204 205 writeLongWithoutAlign((oldIndex - blockSizeIndex) + n); 206 207 bbwi.position(oldIndex); 208 } 209 210 bbwi.needed = n; 211 bufferManagerWrite.overflow(bbwi); 212 213 217 if (bbwi.fragmented) { 219 220 bbwi.fragmented = false; 222 223 fragmentOffset += (oldSize - bbwi.position()); 228 229 if (handleChunk) 232 primitiveAcrossFragmentedChunk = true; 233 234 } 235 } 236 237 public GIOPVersion getGIOPVersion() { 238 return GIOPVersion.V1_2; 239 } 240 241 public void write_wchar(char x) 242 { 243 CodeSetConversion.CTBConverter converter = getWCharConverter(); 252 253 converter.convert(x); 254 255 handleSpecialChunkBegin(1 + converter.getNumBytes()); 256 257 write_octet((byte)converter.getNumBytes()); 258 259 byte[] result = converter.getBytes(); 260 261 internalWriteOctetArray(result, 0, converter.getNumBytes()); 264 265 handleSpecialChunkEnd(); 266 } 267 268 public void write_wchar_array(char[] value, int offset, int length) 269 { 270 if (value == null) { 271 throw wrapper.nullParam(CompletionStatus.COMPLETED_MAYBE); 272 } 273 274 CodeSetConversion.CTBConverter converter = getWCharConverter(); 275 276 int totalNumBytes = 0; 281 282 int maxLength = (int)Math.ceil(converter.getMaxBytesPerChar() * length); 285 byte[] buffer = new byte[maxLength + length]; 286 287 for (int i = 0; i < length; i++) { 288 converter.convert(value[offset + i]); 290 291 buffer[totalNumBytes++] = (byte)converter.getNumBytes(); 293 294 System.arraycopy(converter.getBytes(), 0, 296 buffer, totalNumBytes, 297 converter.getNumBytes()); 298 299 totalNumBytes += converter.getNumBytes(); 300 } 301 302 handleSpecialChunkBegin(totalNumBytes); 306 307 internalWriteOctetArray(buffer, 0, totalNumBytes); 310 311 handleSpecialChunkEnd(); 312 } 313 314 public void write_wstring(String value) { 315 if (value == null) { 316 throw wrapper.nullParam(CompletionStatus.COMPLETED_MAYBE); 317 } 318 319 if (value.length() == 0) { 324 write_long(0); 325 return; 326 } 327 328 CodeSetConversion.CTBConverter converter = getWCharConverter(); 329 330 converter.convert(value); 331 332 handleSpecialChunkBegin(computeAlignment(4) + 4 + converter.getNumBytes()); 333 334 write_long(converter.getNumBytes()); 335 336 internalWriteOctetArray(converter.getBytes(), 0, converter.getNumBytes()); 338 339 handleSpecialChunkEnd(); 340 } 341 } 342 | Popular Tags |