1. /*
  2. * @(#)ByteBufferAs-X-Buffer.java 1.17 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. class ByteBufferAsShortBufferL // package-private
  10. extends ShortBuffer
  11. {
  12. protected final ByteBuffer bb;
  13. protected final int offset;
  14. ByteBufferAsShortBufferL(ByteBuffer bb) { // package-private
  15. super(-1, 0,
  16. bb.remaining() >> 1,
  17. bb.remaining() >> 1);
  18. this.bb = bb;
  19. // enforce limit == capacity
  20. int cap = this.capacity();
  21. this.limit(cap);
  22. int pos = this.position();
  23. assert (pos <= cap);
  24. offset = pos;
  25. }
  26. ByteBufferAsShortBufferL(ByteBuffer bb,
  27. int mark, int pos, int lim, int cap,
  28. int off)
  29. {
  30. super(mark, pos, lim, cap);
  31. this.bb = bb;
  32. offset = off;
  33. }
  34. public ShortBuffer slice() {
  35. int pos = this.position();
  36. int lim = this.limit();
  37. assert (pos <= lim);
  38. int rem = (pos <= lim ? lim - pos : 0);
  39. int off = (pos << 1) + offset;
  40. assert (off >= 0);
  41. return new ByteBufferAsShortBufferL(bb, -1, 0, rem, rem, off);
  42. }
  43. public ShortBuffer duplicate() {
  44. return new ByteBufferAsShortBufferL(bb,
  45. this.markValue(),
  46. this.position(),
  47. this.limit(),
  48. this.capacity(),
  49. offset);
  50. }
  51. public ShortBuffer asReadOnlyBuffer() {
  52. return new ByteBufferAsShortBufferRL(bb,
  53. this.markValue(),
  54. this.position(),
  55. this.limit(),
  56. this.capacity(),
  57. offset);
  58. }
  59. protected int ix(int i) {
  60. return (i << 1) + offset;
  61. }
  62. public short get() {
  63. return Bits.getShortL(bb, ix(nextGetIndex()));
  64. }
  65. public short get(int i) {
  66. return Bits.getShortL(bb, ix(checkIndex(i)));
  67. }
  68. public ShortBuffer put(short x) {
  69. Bits.putShortL(bb, ix(nextPutIndex()), x);
  70. return this;
  71. }
  72. public ShortBuffer put(int i, short x) {
  73. Bits.putShortL(bb, ix(checkIndex(i)), x);
  74. return this;
  75. }
  76. public ShortBuffer compact() {
  77. int pos = position();
  78. int lim = limit();
  79. assert (pos <= lim);
  80. int rem = (pos <= lim ? lim - pos : 0);
  81. ByteBuffer db = bb.duplicate();
  82. db.limit(ix(lim));
  83. db.position(ix(0));
  84. ByteBuffer sb = db.slice();
  85. sb.position(pos << 1);
  86. sb.compact();
  87. position(rem);
  88. limit(capacity());
  89. return this;
  90. }
  91. public boolean isDirect() {
  92. return bb.isDirect();
  93. }
  94. public boolean isReadOnly() {
  95. return false;
  96. }
  97. public ByteOrder order() {
  98. return ByteOrder.LITTLE_ENDIAN;
  99. }
  100. }