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/write HeapLongBuffer.
  11. */
  12. class HeapLongBuffer
  13. extends LongBuffer
  14. {
  15. // For speed these fields are actually declared in X-Buffer;
  16. // these declarations are here as documentation
  17. /*
  18. protected final long[] hb;
  19. protected final int offset;
  20. */
  21. HeapLongBuffer(int cap, int lim) { // package-private
  22. super(-1, 0, lim, cap, new long[cap], 0);
  23. /*
  24. hb = new long[cap];
  25. offset = 0;
  26. */
  27. }
  28. HeapLongBuffer(long[] buf, int off, int len) { // package-private
  29. super(-1, off, off + len, buf.length, buf, 0);
  30. /*
  31. hb = buf;
  32. offset = 0;
  33. */
  34. }
  35. protected HeapLongBuffer(long[] buf,
  36. int mark, int pos, int lim, int cap,
  37. int off)
  38. {
  39. super(mark, pos, lim, cap, buf, off);
  40. /*
  41. hb = buf;
  42. offset = off;
  43. */
  44. }
  45. public LongBuffer slice() {
  46. return new HeapLongBuffer(hb,
  47. -1,
  48. 0,
  49. this.remaining(),
  50. this.remaining(),
  51. this.position() + offset);
  52. }
  53. public LongBuffer duplicate() {
  54. return new HeapLongBuffer(hb,
  55. this.markValue(),
  56. this.position(),
  57. this.limit(),
  58. this.capacity(),
  59. offset);
  60. }
  61. public LongBuffer asReadOnlyBuffer() {
  62. return new HeapLongBufferR(hb,
  63. this.markValue(),
  64. this.position(),
  65. this.limit(),
  66. this.capacity(),
  67. offset);
  68. }
  69. protected int ix(int i) {
  70. return i + offset;
  71. }
  72. public long get() {
  73. return hb[ix(nextGetIndex())];
  74. }
  75. public long get(int i) {
  76. return hb[ix(checkIndex(i))];
  77. }
  78. public LongBuffer get(long[] dst, int offset, int length) {
  79. checkBounds(offset, length, dst.length);
  80. if (length > remaining())
  81. throw new BufferUnderflowException();
  82. System.arraycopy(hb, ix(position()), dst, offset, length);
  83. position(position() + length);
  84. return this;
  85. }
  86. public boolean isDirect() {
  87. return false;
  88. }
  89. public boolean isReadOnly() {
  90. return false;
  91. }
  92. public LongBuffer put(long x) {
  93. hb[ix(nextPutIndex())] = x;
  94. return this;
  95. }
  96. public LongBuffer put(int i, long x) {
  97. hb[ix(checkIndex(i))] = x;
  98. return this;
  99. }
  100. public LongBuffer put(long[] src, int offset, int length) {
  101. checkBounds(offset, length, src.length);
  102. if (length > remaining())
  103. throw new BufferOverflowException();
  104. System.arraycopy(src, offset, hb, ix(position()), length);
  105. position(position() + length);
  106. return this;
  107. }
  108. public LongBuffer put(LongBuffer src) {
  109. if (src instanceof HeapLongBuffer) {
  110. if (src == this)
  111. throw new IllegalArgumentException();
  112. HeapLongBuffer sb = (HeapLongBuffer)src;
  113. int n = sb.remaining();
  114. if (n > remaining())
  115. throw new BufferOverflowException();
  116. System.arraycopy(sb.hb, sb.ix(sb.position()),
  117. hb, ix(position()), n);
  118. sb.position(sb.position() + n);
  119. position(position() + n);
  120. } else if (src.isDirect()) {
  121. int n = src.remaining();
  122. if (n > remaining())
  123. throw new BufferOverflowException();
  124. src.get(hb, ix(position()), n);
  125. position(position() + n);
  126. } else {
  127. super.put(src);
  128. }
  129. return this;
  130. }
  131. public LongBuffer compact() {
  132. System.arraycopy(hb, ix(position()), hb, ix(0), remaining());
  133. position(remaining());
  134. limit(capacity());
  135. return this;
  136. }
  137. public ByteOrder order() {
  138. return ByteOrder.nativeOrder();
  139. }
  140. }