1. /*
  2. * @(#)Heap-X-Buffer.java 1.28 03/12/19
  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. /**
  10. * A read-only HeapCharBuffer. This class extends the corresponding
  11. * read/write class, overriding the mutation methods to throw a {@link
  12. * ReadOnlyBufferException} and overriding the view-buffer methods to return an
  13. * instance of this class rather than of the superclass.
  14. */
  15. class HeapCharBufferR
  16. extends HeapCharBuffer
  17. {
  18. // For speed these fields are actually declared in X-Buffer;
  19. // these declarations are here as documentation
  20. /*
  21. */
  22. HeapCharBufferR(int cap, int lim) { // package-private
  23. super(cap, lim);
  24. this.isReadOnly = true;
  25. }
  26. HeapCharBufferR(char[] buf, int off, int len) { // package-private
  27. super(buf, off, len);
  28. this.isReadOnly = true;
  29. }
  30. protected HeapCharBufferR(char[] buf,
  31. int mark, int pos, int lim, int cap,
  32. int off)
  33. {
  34. super(buf, mark, pos, lim, cap, off);
  35. this.isReadOnly = true;
  36. }
  37. public CharBuffer slice() {
  38. return new HeapCharBufferR(hb,
  39. -1,
  40. 0,
  41. this.remaining(),
  42. this.remaining(),
  43. this.position() + offset);
  44. }
  45. public CharBuffer duplicate() {
  46. return new HeapCharBufferR(hb,
  47. this.markValue(),
  48. this.position(),
  49. this.limit(),
  50. this.capacity(),
  51. offset);
  52. }
  53. public CharBuffer asReadOnlyBuffer() {
  54. return duplicate();
  55. }
  56. public boolean isReadOnly() {
  57. return true;
  58. }
  59. public CharBuffer put(char x) {
  60. throw new ReadOnlyBufferException();
  61. }
  62. public CharBuffer put(int i, char x) {
  63. throw new ReadOnlyBufferException();
  64. }
  65. public CharBuffer put(char[] src, int offset, int length) {
  66. throw new ReadOnlyBufferException();
  67. }
  68. public CharBuffer put(CharBuffer src) {
  69. throw new ReadOnlyBufferException();
  70. }
  71. public CharBuffer compact() {
  72. throw new ReadOnlyBufferException();
  73. }
  74. String toString(int start, int end) { // package-private
  75. try {
  76. return new String(hb, start + offset, end - start);
  77. } catch (StringIndexOutOfBoundsException x) {
  78. throw new IndexOutOfBoundsException();
  79. }
  80. }
  81. // --- Methods to support CharSequence ---
  82. public CharSequence subSequence(int start, int end) {
  83. if ((start < 0)
  84. || (end > length())
  85. || (start > end))
  86. throw new IndexOutOfBoundsException();
  87. int len = end - start;
  88. return new HeapCharBufferR(hb,
  89. -1, 0, len, len,
  90. offset + position() + start);
  91. }
  92. public ByteOrder order() {
  93. return ByteOrder.nativeOrder();
  94. }
  95. }