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