1. /*
  2. * @(#)Direct-X-Buffer.java 1.48 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. import sun.misc.Cleaner;
  10. import sun.misc.Unsafe;
  11. import sun.nio.ch.DirectBuffer;
  12. import sun.nio.ch.FileChannelImpl;
  13. class DirectFloatBufferS
  14. extends FloatBuffer
  15. implements DirectBuffer
  16. {
  17. // Cached unsafe-access object
  18. protected static final Unsafe unsafe = Bits.unsafe();
  19. // Cached unaligned-access capability
  20. protected static final boolean unaligned = Bits.unaligned();
  21. // Base address, used in all indexing calculations
  22. // NOTE: moved up to Buffer.java for speed in JNI GetDirectBufferAddress
  23. // protected long address;
  24. // If this buffer is a view of another buffer then we keep a reference to
  25. // that buffer so that its memory isn't freed before we're done with it
  26. protected Object viewedBuffer = null;
  27. public Object viewedBuffer() {
  28. return viewedBuffer;
  29. }
  30. public Cleaner cleaner() { return null; }
  31. // For duplicates and slices
  32. //
  33. DirectFloatBufferS(DirectBuffer db, // package-private
  34. int mark, int pos, int lim, int cap,
  35. int off)
  36. {
  37. super(mark, pos, lim, cap);
  38. address = db.address() + off;
  39. viewedBuffer = db;
  40. }
  41. public FloatBuffer slice() {
  42. int pos = this.position();
  43. int lim = this.limit();
  44. assert (pos <= lim);
  45. int rem = (pos <= lim ? lim - pos : 0);
  46. int off = (pos << 2);
  47. assert (off >= 0);
  48. return new DirectFloatBufferS(this, -1, 0, rem, rem, off);
  49. }
  50. public FloatBuffer duplicate() {
  51. return new DirectFloatBufferS(this,
  52. this.markValue(),
  53. this.position(),
  54. this.limit(),
  55. this.capacity(),
  56. 0);
  57. }
  58. public FloatBuffer asReadOnlyBuffer() {
  59. return new DirectFloatBufferRS(this,
  60. this.markValue(),
  61. this.position(),
  62. this.limit(),
  63. this.capacity(),
  64. 0);
  65. }
  66. public long address() {
  67. return address;
  68. }
  69. private long ix(int i) {
  70. return address + (i << 2);
  71. }
  72. public float get() {
  73. return Float.intBitsToFloat(Bits.swap(unsafe.getInt(ix(nextGetIndex()))));
  74. }
  75. public float get(int i) {
  76. return Float.intBitsToFloat(Bits.swap(unsafe.getInt(ix(checkIndex(i)))));
  77. }
  78. public FloatBuffer get(float[] dst, int offset, int length) {
  79. if ((length << 2) > Bits.JNI_COPY_TO_ARRAY_THRESHOLD) {
  80. checkBounds(offset, length, dst.length);
  81. int pos = position();
  82. int lim = limit();
  83. assert (pos <= lim);
  84. int rem = (pos <= lim ? lim - pos : 0);
  85. if (length > rem)
  86. throw new BufferUnderflowException();
  87. if (order() != ByteOrder.nativeOrder())
  88. Bits.copyToIntArray(ix(pos), dst,
  89. offset << 2,
  90. length << 2);
  91. else
  92. Bits.copyToByteArray(ix(pos), dst,
  93. offset << 2,
  94. length << 2);
  95. position(pos + length);
  96. } else {
  97. super.get(dst, offset, length);
  98. }
  99. return this;
  100. }
  101. public FloatBuffer put(float x) {
  102. unsafe.putInt(ix(nextPutIndex()), Bits.swap(Float.floatToRawIntBits(x)));
  103. return this;
  104. }
  105. public FloatBuffer put(int i, float x) {
  106. unsafe.putInt(ix(checkIndex(i)), Bits.swap(Float.floatToRawIntBits(x)));
  107. return this;
  108. }
  109. public FloatBuffer put(FloatBuffer src) {
  110. if (src instanceof DirectFloatBufferS) {
  111. if (src == this)
  112. throw new IllegalArgumentException();
  113. DirectFloatBufferS sb = (DirectFloatBufferS)src;
  114. int spos = sb.position();
  115. int slim = sb.limit();
  116. assert (spos <= slim);
  117. int srem = (spos <= slim ? slim - spos : 0);
  118. int pos = position();
  119. int lim = limit();
  120. assert (pos <= lim);
  121. int rem = (pos <= lim ? lim - pos : 0);
  122. if (srem > rem)
  123. throw new BufferOverflowException();
  124. unsafe.copyMemory(sb.ix(spos), ix(pos), srem << 2);
  125. sb.position(spos + srem);
  126. position(pos + srem);
  127. } else if (!src.isDirect()) {
  128. int spos = src.position();
  129. int slim = src.limit();
  130. assert (spos <= slim);
  131. int srem = (spos <= slim ? slim - spos : 0);
  132. put(src.hb, src.offset + spos, srem);
  133. src.position(spos + srem);
  134. } else {
  135. super.put(src);
  136. }
  137. return this;
  138. }
  139. public FloatBuffer put(float[] src, int offset, int length) {
  140. if ((length << 2) > Bits.JNI_COPY_FROM_ARRAY_THRESHOLD) {
  141. checkBounds(offset, length, src.length);
  142. int pos = position();
  143. int lim = limit();
  144. assert (pos <= lim);
  145. int rem = (pos <= lim ? lim - pos : 0);
  146. if (length > rem)
  147. throw new BufferOverflowException();
  148. if (order() != ByteOrder.nativeOrder())
  149. Bits.copyFromIntArray(src, offset << 2,
  150. ix(pos), length << 2);
  151. else
  152. Bits.copyFromByteArray(src, offset << 2,
  153. ix(pos), length << 2);
  154. position(pos + length);
  155. } else {
  156. super.put(src, offset, length);
  157. }
  158. return this;
  159. }
  160. public FloatBuffer compact() {
  161. int pos = position();
  162. int lim = limit();
  163. assert (pos <= lim);
  164. int rem = (pos <= lim ? lim - pos : 0);
  165. unsafe.copyMemory(ix(pos), ix(0), rem << 2);
  166. position(rem);
  167. limit(capacity());
  168. return this;
  169. }
  170. public boolean isDirect() {
  171. return true;
  172. }
  173. public boolean isReadOnly() {
  174. return false;
  175. }
  176. public ByteOrder order() {
  177. return ((ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN)
  178. ? ByteOrder.LITTLE_ENDIAN : ByteOrder.BIG_ENDIAN);
  179. }
  180. }