1. /*
  2. * @(#)ByteBufferAs-X-Buffer.java 1.17 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. class ByteBufferAsCharBufferRL // package-private
  10. extends ByteBufferAsCharBufferL
  11. {
  12. ByteBufferAsCharBufferRL(ByteBuffer bb) { // package-private
  13. super(bb);
  14. }
  15. ByteBufferAsCharBufferRL(ByteBuffer bb,
  16. int mark, int pos, int lim, int cap,
  17. int off)
  18. {
  19. super(bb, mark, pos, lim, cap, off);
  20. }
  21. public CharBuffer slice() {
  22. int pos = this.position();
  23. int lim = this.limit();
  24. assert (pos <= lim);
  25. int rem = (pos <= lim ? lim - pos : 0);
  26. int off = (pos << 1) + offset;
  27. assert (off >= 0);
  28. return new ByteBufferAsCharBufferRL(bb, -1, 0, rem, rem, off);
  29. }
  30. public CharBuffer duplicate() {
  31. return new ByteBufferAsCharBufferRL(bb,
  32. this.markValue(),
  33. this.position(),
  34. this.limit(),
  35. this.capacity(),
  36. offset);
  37. }
  38. public CharBuffer asReadOnlyBuffer() {
  39. return duplicate();
  40. }
  41. public CharBuffer put(char x) {
  42. throw new ReadOnlyBufferException();
  43. }
  44. public CharBuffer put(int i, char x) {
  45. throw new ReadOnlyBufferException();
  46. }
  47. public CharBuffer compact() {
  48. throw new ReadOnlyBufferException();
  49. }
  50. public boolean isDirect() {
  51. return bb.isDirect();
  52. }
  53. public boolean isReadOnly() {
  54. return true;
  55. }
  56. public String toString(int start, int end) {
  57. if ((end > limit()) || (start > end))
  58. throw new IndexOutOfBoundsException();
  59. try {
  60. int len = end - start;
  61. char[] ca = new char[len];
  62. CharBuffer cb = CharBuffer.wrap(ca);
  63. CharBuffer db = this.duplicate();
  64. db.position(start);
  65. db.limit(end);
  66. cb.put(db);
  67. return new String(ca);
  68. } catch (StringIndexOutOfBoundsException x) {
  69. throw new IndexOutOfBoundsException();
  70. }
  71. }
  72. // --- Methods to support CharSequence ---
  73. public CharSequence subSequence(int start, int end) {
  74. int pos = position();
  75. int lim = limit();
  76. assert (pos <= lim);
  77. pos = (pos <= lim ? pos : lim);
  78. int len = lim - pos;
  79. if ((start < 0) || (end > len) || (start > end))
  80. throw new IndexOutOfBoundsException();
  81. int sublen = end - start;
  82. int off = offset + ((pos + start) << 1);
  83. assert (off >= 0);
  84. return new ByteBufferAsCharBufferRL(bb, -1, 0, sublen, sublen, off);
  85. }
  86. public ByteOrder order() {
  87. return ByteOrder.LITTLE_ENDIAN;
  88. }
  89. }