History

Added some missing classes from java/nio, fixed some bad things

Dmitry Kabak (userdima committed 13 years ago

Commit 7d47bc81 parent b1be22084 files · +40111 −23Browse files

Showing the changes to java/pkg/java/nio/ByteBuffer.java (1 of 84 files). Show all

Unified · Split

java/pkg/java/nio/ByteBuffer.java+2046−0
@@ -0,0 +1,2046 @@
1/*
2 * Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26// -- This file was mechanically generated: Do not edit! -- //
27
28package java.nio;
29
30
31
32
33
34/**
35 * A byte buffer.
36 *
37 * <p> This class defines six categories of operations upon
38 * byte buffers:
39 *
40 * <ul>
41 *
42 * <li><p> Absolute and relative {@link #get() </code><i>get</i><code>} and
43 * {@link #put(byte) </code><i>put</i><code>} methods that read and write
44 * single bytes; </p></li>
45 *
46 * <li><p> Relative {@link #get(byte[]) </code><i>bulk get</i><code>}
47 * methods that transfer contiguous sequences of bytes from this buffer
48 * into an array; </p></li>
49 *
50 * <li><p> Relative {@link #put(byte[]) </code><i>bulk put</i><code>}
51 * methods that transfer contiguous sequences of bytes from a
52 * byte array or some other byte
53 * buffer into this buffer; </p></li>
54 *
55
56 *
57 * <li><p> Absolute and relative {@link #getChar() </code><i>get</i><code>}
58 * and {@link #putChar(char) </code><i>put</i><code>} methods that read and
59 * write values of other primitive types, translating them to and from
60 * sequences of bytes in a particular byte order; </p></li>
61 *
62 * <li><p> Methods for creating <i><a href="#views">view buffers</a></i>,
63 * which allow a byte buffer to be viewed as a buffer containing values of
64 * some other primitive type; and </p></li>
65 *
66
67 *
68 * <li><p> Methods for {@link #compact </code>compacting<code>}, {@link
69 * #duplicate </code>duplicating<code>}, and {@link #slice
70 * </code>slicing<code>} a byte buffer. </p></li>
71 *
72 * </ul>
73 *
74 * <p> Byte buffers can be created either by {@link #allocate
75 * </code><i>allocation</i><code>}, which allocates space for the buffer's
76 *
77
78 *
79 * content, or by {@link #wrap(byte[]) </code><i>wrapping</i><code>} an
80 * existing byte array into a buffer.
81 *
82
83
84
85
86
87
88
89 *
90
91 *
92 * <a name="direct">
93 * <h4> Direct <i>vs.</i> non-direct buffers </h4>
94 *
95 * <p> A byte buffer is either <i>direct</i> or <i>non-direct</i>. Given a
96 * direct byte buffer, the Java virtual machine will make a best effort to
97 * perform native I/O operations directly upon it. That is, it will attempt to
98 * avoid copying the buffer's content to (or from) an intermediate buffer
99 * before (or after) each invocation of one of the underlying operating
100 * system's native I/O operations.
101 *
102 * <p> A direct byte buffer may be created by invoking the {@link
103 * #allocateDirect(int) allocateDirect} factory method of this class. The
104 * buffers returned by this method typically have somewhat higher allocation
105 * and deallocation costs than non-direct buffers. The contents of direct
106 * buffers may reside outside of the normal garbage-collected heap, and so
107 * their impact upon the memory footprint of an application might not be
108 * obvious. It is therefore recommended that direct buffers be allocated
109 * primarily for large, long-lived buffers that are subject to the underlying
110 * system's native I/O operations. In general it is best to allocate direct
111 * buffers only when they yield a measureable gain in program performance.
112 *
113 * <p> A direct byte buffer may also be created by {@link
114 * java.nio.channels.FileChannel#map </code>mapping<code>} a region of a file
115 * directly into memory. An implementation of the Java platform may optionally
116 * support the creation of direct byte buffers from native code via JNI. If an
117 * instance of one of these kinds of buffers refers to an inaccessible region
118 * of memory then an attempt to access that region will not change the buffer's
119 * content and will cause an unspecified exception to be thrown either at the
120 * time of the access or at some later time.
121 *
122 * <p> Whether a byte buffer is direct or non-direct may be determined by
123 * invoking its {@link #isDirect isDirect} method. This method is provided so
124 * that explicit buffer management can be done in performance-critical code.
125 *
126 *
127 * <a name="bin">
128 * <h4> Access to binary data </h4>
129 *
130 * <p> This class defines methods for reading and writing values of all other
131 * primitive types, except <tt>boolean</tt>. Primitive values are translated
132 * to (or from) sequences of bytes according to the buffer's current byte
133 * order, which may be retrieved and modified via the {@link #order order}
134 * methods. Specific byte orders are represented by instances of the {@link
135 * ByteOrder} class. The initial order of a byte buffer is always {@link
136 * ByteOrder#BIG_ENDIAN BIG_ENDIAN}.
137 *
138 * <p> For access to heterogeneous binary data, that is, sequences of values of
139 * different types, this class defines a family of absolute and relative
140 * <i>get</i> and <i>put</i> methods for each type. For 32-bit floating-point
141 * values, for example, this class defines:
142 *
143 * <blockquote><pre>
144 * float {@link #getFloat()}
145 * float {@link #getFloat(int) getFloat(int index)}
146 * void {@link #putFloat(float) putFloat(float f)}
147 * void {@link #putFloat(int,float) putFloat(int index, float f)}</pre></blockquote>
148 *
149 * <p> Corresponding methods are defined for the types <tt>char</tt>,
150 * <tt>short</tt>, <tt>int</tt>, <tt>long</tt>, and <tt>double</tt>. The index
151 * parameters of the absolute <i>get</i> and <i>put</i> methods are in terms of
152 * bytes rather than of the type being read or written.
153 *
154 * <a name="views">
155 *
156 * <p> For access to homogeneous binary data, that is, sequences of values of
157 * the same type, this class defines methods that can create <i>views</i> of a
158 * given byte buffer. A <i>view buffer</i> is simply another buffer whose
159 * content is backed by the byte buffer. Changes to the byte buffer's content
160 * will be visible in the view buffer, and vice versa; the two buffers'
161 * position, limit, and mark values are independent. The {@link
162 * #asFloatBuffer() asFloatBuffer} method, for example, creates an instance of
163 * the {@link FloatBuffer} class that is backed by the byte buffer upon which
164 * the method is invoked. Corresponding view-creation methods are defined for
165 * the types <tt>char</tt>, <tt>short</tt>, <tt>int</tt>, <tt>long</tt>, and
166 * <tt>double</tt>.
167 *
168 * <p> View buffers have three important advantages over the families of
169 * type-specific <i>get</i> and <i>put</i> methods described above:
170 *
171 * <ul>
172 *
173 * <li><p> A view buffer is indexed not in terms of bytes but rather in terms
174 * of the type-specific size of its values; </p></li>
175 *
176 * <li><p> A view buffer provides relative bulk <i>get</i> and <i>put</i>
177 * methods that can transfer contiguous sequences of values between a buffer
178 * and an array or some other buffer of the same type; and </p></li>
179 *
180 * <li><p> A view buffer is potentially much more efficient because it will
181 * be direct if, and only if, its backing byte buffer is direct. </p></li>
182 *
183 * </ul>
184 *
185 * <p> The byte order of a view buffer is fixed to be that of its byte buffer
186 * at the time that the view is created. </p>
187 *
188
189*
190
191
192
193
194
195
196
197
198
199
200
201*
202
203
204
205
206
207
208
209
210 *
211
212 * <h4> Invocation chaining </h4>
213
214 *
215 * <p> Methods in this class that do not otherwise have a value to return are
216 * specified to return the buffer upon which they are invoked. This allows
217 * method invocations to be chained.
218 *
219
220 *
221 * The sequence of statements
222 *
223 * <blockquote><pre>
224 * bb.putInt(0xCAFEBABE);
225 * bb.putShort(3);
226 * bb.putShort(45);</pre></blockquote>
227 *
228 * can, for example, be replaced by the single statement
229 *
230 * <blockquote><pre>
231 * bb.putInt(0xCAFEBABE).putShort(3).putShort(45);</pre></blockquote>
232 *
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250 *
251 *
252 * @author Mark Reinhold
253 * @author JSR-51 Expert Group
254 * @since 1.4
255 */
256
257public abstract class ByteBuffer
258 extends Buffer
259 implements Comparable<ByteBuffer>
260{
261
262 // These fields are declared here rather than in Heap-X-Buffer in order to
263 // reduce the number of virtual method invocations needed to access these
264 // values, which is especially costly when coding small buffers.
265 //
266 final byte[] hb; // Non-null only for heap buffers
267 final int offset;
268 boolean isReadOnly; // Valid only for heap buffers
269
270 // Creates a new buffer with the given mark, position, limit, capacity,
271 // backing array, and array offset
272 //
273 ByteBuffer(int mark, int pos, int lim, int cap, // package-private
274 byte[] hb, int offset)
275 {
276 super(mark, pos, lim, cap);
277 this.hb = hb;
278 this.offset = offset;
279 }
280
281 // Creates a new buffer with the given mark, position, limit, and capacity
282 //
283 ByteBuffer(int mark, int pos, int lim, int cap) { // package-private
284 this(mark, pos, lim, cap, null, 0);
285 }
286
287
288
289 /**
290 * Allocates a new direct byte buffer.
291 *
292 * <p> The new buffer's position will be zero, its limit will be its
293 * capacity, its mark will be undefined, and each of its elements will be
294 * initialized to zero. Whether or not it has a
295 * {@link #hasArray </code>backing array<code>} is unspecified.
296 *
297 * @param capacity
298 * The new buffer's capacity, in bytes
299 *
300 * @return The new byte buffer
301 *
302 * @throws IllegalArgumentException
303 * If the <tt>capacity</tt> is a negative integer
304 */
305 public static ByteBuffer allocateDirect(int capacity) {
306 return new DirectByteBuffer(capacity);
307 }
308
309
310
311 /**
312 * Allocates a new byte buffer.
313 *
314 * <p> The new buffer's position will be zero, its limit will be its
315 * capacity, its mark will be undefined, and each of its elements will be
316 * initialized to zero. It will have a {@link #array
317 * </code>backing array<code>}, and its {@link #arrayOffset </code>array
318 * offset<code>} will be zero.
319 *
320 * @param capacity
321 * The new buffer's capacity, in bytes
322 *
323 * @return The new byte buffer
324 *
325 * @throws IllegalArgumentException
326 * If the <tt>capacity</tt> is a negative integer
327 */
328 public static ByteBuffer allocate(int capacity) {
329 if (capacity < 0)
330 throw new IllegalArgumentException();
331 return new HeapByteBuffer(capacity, capacity);
332 }
333
334 /**
335 * Wraps a byte array into a buffer.
336 *
337 * <p> The new buffer will be backed by the given byte array;
338 * that is, modifications to the buffer will cause the array to be modified
339 * and vice versa. The new buffer's capacity will be
340 * <tt>array.length</tt>, its position will be <tt>offset</tt>, its limit
341 * will be <tt>offset + length</tt>, and its mark will be undefined. Its
342 * {@link #array </code>backing array<code>} will be the given array, and
343 * its {@link #arrayOffset </code>array offset<code>} will be zero. </p>
344 *
345 * @param array
346 * The array that will back the new buffer
347 *
348 * @param offset
349 * The offset of the subarray to be used; must be non-negative and
350 * no larger than <tt>array.length</tt>. The new buffer's position
351 * will be set to this value.
352 *
353 * @param length
354 * The length of the subarray to be used;
355 * must be non-negative and no larger than
356 * <tt>array.length - offset</tt>.
357 * The new buffer's limit will be set to <tt>offset + length</tt>.
358 *
359 * @return The new byte buffer
360 *
361 * @throws IndexOutOfBoundsException
362 * If the preconditions on the <tt>offset</tt> and <tt>length</tt>
363 * parameters do not hold
364 */
365 public static ByteBuffer wrap(byte[] array,
366 int offset, int length)
367 {
368 try {
369 return new HeapByteBuffer(array, offset, length);
370 } catch (IllegalArgumentException x) {
371 throw new IndexOutOfBoundsException();
372 }
373 }
374
375 /**
376 * Wraps a byte array into a buffer.
377 *
378 * <p> The new buffer will be backed by the given byte array;
379 * that is, modifications to the buffer will cause the array to be modified
380 * and vice versa. The new buffer's capacity and limit will be
381 * <tt>array.length</tt>, its position will be zero, and its mark will be
382 * undefined. Its {@link #array </code>backing array<code>} will be the
383 * given array, and its {@link #arrayOffset </code>array offset<code>} will
384 * be zero. </p>
385 *
386 * @param array
387 * The array that will back this buffer
388 *
389 * @return The new byte buffer
390 */
391 public static ByteBuffer wrap(byte[] array) {
392 return wrap(array, 0, array.length);
393 }
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488 /**
489 * Creates a new byte buffer whose content is a shared subsequence of
490 * this buffer's content.
491 *
492 * <p> The content of the new buffer will start at this buffer's current
493 * position. Changes to this buffer's content will be visible in the new
494 * buffer, and vice versa; the two buffers' position, limit, and mark
495 * values will be independent.
496 *
497 * <p> The new buffer's position will be zero, its capacity and its limit
498 * will be the number of bytes remaining in this buffer, and its mark
499 * will be undefined. The new buffer will be direct if, and only if, this
500 * buffer is direct, and it will be read-only if, and only if, this buffer
501 * is read-only. </p>
502 *
503 * @return The new byte buffer
504 */
505 public abstract ByteBuffer slice();
506
507 /**
508 * Creates a new byte buffer that shares this buffer's content.
509 *
510 * <p> The content of the new buffer will be that of this buffer. Changes
511 * to this buffer's content will be visible in the new buffer, and vice
512 * versa; the two buffers' position, limit, and mark values will be
513 * independent.
514 *
515 * <p> The new buffer's capacity, limit, position, and mark values will be
516 * identical to those of this buffer. The new buffer will be direct if,
517 * and only if, this buffer is direct, and it will be read-only if, and
518 * only if, this buffer is read-only. </p>
519 *
520 * @return The new byte buffer
521 */
522 public abstract ByteBuffer duplicate();
523
524 /**
525 * Creates a new, read-only byte buffer that shares this buffer's
526 * content.
527 *
528 * <p> The content of the new buffer will be that of this buffer. Changes
529 * to this buffer's content will be visible in the new buffer; the new
530 * buffer itself, however, will be read-only and will not allow the shared
531 * content to be modified. The two buffers' position, limit, and mark
532 * values will be independent.
533 *
534 * <p> The new buffer's capacity, limit, position, and mark values will be
535 * identical to those of this buffer.
536 *
537 * <p> If this buffer is itself read-only then this method behaves in
538 * exactly the same way as the {@link #duplicate duplicate} method. </p>
539 *
540 * @return The new, read-only byte buffer
541 */
542 public abstract ByteBuffer asReadOnlyBuffer();
543
544
545 // -- Singleton get/put methods --
546
547 /**
548 * Relative <i>get</i> method. Reads the byte at this buffer's
549 * current position, and then increments the position. </p>
550 *
551 * @return The byte at the buffer's current position
552 *
553 * @throws BufferUnderflowException
554 * If the buffer's current position is not smaller than its limit
555 */
556 public abstract byte get();
557
558 /**
559 * Relative <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.
560 *
561 * <p> Writes the given byte into this buffer at the current
562 * position, and then increments the position. </p>
563 *
564 * @param b
565 * The byte to be written
566 *
567 * @return This buffer
568 *
569 * @throws BufferOverflowException
570 * If this buffer's current position is not smaller than its limit
571 *
572 * @throws ReadOnlyBufferException
573 * If this buffer is read-only
574 */
575 public abstract ByteBuffer put(byte b);
576
577 /**
578 * Absolute <i>get</i> method. Reads the byte at the given
579 * index. </p>
580 *
581 * @param index
582 * The index from which the byte will be read
583 *
584 * @return The byte at the given index
585 *
586 * @throws IndexOutOfBoundsException
587 * If <tt>index</tt> is negative
588 * or not smaller than the buffer's limit
589 */
590 public abstract byte get(int index);
591
592 /**
593 * Absolute <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.
594 *
595 * <p> Writes the given byte into this buffer at the given
596 * index. </p>
597 *
598 * @param index
599 * The index at which the byte will be written
600 *
601 * @param b
602 * The byte value to be written
603 *
604 * @return This buffer
605 *
606 * @throws IndexOutOfBoundsException
607 * If <tt>index</tt> is negative
608 * or not smaller than the buffer's limit
609 *
610 * @throws ReadOnlyBufferException
611 * If this buffer is read-only
612 */
613 public abstract ByteBuffer put(int index, byte b);
614
615
616 // -- Bulk get operations --
617
618 /**
619 * Relative bulk <i>get</i> method.
620 *
621 * <p> This method transfers bytes from this buffer into the given
622 * destination array. If there are fewer bytes remaining in the
623 * buffer than are required to satisfy the request, that is, if
624 * <tt>length</tt>&nbsp;<tt>&gt;</tt>&nbsp;<tt>remaining()</tt>, then no
625 * bytes are transferred and a {@link BufferUnderflowException} is
626 * thrown.
627 *
628 * <p> Otherwise, this method copies <tt>length</tt> bytes from this
629 * buffer into the given array, starting at the current position of this
630 * buffer and at the given offset in the array. The position of this
631 * buffer is then incremented by <tt>length</tt>.
632 *
633 * <p> In other words, an invocation of this method of the form
634 * <tt>src.get(dst,&nbsp;off,&nbsp;len)</tt> has exactly the same effect as
635 * the loop
636 *
637 * <pre>
638 * for (int i = off; i < off + len; i++)
639 * dst[i] = src.get(); </pre>
640 *
641 * except that it first checks that there are sufficient bytes in
642 * this buffer and it is potentially much more efficient. </p>
643 *
644 * @param dst
645 * The array into which bytes are to be written
646 *
647 * @param offset
648 * The offset within the array of the first byte to be
649 * written; must be non-negative and no larger than
650 * <tt>dst.length</tt>
651 *
652 * @param length
653 * The maximum number of bytes to be written to the given
654 * array; must be non-negative and no larger than
655 * <tt>dst.length - offset</tt>
656 *
657 * @return This buffer
658 *
659 * @throws BufferUnderflowException
660 * If there are fewer than <tt>length</tt> bytes
661 * remaining in this buffer
662 *
663 * @throws IndexOutOfBoundsException
664 * If the preconditions on the <tt>offset</tt> and <tt>length</tt>
665 * parameters do not hold
666 */
667 public ByteBuffer get(byte[] dst, int offset, int length) {
668 // [Inferno] <
669 //checkBounds(offset, length, dst.length);
670 // [Inferno] =
671 Buffer.checkBounds(offset, length, dst.length);
672 // [Inferno] >
673 if (length > remaining())
674 throw new BufferUnderflowException();
675 int end = offset + length;
676 for (int i = offset; i < end; i++)
677 dst[i] = get();
678 return this;
679 }
680
681 /**
682 * Relative bulk <i>get</i> method.
683 *
684 * <p> This method transfers bytes from this buffer into the given
685 * destination array. An invocation of this method of the form
686 * <tt>src.get(a)</tt> behaves in exactly the same way as the invocation
687 *
688 * <pre>
689 * src.get(a, 0, a.length) </pre>
690 *
691 * @return This buffer
692 *
693 * @throws BufferUnderflowException
694 * If there are fewer than <tt>length</tt> bytes
695 * remaining in this buffer
696 */
697 public ByteBuffer get(byte[] dst) {
698 return get(dst, 0, dst.length);
699 }
700
701
702 // -- Bulk put operations --
703
704 /**
705 * Relative bulk <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.
706 *
707 * <p> This method transfers the bytes remaining in the given source
708 * buffer into this buffer. If there are more bytes remaining in the
709 * source buffer than in this buffer, that is, if
710 * <tt>src.remaining()</tt>&nbsp;<tt>&gt;</tt>&nbsp;<tt>remaining()</tt>,
711 * then no bytes are transferred and a {@link
712 * BufferOverflowException} is thrown.
713 *
714 * <p> Otherwise, this method copies
715 * <i>n</i>&nbsp;=&nbsp;<tt>src.remaining()</tt> bytes from the given
716 * buffer into this buffer, starting at each buffer's current position.
717 * The positions of both buffers are then incremented by <i>n</i>.
718 *
719 * <p> In other words, an invocation of this method of the form
720 * <tt>dst.put(src)</tt> has exactly the same effect as the loop
721 *
722 * <pre>
723 * while (src.hasRemaining())
724 * dst.put(src.get()); </pre>
725 *
726 * except that it first checks that there is sufficient space in this
727 * buffer and it is potentially much more efficient. </p>
728 *
729 * @param src
730 * The source buffer from which bytes are to be read;
731 * must not be this buffer
732 *
733 * @return This buffer
734 *
735 * @throws BufferOverflowException
736 * If there is insufficient space in this buffer
737 * for the remaining bytes in the source buffer
738 *
739 * @throws IllegalArgumentException
740 * If the source buffer is this buffer
741 *
742 * @throws ReadOnlyBufferException
743 * If this buffer is read-only
744 */
745 public ByteBuffer put(ByteBuffer src) {
746 if (src == this)
747 throw new IllegalArgumentException();
748 int n = src.remaining();
749 if (n > remaining())
750 throw new BufferOverflowException();
751 for (int i = 0; i < n; i++)
752 put(src.get());
753 return this;
754 }
755
756 /**
757 * Relative bulk <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.
758 *
759 * <p> This method transfers bytes into this buffer from the given
760 * source array. If there are more bytes to be copied from the array
761 * than remain in this buffer, that is, if
762 * <tt>length</tt>&nbsp;<tt>&gt;</tt>&nbsp;<tt>remaining()</tt>, then no
763 * bytes are transferred and a {@link BufferOverflowException} is
764 * thrown.
765 *
766 * <p> Otherwise, this method copies <tt>length</tt> bytes from the
767 * given array into this buffer, starting at the given offset in the array
768 * and at the current position of this buffer. The position of this buffer
769 * is then incremented by <tt>length</tt>.
770 *
771 * <p> In other words, an invocation of this method of the form
772 * <tt>dst.put(src,&nbsp;off,&nbsp;len)</tt> has exactly the same effect as
773 * the loop
774 *
775 * <pre>
776 * for (int i = off; i < off + len; i++)
777 * dst.put(a[i]); </pre>
778 *
779 * except that it first checks that there is sufficient space in this
780 * buffer and it is potentially much more efficient. </p>
781 *
782 * @param src
783 * The array from which bytes are to be read
784 *
785 * @param offset
786 * The offset within the array of the first byte to be read;
787 * must be non-negative and no larger than <tt>array.length</tt>
788 *
789 * @param length
790 * The number of bytes to be read from the given array;
791 * must be non-negative and no larger than
792 * <tt>array.length - offset</tt>
793 *
794 * @return This buffer
795 *
796 * @throws BufferOverflowException
797 * If there is insufficient space in this buffer
798 *
799 * @throws IndexOutOfBoundsException
800 * If the preconditions on the <tt>offset</tt> and <tt>length</tt>
801 * parameters do not hold
802 *
803 * @throws ReadOnlyBufferException
804 * If this buffer is read-only
805 */
806 public ByteBuffer put(byte[] src, int offset, int length) {
807 // [Inferno] <
808 //checkBounds(offset, length, src.length);
809 // [Inferno] =
810 Buffer.checkBounds(offset, length, src.length);
811 // [Inferno] >
812 if (length > remaining())
813 throw new BufferOverflowException();
814 int end = offset + length;
815 for (int i = offset; i < end; i++)
816 this.put(src[i]);
817 return this;
818 }
819
820 /**
821 * Relative bulk <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.
822 *
823 * <p> This method transfers the entire content of the given source
824 * byte array into this buffer. An invocation of this method of the
825 * form <tt>dst.put(a)</tt> behaves in exactly the same way as the
826 * invocation
827 *
828 * <pre>
829 * dst.put(a, 0, a.length) </pre>
830 *
831 * @return This buffer
832 *
833 * @throws BufferOverflowException
834 * If there is insufficient space in this buffer
835 *
836 * @throws ReadOnlyBufferException
837 * If this buffer is read-only
838 */
839 public final ByteBuffer put(byte[] src) {
840 return put(src, 0, src.length);
841 }
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929 // -- Other stuff --
930
931 /**
932 * Tells whether or not this buffer is backed by an accessible byte
933 * array.
934 *
935 * <p> If this method returns <tt>true</tt> then the {@link #array() array}
936 * and {@link #arrayOffset() arrayOffset} methods may safely be invoked.
937 * </p>
938 *
939 * @return <tt>true</tt> if, and only if, this buffer
940 * is backed by an array and is not read-only
941 */
942 public final boolean hasArray() {
943 return (hb != null) && !isReadOnly;
944 }
945
946 /**
947 * Returns the byte array that backs this
948 * buffer&nbsp;&nbsp;<i>(optional operation)</i>.
949 *
950 * <p> Modifications to this buffer's content will cause the returned
951 * array's content to be modified, and vice versa.
952 *
953 * <p> Invoke the {@link #hasArray hasArray} method before invoking this
954 * method in order to ensure that this buffer has an accessible backing
955 * array. </p>
956 *
957 * @return The array that backs this buffer
958 *
959 * @throws ReadOnlyBufferException
960 * If this buffer is backed by an array but is read-only
961 *
962 * @throws UnsupportedOperationException
963 * If this buffer is not backed by an accessible array
964 */
965 public final byte[] array() {
966 if (hb == null)
967 throw new UnsupportedOperationException();
968 if (isReadOnly)
969 throw new ReadOnlyBufferException();
970 return hb;
971 }
972
973 /**
974 * Returns the offset within this buffer's backing array of the first
975 * element of the buffer&nbsp;&nbsp;<i>(optional operation)</i>.
976 *
977 * <p> If this buffer is backed by an array then buffer position <i>p</i>
978 * corresponds to array index <i>p</i>&nbsp;+&nbsp;<tt>arrayOffset()</tt>.
979 *
980 * <p> Invoke the {@link #hasArray hasArray} method before invoking this
981 * method in order to ensure that this buffer has an accessible backing
982 * array. </p>
983 *
984 * @return The offset within this buffer's array
985 * of the first element of the buffer
986 *
987 * @throws ReadOnlyBufferException
988 * If this buffer is backed by an array but is read-only
989 *
990 * @throws UnsupportedOperationException
991 * If this buffer is not backed by an accessible array
992 */
993 public final int arrayOffset() {
994 if (hb == null)
995 throw new UnsupportedOperationException();
996 if (isReadOnly)
997 throw new ReadOnlyBufferException();
998 return offset;
999 }
1000
1001 /**
1002 * Compacts this buffer&nbsp;&nbsp;<i>(optional operation)</i>.
1003 *
1004 * <p> The bytes between the buffer's current position and its limit,
1005 * if any, are copied to the beginning of the buffer. That is, the
1006 * byte at index <i>p</i>&nbsp;=&nbsp;<tt>position()</tt> is copied
1007 * to index zero, the byte at index <i>p</i>&nbsp;+&nbsp;1 is copied
1008 * to index one, and so forth until the byte at index
1009 * <tt>limit()</tt>&nbsp;-&nbsp;1 is copied to index
1010 * <i>n</i>&nbsp;=&nbsp;<tt>limit()</tt>&nbsp;-&nbsp;<tt>1</tt>&nbsp;-&nbsp;<i>p</i>.
1011 * The buffer's position is then set to <i>n+1</i> and its limit is set to
1012 * its capacity. The mark, if defined, is discarded.
1013 *
1014 * <p> The buffer's position is set to the number of bytes copied,
1015 * rather than to zero, so that an invocation of this method can be
1016 * followed immediately by an invocation of another relative <i>put</i>
1017 * method. </p>
1018 *
1019
1020 *
1021 * <p> Invoke this method after writing data from a buffer in case the
1022 * write was incomplete. The following loop, for example, copies bytes
1023 * from one channel to another via the buffer <tt>buf</tt>:
1024 *
1025 * <blockquote><pre>
1026 * buf.clear(); // Prepare buffer for use
1027 * while (in.read(buf) >= 0 || buf.position != 0) {
1028 * buf.flip();
1029 * out.write(buf);
1030 * buf.compact(); // In case of partial write
1031 * }</pre></blockquote>
1032 *
1033
1034 *
1035 * @return This buffer
1036 *
1037 * @throws ReadOnlyBufferException
1038 * If this buffer is read-only
1039 */
1040 public abstract ByteBuffer compact();
1041
1042 /**
1043 * Tells whether or not this byte buffer is direct. </p>
1044 *
1045 * @return <tt>true</tt> if, and only if, this buffer is direct
1046 */
1047 public abstract boolean isDirect();
1048
1049
1050
1051 /**
1052 * Returns a string summarizing the state of this buffer. </p>
1053 *
1054 * @return A summary string
1055 */
1056 public String toString() {
1057 StringBuffer sb = new StringBuffer();
1058 sb.append(getClass().getName());
1059 sb.append("[pos=");
1060 sb.append(position());
1061 sb.append(" lim=");
1062 sb.append(limit());
1063 sb.append(" cap=");
1064 sb.append(capacity());
1065 sb.append("]");
1066 return sb.toString();
1067 }
1068
1069
1070
1071
1072
1073
1074 /**
1075 * Returns the current hash code of this buffer.
1076 *
1077 * <p> The hash code of a byte buffer depends only upon its remaining
1078 * elements; that is, upon the elements from <tt>position()</tt> up to, and
1079 * including, the element at <tt>limit()</tt>&nbsp;-&nbsp;<tt>1</tt>.
1080 *
1081 * <p> Because buffer hash codes are content-dependent, it is inadvisable
1082 * to use buffers as keys in hash maps or similar data structures unless it
1083 * is known that their contents will not change. </p>
1084 *
1085 * @return The current hash code of this buffer
1086 */
1087 public int hashCode() {
1088 int h = 1;
1089 int p = position();
1090 for (int i = limit() - 1; i >= p; i--)
1091 h = 31 * h + (int)get(i);
1092 return h;
1093 }
1094
1095 /**
1096 * Tells whether or not this buffer is equal to another object.
1097 *
1098 * <p> Two byte buffers are equal if, and only if,
1099 *
1100 * <p><ol>
1101 *
1102 * <li><p> They have the same element type, </p></li>
1103 *
1104 * <li><p> They have the same number of remaining elements, and
1105 * </p></li>
1106 *
1107 * <li><p> The two sequences of remaining elements, considered
1108 * independently of their starting positions, are pointwise equal.
1109
1110
1111
1112
1113
1114
1115
1116 * </p></li>
1117 *
1118 * </ol>
1119 *
1120 * <p> A byte buffer is not equal to any other type of object. </p>
1121 *
1122 * @param ob The object to which this buffer is to be compared
1123 *
1124 * @return <tt>true</tt> if, and only if, this buffer is equal to the
1125 * given object
1126 */
1127 public boolean equals(Object ob) {
1128 if (this == ob)
1129 return true;
1130 if (!(ob instanceof ByteBuffer))
1131 return false;
1132 ByteBuffer that = (ByteBuffer)ob;
1133 if (this.remaining() != that.remaining())
1134 return false;
1135 int p = this.position();
1136 for (int i = this.limit() - 1, j = that.limit() - 1; i >= p; i--, j--)
1137 if (!equals(this.get(i), that.get(j)))
1138 return false;
1139 return true;
1140 }
1141
1142 private static boolean equals(byte x, byte y) {
1143
1144
1145
1146 return x == y;
1147
1148 }
1149
1150 /**
1151 * Compares this buffer to another.
1152 *
1153 * <p> Two byte buffers are compared by comparing their sequences of
1154 * remaining elements lexicographically, without regard to the starting
1155 * position of each sequence within its corresponding buffer.
1156
1157
1158
1159
1160
1161
1162
1163
1164 * Pairs of {@code byte} elements are compared as if by invoking
1165 * {@link Byte#compare(byte,byte)}.
1166
1167 *
1168 * <p> A byte buffer is not comparable to any other type of object.
1169 *
1170 * @return A negative integer, zero, or a positive integer as this buffer
1171 * is less than, equal to, or greater than the given buffer
1172 */
1173 public int compareTo(ByteBuffer that) {
1174 int n = this.position() + Math.min(this.remaining(), that.remaining());
1175 for (int i = this.position(), j = that.position(); i < n; i++, j++) {
1176 int cmp = compare(this.get(i), that.get(j));
1177 if (cmp != 0)
1178 return cmp;
1179 }
1180 return this.remaining() - that.remaining();
1181 }
1182
1183 private static int compare(byte x, byte y) {
1184
1185
1186
1187
1188
1189
1190 return Byte.compare(x, y);
1191
1192 }
1193
1194 // -- Other char stuff --
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389 // -- Other byte stuff: Access to binary data --
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411 boolean bigEndian // package-private
1412 = true;
1413 boolean nativeByteOrder // package-private
1414 = (Bits.byteOrder() == ByteOrder.BIG_ENDIAN);
1415
1416 /**
1417 * Retrieves this buffer's byte order.
1418 *
1419 * <p> The byte order is used when reading or writing multibyte values, and
1420 * when creating buffers that are views of this byte buffer. The order of
1421 * a newly-created byte buffer is always {@link ByteOrder#BIG_ENDIAN
1422 * BIG_ENDIAN}. </p>
1423 *
1424 * @return This buffer's byte order
1425 */
1426 public final ByteOrder order() {
1427 return bigEndian ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN;
1428 }
1429
1430 /**
1431 * Modifies this buffer's byte order. </p>
1432 *
1433 * @param bo
1434 * The new byte order,
1435 * either {@link ByteOrder#BIG_ENDIAN BIG_ENDIAN}
1436 * or {@link ByteOrder#LITTLE_ENDIAN LITTLE_ENDIAN}
1437 *
1438 * @return This buffer
1439 */
1440 public final ByteBuffer order(ByteOrder bo) {
1441 bigEndian = (bo == ByteOrder.BIG_ENDIAN);
1442 nativeByteOrder =
1443 (bigEndian == (Bits.byteOrder() == ByteOrder.BIG_ENDIAN));
1444 return this;
1445 }
1446
1447 // Unchecked accessors, for use by ByteBufferAs-X-Buffer classes
1448 //
1449 abstract byte _get(int i); // package-private
1450 abstract void _put(int i, byte b); // package-private
1451
1452
1453 /**
1454 * Relative <i>get</i> method for reading a char value.
1455 *
1456 * <p> Reads the next two bytes at this buffer's current position,
1457 * composing them into a char value according to the current byte order,
1458 * and then increments the position by two. </p>
1459 *
1460 * @return The char value at the buffer's current position
1461 *
1462 * @throws BufferUnderflowException
1463 * If there are fewer than two bytes
1464 * remaining in this buffer
1465 */
1466 public abstract char getChar();
1467
1468 /**
1469 * Relative <i>put</i> method for writing a char
1470 * value&nbsp;&nbsp;<i>(optional operation)</i>.
1471 *
1472 * <p> Writes two bytes containing the given char value, in the
1473 * current byte order, into this buffer at the current position, and then
1474 * increments the position by two. </p>
1475 *
1476 * @param value
1477 * The char value to be written
1478 *
1479 * @return This buffer
1480 *
1481 * @throws BufferOverflowException
1482 * If there are fewer than two bytes
1483 * remaining in this buffer
1484 *
1485 * @throws ReadOnlyBufferException
1486 * If this buffer is read-only
1487 */
1488 public abstract ByteBuffer putChar(char value);
1489
1490 /**
1491 * Absolute <i>get</i> method for reading a char value.
1492 *
1493 * <p> Reads two bytes at the given index, composing them into a
1494 * char value according to the current byte order. </p>
1495 *
1496 * @param index
1497 * The index from which the bytes will be read
1498 *
1499 * @return The char value at the given index
1500 *
1501 * @throws IndexOutOfBoundsException
1502 * If <tt>index</tt> is negative
1503 * or not smaller than the buffer's limit,
1504 * minus one
1505 */
1506 public abstract char getChar(int index);
1507
1508 /**
1509 * Absolute <i>put</i> method for writing a char
1510 * value&nbsp;&nbsp;<i>(optional operation)</i>.
1511 *
1512 * <p> Writes two bytes containing the given char value, in the
1513 * current byte order, into this buffer at the given index. </p>
1514 *
1515 * @param index
1516 * The index at which the bytes will be written
1517 *
1518 * @param value
1519 * The char value to be written
1520 *
1521 * @return This buffer
1522 *
1523 * @throws IndexOutOfBoundsException
1524 * If <tt>index</tt> is negative
1525 * or not smaller than the buffer's limit,
1526 * minus one
1527 *
1528 * @throws ReadOnlyBufferException
1529 * If this buffer is read-only
1530 */
1531 public abstract ByteBuffer putChar(int index, char value);
1532
1533 /**
1534 * Creates a view of this byte buffer as a char buffer.
1535 *
1536 * <p> The content of the new buffer will start at this buffer's current
1537 * position. Changes to this buffer's content will be visible in the new
1538 * buffer, and vice versa; the two buffers' position, limit, and mark
1539 * values will be independent.
1540 *
1541 * <p> The new buffer's position will be zero, its capacity and its limit
1542 * will be the number of bytes remaining in this buffer divided by
1543 * two, and its mark will be undefined. The new buffer will be direct
1544 * if, and only if, this buffer is direct, and it will be read-only if, and
1545 * only if, this buffer is read-only. </p>
1546 *
1547 * @return A new char buffer
1548 */
1549 public abstract CharBuffer asCharBuffer();
1550
1551
1552 /**
1553 * Relative <i>get</i> method for reading a short value.
1554 *
1555 * <p> Reads the next two bytes at this buffer's current position,
1556 * composing them into a short value according to the current byte order,
1557 * and then increments the position by two. </p>
1558 *
1559 * @return The short value at the buffer's current position
1560 *
1561 * @throws BufferUnderflowException
1562 * If there are fewer than two bytes
1563 * remaining in this buffer
1564 */
1565 public abstract short getShort();
1566
1567 /**
1568 * Relative <i>put</i> method for writing a short
1569 * value&nbsp;&nbsp;<i>(optional operation)</i>.
1570 *
1571 * <p> Writes two bytes containing the given short value, in the
1572 * current byte order, into this buffer at the current position, and then
1573 * increments the position by two. </p>
1574 *
1575 * @param value
1576 * The short value to be written
1577 *
1578 * @return This buffer
1579 *
1580 * @throws BufferOverflowException
1581 * If there are fewer than two bytes
1582 * remaining in this buffer
1583 *
1584 * @throws ReadOnlyBufferException
1585 * If this buffer is read-only
1586 */
1587 public abstract ByteBuffer putShort(short value);
1588
1589 /**
1590 * Absolute <i>get</i> method for reading a short value.
1591 *
1592 * <p> Reads two bytes at the given index, composing them into a
1593 * short value according to the current byte order. </p>
1594 *
1595 * @param index
1596 * The index from which the bytes will be read
1597 *
1598 * @return The short value at the given index
1599 *
1600 * @throws IndexOutOfBoundsException
1601 * If <tt>index</tt> is negative
1602 * or not smaller than the buffer's limit,
1603 * minus one
1604 */
1605 public abstract short getShort(int index);
1606
1607 /**
1608 * Absolute <i>put</i> method for writing a short
1609 * value&nbsp;&nbsp;<i>(optional operation)</i>.
1610 *
1611 * <p> Writes two bytes containing the given short value, in the
1612 * current byte order, into this buffer at the given index. </p>
1613 *
1614 * @param index
1615 * The index at which the bytes will be written
1616 *
1617 * @param value
1618 * The short value to be written
1619 *
1620 * @return This buffer
1621 *
1622 * @throws IndexOutOfBoundsException
1623 * If <tt>index</tt> is negative
1624 * or not smaller than the buffer's limit,
1625 * minus one
1626 *
1627 * @throws ReadOnlyBufferException
1628 * If this buffer is read-only
1629 */
1630 public abstract ByteBuffer putShort(int index, short value);
1631
1632 /**
1633 * Creates a view of this byte buffer as a short buffer.
1634 *
1635 * <p> The content of the new buffer will start at this buffer's current
1636 * position. Changes to this buffer's content will be visible in the new
1637 * buffer, and vice versa; the two buffers' position, limit, and mark
1638 * values will be independent.
1639 *
1640 * <p> The new buffer's position will be zero, its capacity and its limit
1641 * will be the number of bytes remaining in this buffer divided by
1642 * two, and its mark will be undefined. The new buffer will be direct
1643 * if, and only if, this buffer is direct, and it will be read-only if, and
1644 * only if, this buffer is read-only. </p>
1645 *
1646 * @return A new short buffer
1647 */
1648 public abstract ShortBuffer asShortBuffer();
1649
1650
1651 /**
1652 * Relative <i>get</i> method for reading an int value.
1653 *
1654 * <p> Reads the next four bytes at this buffer's current position,
1655 * composing them into an int value according to the current byte order,
1656 * and then increments the position by four. </p>
1657 *
1658 * @return The int value at the buffer's current position
1659 *
1660 * @throws BufferUnderflowException
1661 * If there are fewer than four bytes
1662 * remaining in this buffer
1663 */
1664 public abstract int getInt();
1665
1666 /**
1667 * Relative <i>put</i> method for writing an int
1668 * value&nbsp;&nbsp;<i>(optional operation)</i>.
1669 *
1670 * <p> Writes four bytes containing the given int value, in the
1671 * current byte order, into this buffer at the current position, and then
1672 * increments the position by four. </p>
1673 *
1674 * @param value
1675 * The int value to be written
1676 *
1677 * @return This buffer
1678 *
1679 * @throws BufferOverflowException
1680 * If there are fewer than four bytes
1681 * remaining in this buffer
1682 *
1683 * @throws ReadOnlyBufferException
1684 * If this buffer is read-only
1685 */
1686 public abstract ByteBuffer putInt(int value);
1687
1688 /**
1689 * Absolute <i>get</i> method for reading an int value.
1690 *
1691 * <p> Reads four bytes at the given index, composing them into a
1692 * int value according to the current byte order. </p>
1693 *
1694 * @param index
1695 * The index from which the bytes will be read
1696 *
1697 * @return The int value at the given index
1698 *
1699 * @throws IndexOutOfBoundsException
1700 * If <tt>index</tt> is negative
1701 * or not smaller than the buffer's limit,
1702 * minus three
1703 */
1704 public abstract int getInt(int index);
1705
1706 /**
1707 * Absolute <i>put</i> method for writing an int
1708 * value&nbsp;&nbsp;<i>(optional operation)</i>.
1709 *
1710 * <p> Writes four bytes containing the given int value, in the
1711 * current byte order, into this buffer at the given index. </p>
1712 *
1713 * @param index
1714 * The index at which the bytes will be written
1715 *
1716 * @param value
1717 * The int value to be written
1718 *
1719 * @return This buffer
1720 *
1721 * @throws IndexOutOfBoundsException
1722 * If <tt>index</tt> is negative
1723 * or not smaller than the buffer's limit,
1724 * minus three
1725 *
1726 * @throws ReadOnlyBufferException
1727 * If this buffer is read-only
1728 */
1729 public abstract ByteBuffer putInt(int index, int value);
1730
1731 /**
1732 * Creates a view of this byte buffer as an int buffer.
1733 *
1734 * <p> The content of the new buffer will start at this buffer's current
1735 * position. Changes to this buffer's content will be visible in the new
1736 * buffer, and vice versa; the two buffers' position, limit, and mark
1737 * values will be independent.
1738 *
1739 * <p> The new buffer's position will be zero, its capacity and its limit
1740 * will be the number of bytes remaining in this buffer divided by
1741 * four, and its mark will be undefined. The new buffer will be direct
1742 * if, and only if, this buffer is direct, and it will be read-only if, and
1743 * only if, this buffer is read-only. </p>
1744 *
1745 * @return A new int buffer
1746 */
1747 public abstract IntBuffer asIntBuffer();
1748
1749
1750 /**
1751 * Relative <i>get</i> method for reading a long value.
1752 *
1753 * <p> Reads the next eight bytes at this buffer's current position,
1754 * composing them into a long value according to the current byte order,
1755 * and then increments the position by eight. </p>
1756 *
1757 * @return The long value at the buffer's current position
1758 *
1759 * @throws BufferUnderflowException
1760 * If there are fewer than eight bytes
1761 * remaining in this buffer
1762 */
1763 public abstract long getLong();
1764
1765 /**
1766 * Relative <i>put</i> method for writing a long
1767 * value&nbsp;&nbsp;<i>(optional operation)</i>.
1768 *
1769 * <p> Writes eight bytes containing the given long value, in the
1770 * current byte order, into this buffer at the current position, and then
1771 * increments the position by eight. </p>
1772 *
1773 * @param value
1774 * The long value to be written
1775 *
1776 * @return This buffer
1777 *
1778 * @throws BufferOverflowException
1779 * If there are fewer than eight bytes
1780 * remaining in this buffer
1781 *
1782 * @throws ReadOnlyBufferException
1783 * If this buffer is read-only
1784 */
1785 public abstract ByteBuffer putLong(long value);
1786
1787 /**
1788 * Absolute <i>get</i> method for reading a long value.
1789 *
1790 * <p> Reads eight bytes at the given index, composing them into a
1791 * long value according to the current byte order. </p>
1792 *
1793 * @param index
1794 * The index from which the bytes will be read
1795 *
1796 * @return The long value at the given index
1797 *
1798 * @throws IndexOutOfBoundsException
1799 * If <tt>index</tt> is negative
1800 * or not smaller than the buffer's limit,
1801 * minus seven
1802 */
1803 public abstract long getLong(int index);
1804
1805 /**
1806 * Absolute <i>put</i> method for writing a long
1807 * value&nbsp;&nbsp;<i>(optional operation)</i>.
1808 *
1809 * <p> Writes eight bytes containing the given long value, in the
1810 * current byte order, into this buffer at the given index. </p>
1811 *
1812 * @param index
1813 * The index at which the bytes will be written
1814 *
1815 * @param value
1816 * The long value to be written
1817 *
1818 * @return This buffer
1819 *
1820 * @throws IndexOutOfBoundsException
1821 * If <tt>index</tt> is negative
1822 * or not smaller than the buffer's limit,
1823 * minus seven
1824 *
1825 * @throws ReadOnlyBufferException
1826 * If this buffer is read-only
1827 */
1828 public abstract ByteBuffer putLong(int index, long value);
1829
1830 /**
1831 * Creates a view of this byte buffer as a long buffer.
1832 *
1833 * <p> The content of the new buffer will start at this buffer's current
1834 * position. Changes to this buffer's content will be visible in the new
1835 * buffer, and vice versa; the two buffers' position, limit, and mark
1836 * values will be independent.
1837 *
1838 * <p> The new buffer's position will be zero, its capacity and its limit
1839 * will be the number of bytes remaining in this buffer divided by
1840 * eight, and its mark will be undefined. The new buffer will be direct
1841 * if, and only if, this buffer is direct, and it will be read-only if, and
1842 * only if, this buffer is read-only. </p>
1843 *
1844 * @return A new long buffer
1845 */
1846 public abstract LongBuffer asLongBuffer();
1847
1848
1849 /**
1850 * Relative <i>get</i> method for reading a float value.
1851 *
1852 * <p> Reads the next four bytes at this buffer's current position,
1853 * composing them into a float value according to the current byte order,
1854 * and then increments the position by four. </p>
1855 *
1856 * @return The float value at the buffer's current position
1857 *
1858 * @throws BufferUnderflowException
1859 * If there are fewer than four bytes
1860 * remaining in this buffer
1861 */
1862 public abstract float getFloat();
1863
1864 /**
1865 * Relative <i>put</i> method for writing a float
1866 * value&nbsp;&nbsp;<i>(optional operation)</i>.
1867 *
1868 * <p> Writes four bytes containing the given float value, in the
1869 * current byte order, into this buffer at the current position, and then
1870 * increments the position by four. </p>
1871 *
1872 * @param value
1873 * The float value to be written
1874 *
1875 * @return This buffer
1876 *
1877 * @throws BufferOverflowException
1878 * If there are fewer than four bytes
1879 * remaining in this buffer
1880 *
1881 * @throws ReadOnlyBufferException
1882 * If this buffer is read-only
1883 */
1884 public abstract ByteBuffer putFloat(float value);
1885
1886 /**
1887 * Absolute <i>get</i> method for reading a float value.
1888 *
1889 * <p> Reads four bytes at the given index, composing them into a
1890 * float value according to the current byte order. </p>
1891 *
1892 * @param index
1893 * The index from which the bytes will be read
1894 *
1895 * @return The float value at the given index
1896 *
1897 * @throws IndexOutOfBoundsException
1898 * If <tt>index</tt> is negative
1899 * or not smaller than the buffer's limit,
1900 * minus three
1901 */
1902 public abstract float getFloat(int index);
1903
1904 /**
1905 * Absolute <i>put</i> method for writing a float
1906 * value&nbsp;&nbsp;<i>(optional operation)</i>.
1907 *
1908 * <p> Writes four bytes containing the given float value, in the
1909 * current byte order, into this buffer at the given index. </p>
1910 *
1911 * @param index
1912 * The index at which the bytes will be written
1913 *
1914 * @param value
1915 * The float value to be written
1916 *
1917 * @return This buffer
1918 *
1919 * @throws IndexOutOfBoundsException
1920 * If <tt>index</tt> is negative
1921 * or not smaller than the buffer's limit,
1922 * minus three
1923 *
1924 * @throws ReadOnlyBufferException
1925 * If this buffer is read-only
1926 */
1927 public abstract ByteBuffer putFloat(int index, float value);
1928
1929 /**
1930 * Creates a view of this byte buffer as a float buffer.
1931 *
1932 * <p> The content of the new buffer will start at this buffer's current
1933 * position. Changes to this buffer's content will be visible in the new
1934 * buffer, and vice versa; the two buffers' position, limit, and mark
1935 * values will be independent.
1936 *
1937 * <p> The new buffer's position will be zero, its capacity and its limit
1938 * will be the number of bytes remaining in this buffer divided by
1939 * four, and its mark will be undefined. The new buffer will be direct
1940 * if, and only if, this buffer is direct, and it will be read-only if, and
1941 * only if, this buffer is read-only. </p>
1942 *
1943 * @return A new float buffer
1944 */
1945 public abstract FloatBuffer asFloatBuffer();
1946
1947
1948 /**
1949 * Relative <i>get</i> method for reading a double value.
1950 *
1951 * <p> Reads the next eight bytes at this buffer's current position,
1952 * composing them into a double value according to the current byte order,
1953 * and then increments the position by eight. </p>
1954 *
1955 * @return The double value at the buffer's current position
1956 *
1957 * @throws BufferUnderflowException
1958 * If there are fewer than eight bytes
1959 * remaining in this buffer
1960 */
1961 public abstract double getDouble();
1962
1963 /**
1964 * Relative <i>put</i> method for writing a double
1965 * value&nbsp;&nbsp;<i>(optional operation)</i>.
1966 *
1967 * <p> Writes eight bytes containing the given double value, in the
1968 * current byte order, into this buffer at the current position, and then
1969 * increments the position by eight. </p>
1970 *
1971 * @param value
1972 * The double value to be written
1973 *
1974 * @return This buffer
1975 *
1976 * @throws BufferOverflowException
1977 * If there are fewer than eight bytes
1978 * remaining in this buffer
1979 *
1980 * @throws ReadOnlyBufferException
1981 * If this buffer is read-only
1982 */
1983 public abstract ByteBuffer putDouble(double value);
1984
1985 /**
1986 * Absolute <i>get</i> method for reading a double value.
1987 *
1988 * <p> Reads eight bytes at the given index, composing them into a
1989 * double value according to the current byte order. </p>
1990 *
1991 * @param index
1992 * The index from which the bytes will be read
1993 *
1994 * @return The double value at the given index
1995 *
1996 * @throws IndexOutOfBoundsException
1997 * If <tt>index</tt> is negative
1998 * or not smaller than the buffer's limit,
1999 * minus seven
2000 */
2001 public abstract double getDouble(int index);
2002
2003 /**
2004 * Absolute <i>put</i> method for writing a double
2005 * value&nbsp;&nbsp;<i>(optional operation)</i>.
2006 *
2007 * <p> Writes eight bytes containing the given double value, in the
2008 * current byte order, into this buffer at the given index. </p>
2009 *
2010 * @param index
2011 * The index at which the bytes will be written
2012 *
2013 * @param value
2014 * The double value to be written
2015 *
2016 * @return This buffer
2017 *
2018 * @throws IndexOutOfBoundsException
2019 * If <tt>index</tt> is negative
2020 * or not smaller than the buffer's limit,
2021 * minus seven
2022 *
2023 * @throws ReadOnlyBufferException
2024 * If this buffer is read-only
2025 */
2026 public abstract ByteBuffer putDouble(int index, double value);
2027
2028 /**
2029 * Creates a view of this byte buffer as a double buffer.
2030 *
2031 * <p> The content of the new buffer will start at this buffer's current
2032 * position. Changes to this buffer's content will be visible in the new
2033 * buffer, and vice versa; the two buffers' position, limit, and mark
2034 * values will be independent.
2035 *
2036 * <p> The new buffer's position will be zero, its capacity and its limit
2037 * will be the number of bytes remaining in this buffer divided by
2038 * eight, and its mark will be undefined. The new buffer will be direct
2039 * if, and only if, this buffer is direct, and it will be read-only if, and
2040 * only if, this buffer is read-only. </p>
2041 *
2042 * @return A new double buffer
2043 */
2044 public abstract DoubleBuffer asDoubleBuffer();
2045
2046}