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. import com.sun.corba.se.spi.ior.iiop.GIOPVersion;
  9. import com.sun.corba.se.impl.orbutil.ORBConstants;
  10. public class CDRInputStream_1_2 extends CDRInputStream_1_1
  11. {
  12. // Indicates whether the header is padded. In GIOP 1.2 and above,
  13. // the body must be aligned on an 8-octet boundary, and so the header is
  14. // padded appropriately. However, if there is no body to a request or reply
  15. // message, there is no header padding, in the unfragmented case.
  16. protected boolean headerPadding;
  17. // used to remember headerPadding flag when mark() and restore() are used.
  18. protected boolean restoreHeaderPadding;
  19. // Called by RequestMessage_1_2 or ReplyMessage_1_2 classes only.
  20. void setHeaderPadding(boolean headerPadding) {
  21. this.headerPadding = headerPadding;
  22. }
  23. // the mark and reset methods have been overridden to remember the
  24. // headerPadding flag.
  25. public void mark(int readlimit) {
  26. super.mark(readlimit);
  27. restoreHeaderPadding = headerPadding;
  28. }
  29. public void reset() {
  30. super.reset();
  31. headerPadding = restoreHeaderPadding;
  32. restoreHeaderPadding = false;
  33. }
  34. // Template method
  35. // This method has been overriden to ensure that the duplicated stream
  36. // inherits the headerPadding flag, in case of GIOP 1.2 and above, streams.
  37. public CDRInputStreamBase dup() {
  38. CDRInputStreamBase result = super.dup();
  39. ((CDRInputStream_1_2)result).headerPadding = this.headerPadding;
  40. return result;
  41. }
  42. protected void alignAndCheck(int align, int n) {
  43. // headerPadding bit is set by read method of the RequestMessage_1_2
  44. // or ReplyMessage_1_2 classes. When set, the very first body read
  45. // operation (from the stub code) would trigger an alignAndCheck
  46. // method call, that would in turn skip the header padding that was
  47. // inserted during the earlier write operation by the sender. The
  48. // padding ensures that the body is aligned on an 8-octet boundary,
  49. // for GIOP versions 1.2 and beyond.
  50. if (headerPadding == true) {
  51. headerPadding = false;
  52. alignOnBoundary(ORBConstants.GIOP_12_MSG_BODY_ALIGNMENT);
  53. }
  54. checkBlockLength(align, n);
  55. // WARNING: Must compute real alignment after calling
  56. // checkBlockLength since it may move the position
  57. // In GIOP 1.2, a fragment may end with some alignment
  58. // padding (which leads to all fragments ending perfectly
  59. // on evenly divisible 8 byte boundaries). A new fragment
  60. // never requires alignment with the header since it ends
  61. // on an 8 byte boundary.
  62. int alignIncr = computeAlignment(bbwi.position(),align);
  63. bbwi.position(bbwi.position() + alignIncr);
  64. if (bbwi.position() + n > bbwi.buflen) {
  65. grow(1, n);
  66. }
  67. }
  68. public GIOPVersion getGIOPVersion() {
  69. return GIOPVersion.V1_2;
  70. }
  71. public char read_wchar() {
  72. // In GIOP 1.2, a wchar is encoded as an unsigned octet length
  73. // followed by the octets of the converted wchar.
  74. int numBytes = read_octet();
  75. char[] result = getConvertedChars(numBytes, getWCharConverter());
  76. // Did the provided bytes convert to more than one
  77. // character? This may come up as more unicode values are
  78. // assigned, and a single 16 bit Java char isn't enough.
  79. // Better to use strings for i18n purposes.
  80. if (getWCharConverter().getNumChars() > 1)
  81. throw wrapper.btcResultMoreThanOneChar() ;
  82. return result[0];
  83. }
  84. public String read_wstring() {
  85. // In GIOP 1.2, wstrings are not terminated by a null. The
  86. // length is the number of octets in the converted format.
  87. // A zero length string is represented with the 4 byte length
  88. // value of 0.
  89. int len = read_long();
  90. //
  91. // IMPORTANT: Do not replace 'new String("")' with "", it may result
  92. // in a Serialization bug (See serialization.zerolengthstring) and
  93. // bug id: 4728756 for details
  94. if (len == 0)
  95. return new String("");
  96. checkForNegativeLength(len);
  97. return new String(getConvertedChars(len, getWCharConverter()),
  98. 0,
  99. getWCharConverter().getNumChars());
  100. }
  101. }