1. /*
  2. * @(#)Direct-X-Buffer.java 1.48 04/05/03
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. // -- This file was mechanically generated: Do not edit! -- //
  8. package java.nio;
  9. import sun.misc.Cleaner;
  10. import sun.misc.Unsafe;
  11. import sun.nio.ch.DirectBuffer;
  12. import sun.nio.ch.FileChannelImpl;
  13. class DirectCharBufferRU
  14. extends DirectCharBufferU
  15. implements DirectBuffer
  16. {
  17. // For duplicates and slices
  18. //
  19. DirectCharBufferRU(DirectBuffer db, // package-private
  20. int mark, int pos, int lim, int cap,
  21. int off)
  22. {
  23. super(db, mark, pos, lim, cap, off);
  24. }
  25. public CharBuffer slice() {
  26. int pos = this.position();
  27. int lim = this.limit();
  28. assert (pos <= lim);
  29. int rem = (pos <= lim ? lim - pos : 0);
  30. int off = (pos << 1);
  31. assert (off >= 0);
  32. return new DirectCharBufferRU(this, -1, 0, rem, rem, off);
  33. }
  34. public CharBuffer duplicate() {
  35. return new DirectCharBufferRU(this,
  36. this.markValue(),
  37. this.position(),
  38. this.limit(),
  39. this.capacity(),
  40. 0);
  41. }
  42. public CharBuffer asReadOnlyBuffer() {
  43. return duplicate();
  44. }
  45. public CharBuffer put(char x) {
  46. throw new ReadOnlyBufferException();
  47. }
  48. public CharBuffer put(int i, char x) {
  49. throw new ReadOnlyBufferException();
  50. }
  51. public CharBuffer put(CharBuffer src) {
  52. throw new ReadOnlyBufferException();
  53. }
  54. public CharBuffer put(char[] src, int offset, int length) {
  55. throw new ReadOnlyBufferException();
  56. }
  57. public CharBuffer compact() {
  58. throw new ReadOnlyBufferException();
  59. }
  60. public boolean isDirect() {
  61. return true;
  62. }
  63. public boolean isReadOnly() {
  64. return true;
  65. }
  66. public String toString(int start, int end) {
  67. if ((end > limit()) || (start > end))
  68. throw new IndexOutOfBoundsException();
  69. try {
  70. int len = end - start;
  71. char[] ca = new char[len];
  72. CharBuffer cb = CharBuffer.wrap(ca);
  73. CharBuffer db = this.duplicate();
  74. db.position(start);
  75. db.limit(end);
  76. cb.put(db);
  77. return new String(ca);
  78. } catch (StringIndexOutOfBoundsException x) {
  79. throw new IndexOutOfBoundsException();
  80. }
  81. }
  82. // --- Methods to support CharSequence ---
  83. public CharSequence subSequence(int start, int end) {
  84. int pos = position();
  85. int lim = limit();
  86. assert (pos <= lim);
  87. pos = (pos <= lim ? pos : lim);
  88. int len = lim - pos;
  89. if ((start < 0) || (end > len) || (start > end))
  90. throw new IndexOutOfBoundsException();
  91. int sublen = end - start;
  92. int off = (pos + start) << 1;
  93. assert (off >= 0);
  94. return new DirectCharBufferRU(this, -1, 0, sublen, sublen, off);
  95. }
  96. public ByteOrder order() {
  97. return ((ByteOrder.nativeOrder() != ByteOrder.BIG_ENDIAN)
  98. ? ByteOrder.LITTLE_ENDIAN : ByteOrder.BIG_ENDIAN);
  99. }
  100. }