1. /*
  2. * @(#)CDRInputStream_1_2.java 1.11 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.corba.se.internal.iiop;
  8. import org.omg.CORBA.DATA_CONVERSION;
  9. import org.omg.CORBA.CompletionStatus;
  10. import com.sun.corba.se.internal.orbutil.MinorCodes;
  11. import com.sun.corba.se.internal.core.GIOPVersion;
  12. public class CDRInputStream_1_2 extends CDRInputStream_1_1
  13. {
  14. protected void alignAndCheck(int align, int n) {
  15. checkBlockLength();
  16. // In GIOP 1.2, a fragment may end with some alignment
  17. // padding (which leads to all fragments ending perfectly
  18. // on evenly divisible 8 byte boundaries). A new fragment
  19. // never requires alignment with the header since it ends
  20. // on an 8 byte boundary.
  21. bbwi.index += computeAlignment(align);
  22. if (bbwi.index + n > bbwi.buflen) {
  23. grow(1, n);
  24. }
  25. }
  26. public GIOPVersion getGIOPVersion() {
  27. return GIOPVersion.V1_2;
  28. }
  29. public char read_wchar() {
  30. // In GIOP 1.2, a wchar is encoded as an unsigned octet length
  31. // followed by the octets of the converted wchar.
  32. int numBytes = read_octet();
  33. char[] result = getConvertedChars(numBytes, getWCharConverter());
  34. // Did the provided bytes convert to more than one
  35. // character? This may come up as more unicode values are
  36. // assigned, and a single 16 bit Java char isn't enough.
  37. // Better to use strings for i18n purposes.
  38. if (getWCharConverter().getNumChars() > 1)
  39. throw new DATA_CONVERSION(MinorCodes.BTC_RESULT_MORE_THAN_ONE_CHAR,
  40. CompletionStatus.COMPLETED_NO);
  41. return result[0];
  42. }
  43. public String read_wstring() {
  44. // In GIOP 1.2, wstrings are not terminated by a null. The
  45. // length is the number of octets in the converted format.
  46. // A zero length string is represented with the 4 byte length
  47. // value of 0.
  48. int len = read_long();
  49. // IMPORTANT: Do not replace 'new String("")' with "", it may result
  50. // in a Serialization bug (See serialization.zerolengthstring) and
  51. // bug id: 4728756 for details
  52. if (len == 0)
  53. return new String("");
  54. checkForNegativeLength(len);
  55. return new String(getConvertedChars(len, getWCharConverter()),
  56. 0,
  57. getWCharConverter().getNumChars());
  58. }
  59. }