1. /*
  2. * @(#)Heap-X-Buffer.java 1.27 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. /**
  10. * A read-only HeapByteBuffer. 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 HeapByteBufferR
  16. extends HeapByteBuffer
  17. {
  18. // For speed these fields are actually declared in X-Buffer;
  19. // these declarations are here as documentation
  20. /*
  21. */
  22. HeapByteBufferR(int cap, int lim) { // package-private
  23. super(cap, lim);
  24. this.isReadOnly = true;
  25. }
  26. HeapByteBufferR(byte[] buf, int off, int len) { // package-private
  27. super(buf, off, len);
  28. this.isReadOnly = true;
  29. }
  30. protected HeapByteBufferR(byte[] 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 ByteBuffer slice() {
  38. return new HeapByteBufferR(hb,
  39. -1,
  40. 0,
  41. this.remaining(),
  42. this.remaining(),
  43. this.position() + offset);
  44. }
  45. public ByteBuffer duplicate() {
  46. return new HeapByteBufferR(hb,
  47. this.markValue(),
  48. this.position(),
  49. this.limit(),
  50. this.capacity(),
  51. offset);
  52. }
  53. public ByteBuffer asReadOnlyBuffer() {
  54. return duplicate();
  55. }
  56. public boolean isReadOnly() {
  57. return true;
  58. }
  59. public ByteBuffer put(byte x) {
  60. throw new ReadOnlyBufferException();
  61. }
  62. public ByteBuffer put(int i, byte x) {
  63. throw new ReadOnlyBufferException();
  64. }
  65. public ByteBuffer put(byte[] src, int offset, int length) {
  66. throw new ReadOnlyBufferException();
  67. }
  68. public ByteBuffer put(ByteBuffer src) {
  69. throw new ReadOnlyBufferException();
  70. }
  71. public ByteBuffer compact() {
  72. throw new ReadOnlyBufferException();
  73. }
  74. byte _get(int i) { // package-private
  75. return hb[i];
  76. }
  77. void _put(int i, byte b) { // package-private
  78. throw new ReadOnlyBufferException();
  79. }
  80. // char
  81. public ByteBuffer putChar(char x) {
  82. throw new ReadOnlyBufferException();
  83. }
  84. public ByteBuffer putChar(int i, char x) {
  85. throw new ReadOnlyBufferException();
  86. }
  87. public CharBuffer asCharBuffer() {
  88. int size = this.remaining() >> 1;
  89. int off = offset + position();
  90. return (bigEndian
  91. ? (CharBuffer)(new ByteBufferAsCharBufferRB(this,
  92. -1,
  93. 0,
  94. size,
  95. size,
  96. off))
  97. : (CharBuffer)(new ByteBufferAsCharBufferRL(this,
  98. -1,
  99. 0,
  100. size,
  101. size,
  102. off)));
  103. }
  104. // short
  105. public ByteBuffer putShort(short x) {
  106. throw new ReadOnlyBufferException();
  107. }
  108. public ByteBuffer putShort(int i, short x) {
  109. throw new ReadOnlyBufferException();
  110. }
  111. public ShortBuffer asShortBuffer() {
  112. int size = this.remaining() >> 1;
  113. int off = offset + position();
  114. return (bigEndian
  115. ? (ShortBuffer)(new ByteBufferAsShortBufferRB(this,
  116. -1,
  117. 0,
  118. size,
  119. size,
  120. off))
  121. : (ShortBuffer)(new ByteBufferAsShortBufferRL(this,
  122. -1,
  123. 0,
  124. size,
  125. size,
  126. off)));
  127. }
  128. // int
  129. public ByteBuffer putInt(int x) {
  130. throw new ReadOnlyBufferException();
  131. }
  132. public ByteBuffer putInt(int i, int x) {
  133. throw new ReadOnlyBufferException();
  134. }
  135. public IntBuffer asIntBuffer() {
  136. int size = this.remaining() >> 2;
  137. int off = offset + position();
  138. return (bigEndian
  139. ? (IntBuffer)(new ByteBufferAsIntBufferRB(this,
  140. -1,
  141. 0,
  142. size,
  143. size,
  144. off))
  145. : (IntBuffer)(new ByteBufferAsIntBufferRL(this,
  146. -1,
  147. 0,
  148. size,
  149. size,
  150. off)));
  151. }
  152. // long
  153. public ByteBuffer putLong(long x) {
  154. throw new ReadOnlyBufferException();
  155. }
  156. public ByteBuffer putLong(int i, long x) {
  157. throw new ReadOnlyBufferException();
  158. }
  159. public LongBuffer asLongBuffer() {
  160. int size = this.remaining() >> 3;
  161. int off = offset + position();
  162. return (bigEndian
  163. ? (LongBuffer)(new ByteBufferAsLongBufferRB(this,
  164. -1,
  165. 0,
  166. size,
  167. size,
  168. off))
  169. : (LongBuffer)(new ByteBufferAsLongBufferRL(this,
  170. -1,
  171. 0,
  172. size,
  173. size,
  174. off)));
  175. }
  176. // float
  177. public ByteBuffer putFloat(float x) {
  178. throw new ReadOnlyBufferException();
  179. }
  180. public ByteBuffer putFloat(int i, float x) {
  181. throw new ReadOnlyBufferException();
  182. }
  183. public FloatBuffer asFloatBuffer() {
  184. int size = this.remaining() >> 2;
  185. int off = offset + position();
  186. return (bigEndian
  187. ? (FloatBuffer)(new ByteBufferAsFloatBufferRB(this,
  188. -1,
  189. 0,
  190. size,
  191. size,
  192. off))
  193. : (FloatBuffer)(new ByteBufferAsFloatBufferRL(this,
  194. -1,
  195. 0,
  196. size,
  197. size,
  198. off)));
  199. }
  200. // double
  201. public ByteBuffer putDouble(double x) {
  202. throw new ReadOnlyBufferException();
  203. }
  204. public ByteBuffer putDouble(int i, double x) {
  205. throw new ReadOnlyBufferException();
  206. }
  207. public DoubleBuffer asDoubleBuffer() {
  208. int size = this.remaining() >> 3;
  209. int off = offset + position();
  210. return (bigEndian
  211. ? (DoubleBuffer)(new ByteBufferAsDoubleBufferRB(this,
  212. -1,
  213. 0,
  214. size,
  215. size,
  216. off))
  217. : (DoubleBuffer)(new ByteBufferAsDoubleBufferRL(this,
  218. -1,
  219. 0,
  220. size,
  221. size,
  222. off)));
  223. }
  224. }