1. /*
  2. * @(#)Direct-X-Buffer.java 1.45 03/04/23
  3. *
  4. * Copyright 2003 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. return new DirectCharBufferRU(this, -1, 0, rem, rem, off);
  32. }
  33. public CharBuffer duplicate() {
  34. return new DirectCharBufferRU(this,
  35. this.markValue(),
  36. this.position(),
  37. this.limit(),
  38. this.capacity(),
  39. 0);
  40. }
  41. public CharBuffer asReadOnlyBuffer() {
  42. return duplicate();
  43. }
  44. public CharBuffer put(char x) {
  45. throw new ReadOnlyBufferException();
  46. }
  47. public CharBuffer put(int i, char x) {
  48. throw new ReadOnlyBufferException();
  49. }
  50. public CharBuffer put(CharBuffer src) {
  51. throw new ReadOnlyBufferException();
  52. }
  53. public CharBuffer put(char[] src, int offset, int length) {
  54. throw new ReadOnlyBufferException();
  55. }
  56. public CharBuffer compact() {
  57. throw new ReadOnlyBufferException();
  58. }
  59. public boolean isDirect() {
  60. return true;
  61. }
  62. public boolean isReadOnly() {
  63. return true;
  64. }
  65. public String toString(int start, int end) {
  66. if ((end > limit()) || (start > end))
  67. throw new IndexOutOfBoundsException();
  68. try {
  69. int len = end - start;
  70. char[] ca = new char[len];
  71. CharBuffer cb = CharBuffer.wrap(ca);
  72. CharBuffer db = this.duplicate();
  73. db.position(start);
  74. db.limit(end);
  75. cb.put(db);
  76. return new String(ca);
  77. } catch (StringIndexOutOfBoundsException x) {
  78. throw new IndexOutOfBoundsException();
  79. }
  80. }
  81. // --- Methods to support CharSequence ---
  82. public CharSequence subSequence(int start, int end) {
  83. int len = length();
  84. int pos = position();
  85. assert (pos <= len);
  86. pos = (pos <= len ? pos : len);
  87. if ((start < 0) || (end > len) || (start > end))
  88. throw new IndexOutOfBoundsException();
  89. int sublen = end - start;
  90. int off = (pos + start) << 1;
  91. return new DirectCharBufferRU(this, -1, 0, sublen, sublen, off);
  92. }
  93. public ByteOrder order() {
  94. return ((ByteOrder.nativeOrder() != ByteOrder.BIG_ENDIAN)
  95. ? ByteOrder.LITTLE_ENDIAN : ByteOrder.BIG_ENDIAN);
  96. }
  97. }