X-Buffer.java.template revision 2005
1N/A * Copyright 2000-2008 Sun Microsystems, Inc. All Rights Reserved. 1N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1N/A * This code is free software; you can redistribute it and/or modify it 1N/A * under the terms of the GNU General Public License version 2 only, as 1N/A * published by the Free Software Foundation. Sun designates this 1N/A * particular file as subject to the "Classpath" exception as provided 1N/A * by Sun in the LICENSE file that accompanied this code. 1N/A * This code is distributed in the hope that it will be useful, but WITHOUT 1N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1N/A * version 2 for more details (a copy is included in the LICENSE file that 1N/A * accompanied this code). 1N/A * You should have received a copy of the GNU General Public License version 1N/A * 2 along with this work; if not, write to the Free Software Foundation, 1N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1N/A * CA 95054 USA or visit www.sun.com if you need additional information or 1N/A * have any questions. 1N/A * $A$ $type$ buffer. 1N/A * <p> This class defines {#if[byte]?six:four} categories of operations upon 1N/A * <li><p> Absolute and relative {@link #get() </code><i>get</i><code>} and 1N/A * {@link #put($type$) </code><i>put</i><code>} methods that read and write 1N/A * single $type$s; </p></li> 1N/A * <li><p> Relative {@link #get($type$[]) </code><i>bulk get</i><code>} 1N/A * methods that transfer contiguous sequences of $type$s from this buffer 1N/A * into an array; {#if[!byte]?and}</p></li> 1N/A * <li><p> Relative {@link #put($type$[]) </code><i>bulk put</i><code>} 1N/A * methods that transfer contiguous sequences of $type$s from $a$ 1N/A * $type$ array{#if[char]?, a string,} or some other $type$ 1N/A * buffer into this buffer;{#if[!byte]? and} </p></li> 1N/A * <li><p> Absolute and relative {@link #getChar() </code><i>get</i><code>} 1N/A * and {@link #putChar(char) </code><i>put</i><code>} methods that read and 1N/A * write values of other primitive types, translating them to and from 1N/A * sequences of bytes in a particular byte order; </p></li> 1N/A * <li><p> Methods for creating <i><a href="#views">view buffers</a></i>, 1N/A * which allow a byte buffer to be viewed as a buffer containing values of 1N/A * some other primitive type; and </p></li> 1N/A * <li><p> Methods for {@link #compact </code>compacting<code>}, {@link 1N/A * #duplicate </code>duplicating<code>}, and {@link #slice 1N/A * </code>slicing<code>} $a$ $type$ buffer. </p></li> 1N/A * <p> $Type$ buffers can be created either by {@link #allocate 1N/A * </code><i>allocation</i><code>}, which allocates space for the buffer's 1N/A * content, or by {@link #wrap($type$[]) </code><i>wrapping</i><code>} an 1N/A * existing $type$ array {#if[char]?or string} into a buffer. 1N/A * content, by {@link #wrap($type$[]) </code><i>wrapping</i><code>} an existing 1N/A * $type$ array {#if[char]?or string} into a buffer, or by creating a 1N/A * <h4> Direct <i>vs.</i> non-direct buffers </h4> 1N/A * <p> A byte buffer is either <i>direct</i> or <i>non-direct</i>. Given a 1N/A * direct byte buffer, the Java virtual machine will make a best effort to 1N/A * perform native I/O operations directly upon it. That is, it will attempt to 1N/A * avoid copying the buffer's content to (or from) an intermediate buffer 1N/A * before (or after) each invocation of one of the underlying operating 1N/A * system's native I/O operations. 1N/A * <p> A direct byte buffer may be created by invoking the {@link 1N/A * #allocateDirect(int) allocateDirect} factory method of this class. The 1N/A * buffers returned by this method typically have somewhat higher allocation 1N/A * and deallocation costs than non-direct buffers. The contents of direct 1N/A * buffers may reside outside of the normal garbage-collected heap, and so 1N/A * their impact upon the memory footprint of an application might not be 1N/A * obvious. It is therefore recommended that direct buffers be allocated 1N/A * primarily for large, long-lived buffers that are subject to the underlying 1N/A * system's native I/O operations. In general it is best to allocate direct 1N/A * buffers only when they yield a measureable gain in program performance. 1N/A * <p> A direct byte buffer may also be created by {@link 1N/A * java.nio.channels.FileChannel#map </code>mapping<code>} a region of a file 1N/A * directly into memory. An implementation of the Java platform may optionally 1N/A * support the creation of direct byte buffers from native code via JNI. If an 1N/A * instance of one of these kinds of buffers refers to an inaccessible region 1N/A * of memory then an attempt to access that region will not change the buffer's 1N/A * content and will cause an unspecified exception to be thrown either at the 1N/A * time of the access or at some later time. 1N/A * <p> Whether a byte buffer is direct or non-direct may be determined by 1N/A * invoking its {@link #isDirect isDirect} method. This method is provided so 1N/A * that explicit buffer management can be done in performance-critical code. 1N/A * <h4> Access to binary data </h4> 1N/A * <p> This class defines methods for reading and writing values of all other 1N/A * primitive types, except <tt>boolean</tt>. Primitive values are translated 1N/A * to (or from) sequences of bytes according to the buffer's current byte 1N/A * order, which may be retrieved and modified via the {@link #order order} 1N/A * methods. Specific byte orders are represented by instances of the {@link 1N/A * ByteOrder} class. The initial order of a byte buffer is always {@link 1N/A * ByteOrder#BIG_ENDIAN BIG_ENDIAN}. 1N/A * <p> For access to heterogeneous binary data, that is, sequences of values of 1N/A * different types, this class defines a family of absolute and relative 1N/A * <i>get</i> and <i>put</i> methods for each type. For 32-bit floating-point 1N/A * values, for example, this class defines: * float {@link #getFloat()} * float {@link #getFloat(int) getFloat(int index)} * void {@link #putFloat(float) putFloat(float f)} * void {@link #putFloat(int,float) putFloat(int index, float f)}</pre></blockquote> * <p> Corresponding methods are defined for the types <tt>char</tt>, * <tt>short</tt>, <tt>int</tt>, <tt>long</tt>, and <tt>double</tt>. The index * parameters of the absolute <i>get</i> and <i>put</i> methods are in terms of * bytes rather than of the type being read or written. * <p> For access to homogeneous binary data, that is, sequences of values of * the same type, this class defines methods that can create <i>views</i> of a * given byte buffer. A <i>view buffer</i> is simply another buffer whose * content is backed by the byte buffer. Changes to the byte buffer's content * will be visible in the view buffer, and vice versa; the two buffers' * position, limit, and mark values are independent. The {@link * #asFloatBuffer() asFloatBuffer} method, for example, creates an instance of * the {@link FloatBuffer} class that is backed by the byte buffer upon which * the method is invoked. Corresponding view-creation methods are defined for * the types <tt>char</tt>, <tt>short</tt>, <tt>int</tt>, <tt>long</tt>, and * <p> View buffers have three important advantages over the families of * type-specific <i>get</i> and <i>put</i> methods described above: * <li><p> A view buffer is indexed not in terms of bytes but rather in terms * of the type-specific size of its values; </p></li> * <li><p> A view buffer provides relative bulk <i>get</i> and <i>put</i> * methods that can transfer contiguous sequences of values between a buffer * and an array or some other buffer of the same type; and </p></li> * <li><p> A view buffer is potentially much more efficient because it will * be direct if, and only if, its backing byte buffer is direct. </p></li> * <p> The byte order of a view buffer is fixed to be that of its byte buffer * at the time that the view is created. </p> * <p> Like a byte buffer, $a$ $type$ buffer is either <a * $type$ buffer created via the <tt>wrap</tt> methods of this class will * be non-direct. $A$ $type$ buffer created as a view of a byte buffer will * be direct if, and only if, the byte buffer itself is direct. Whether or not * $a$ $type$ buffer is direct may be determined by invoking the {@link * #isDirect isDirect} method. </p> * <p> This class implements the {@link CharSequence} interface so that * character buffers may be used wherever character sequences are accepted, for * example in the regular-expression package <tt>{@link java.util.regex}</tt>. * <h4> Invocation chaining </h4> * <p> Methods in this class that do not otherwise have a value to return are * specified to return the buffer upon which they are invoked. This allows * method invocations to be chained. * The sequence of statements * bb.putShort(45);</pre></blockquote> * can, for example, be replaced by the single statement * bb.putInt(0xCAFEBABE).putShort(3).putShort(45);</pre></blockquote> * The sequence of statements * cb.put(enc);</pre></blockquote> * can, for example, be replaced by the single statement * cb.put("text/").put(subtype).put("; charset=").put(enc);</pre></blockquote> * @author JSR-51 Expert Group // These fields are declared here rather than in Heap-X-Buffer in order to // reduce the number of virtual method invocations needed to access these // values, which is especially costly when coding small buffers. final $
type$[]
hb;
// Non-null only for heap buffers boolean isReadOnly;
// Valid only for heap buffers // Creates a new buffer with the given mark, position, limit, capacity, // backing array, and array offset // Creates a new buffer with the given mark, position, limit, and capacity * Allocates a new direct $type$ buffer. * <p> The new buffer's position will be zero, its limit will be its * capacity, its mark will be undefined, and each of its elements will be * initialized to zero. Whether or not it has a * {@link #hasArray </code>backing array<code>} is unspecified. * The new buffer's capacity, in $type$s * @return The new $type$ buffer * @throws IllegalArgumentException * If the <tt>capacity</tt> is a negative integer * Allocates a new $type$ buffer. * <p> The new buffer's position will be zero, its limit will be its * capacity, its mark will be undefined, and each of its elements will be * initialized to zero. It will have a {@link #array * </code>backing array<code>}, and its {@link #arrayOffset </code>array * offset<code>} will be zero. * The new buffer's capacity, in $type$s * @return The new $type$ buffer * @throws IllegalArgumentException * If the <tt>capacity</tt> is a negative integer * Wraps $a$ $type$ array into a buffer. * <p> The new buffer will be backed by the given $type$ array; * that is, modifications to the buffer will cause the array to be modified * and vice versa. The new buffer's capacity will be * <tt>array.length</tt>, its position will be <tt>offset</tt>, its limit * will be <tt>offset + length</tt>, and its mark will be undefined. Its * {@link #array </code>backing array<code>} will be the given array, and * its {@link #arrayOffset </code>array offset<code>} will be zero. </p> * The array that will back the new buffer * The offset of the subarray to be used; must be non-negative and * no larger than <tt>array.length</tt>. The new buffer's position * will be set to this value. * The length of the subarray to be used; * must be non-negative and no larger than * <tt>array.length - offset</tt>. * The new buffer's limit will be set to <tt>offset + length</tt>. * @return The new $type$ buffer * @throws IndexOutOfBoundsException * If the preconditions on the <tt>offset</tt> and <tt>length</tt> * Wraps $a$ $type$ array into a buffer. * <p> The new buffer will be backed by the given $type$ array; * that is, modifications to the buffer will cause the array to be modified * and vice versa. The new buffer's capacity and limit will be * <tt>array.length</tt>, its position will be zero, and its mark will be * undefined. Its {@link #array </code>backing array<code>} will be the * given array, and its {@link #arrayOffset </code>array offset<code>} will * The array that will back this buffer * @return The new $type$ buffer * Attempts to read characters into the specified character buffer. * The buffer is used as a repository of characters as-is: the only * changes made are the results of a put operation. No flipping or * rewinding of the buffer is performed. * @param target the buffer to read characters into * @return The number of characters added to the buffer, or * -1 if this source of characters is at its end * @throws IOException if an I/O error occurs * @throws NullPointerException if target is null * @throws ReadOnlyBufferException if target is a read only buffer // Determine the number of bytes n that can be transferred // Set source limit to prevent target overflow * Wraps a character sequence into a buffer. * <p> The content of the new, read-only buffer will be the content of the * given character sequence. The buffer's capacity will be * <tt>csq.length()</tt>, its position will be <tt>start</tt>, its limit * will be <tt>end</tt>, and its mark will be undefined. </p> * The character sequence from which the new character buffer is to * The index of the first character to be used; * must be non-negative and no larger than <tt>csq.length()</tt>. * The new buffer's position will be set to this value. * The index of the character following the last character to be * used; must be no smaller than <tt>start</tt> and no larger * than <tt>csq.length()</tt>. * The new buffer's limit will be set to this value. * @return The new character buffer * @throws IndexOutOfBoundsException * If the preconditions on the <tt>start</tt> and <tt>end</tt> * Wraps a character sequence into a buffer. * <p> The content of the new, read-only buffer will be the content of the * given character sequence. The new buffer's capacity and limit will be * <tt>csq.length()</tt>, its position will be zero, and its mark will be * The character sequence from which the new character buffer is to * @return The new character buffer * Creates a new $type$ buffer whose content is a shared subsequence of * <p> The content of the new buffer will start at this buffer's current * position. Changes to this buffer's content will be visible in the new * buffer, and vice versa; the two buffers' position, limit, and mark * values will be independent. * <p> The new buffer's position will be zero, its capacity and its limit * will be the number of $type$s remaining in this buffer, and its mark * will be undefined. The new buffer will be direct if, and only if, this * buffer is direct, and it will be read-only if, and only if, this buffer * @return The new $type$ buffer * Creates a new $type$ buffer that shares this buffer's content. * <p> The content of the new buffer will be that of this buffer. Changes * to this buffer's content will be visible in the new buffer, and vice * versa; the two buffers' position, limit, and mark values will be * <p> The new buffer's capacity, limit, position, and mark values will be * identical to those of this buffer. The new buffer will be direct if, * and only if, this buffer is direct, and it will be read-only if, and * only if, this buffer is read-only. </p> * @return The new $type$ buffer * Creates a new, read-only $type$ buffer that shares this buffer's * <p> The content of the new buffer will be that of this buffer. Changes * to this buffer's content will be visible in the new buffer; the new * buffer itself, however, will be read-only and will not allow the shared * content to be modified. The two buffers' position, limit, and mark * values will be independent. * <p> The new buffer's capacity, limit, position, and mark values will be * identical to those of this buffer. * <p> If this buffer is itself read-only then this method behaves in * exactly the same way as the {@link #duplicate duplicate} method. </p> * @return The new, read-only $type$ buffer // -- Singleton get/put methods -- * Relative <i>get</i> method. Reads the $type$ at this buffer's * current position, and then increments the position. </p> * @return The $type$ at the buffer's current position * @throws BufferUnderflowException * If the buffer's current position is not smaller than its limit * Relative <i>put</i> method <i>(optional operation)</i>. * <p> Writes the given $type$ into this buffer at the current * position, and then increments the position. </p> * The $type$ to be written * @throws BufferOverflowException * If this buffer's current position is not smaller than its limit * @throws ReadOnlyBufferException * If this buffer is read-only * Absolute <i>get</i> method. Reads the $type$ at the given * The index from which the $type$ will be read * @return The $type$ at the given index * @throws IndexOutOfBoundsException * If <tt>index</tt> is negative * or not smaller than the buffer's limit * Absolute <i>put</i> method <i>(optional operation)</i>. * <p> Writes the given $type$ into this buffer at the given * The index at which the $type$ will be written * The $type$ value to be written * @throws IndexOutOfBoundsException * If <tt>index</tt> is negative * or not smaller than the buffer's limit * @throws ReadOnlyBufferException * If this buffer is read-only // -- Bulk get operations -- * Relative bulk <i>get</i> method. * <p> This method transfers $type$s from this buffer into the given * destination array. If there are fewer $type$s remaining in the * buffer than are required to satisfy the request, that is, if * <tt>length</tt> <tt>></tt> <tt>remaining()</tt>, then no * $type$s are transferred and a {@link BufferUnderflowException} is * <p> Otherwise, this method copies <tt>length</tt> $type$s from this * buffer into the given array, starting at the current position of this * buffer and at the given offset in the array. The position of this * buffer is then incremented by <tt>length</tt>. * <p> In other words, an invocation of this method of the form * <tt>src.get(dst, off, len)</tt> has exactly the same effect as * for (int i = off; i < off + len; i++) * dst[i] = src.get(); </pre> * except that it first checks that there are sufficient $type$s in * this buffer and it is potentially much more efficient. </p> * The array into which $type$s are to be written * The offset within the array of the first $type$ to be * written; must be non-negative and no larger than * The maximum number of $type$s to be written to the given * array; must be non-negative and no larger than * <tt>dst.length - offset</tt> * @throws BufferUnderflowException * If there are fewer than <tt>length</tt> $type$s * remaining in this buffer * @throws IndexOutOfBoundsException * If the preconditions on the <tt>offset</tt> and <tt>length</tt> * Relative bulk <i>get</i> method. * <p> This method transfers $type$s from this buffer into the given * destination array. An invocation of this method of the form * <tt>src.get(a)</tt> behaves in exactly the same way as the invocation * src.get(a, 0, a.length) </pre> * @throws BufferUnderflowException * If there are fewer than <tt>length</tt> $type$s * remaining in this buffer // -- Bulk put operations -- * Relative bulk <i>put</i> method <i>(optional operation)</i>. * <p> This method transfers the $type$s remaining in the given source * buffer into this buffer. If there are more $type$s remaining in the * source buffer than in this buffer, that is, if * <tt>src.remaining()</tt> <tt>></tt> <tt>remaining()</tt>, * then no $type$s are transferred and a {@link * BufferOverflowException} is thrown. * <p> Otherwise, this method copies * <i>n</i> = <tt>src.remaining()</tt> $type$s from the given * buffer into this buffer, starting at each buffer's current position. * The positions of both buffers are then incremented by <i>n</i>. * <p> In other words, an invocation of this method of the form * <tt>dst.put(src)</tt> has exactly the same effect as the loop * while (src.hasRemaining()) * dst.put(src.get()); </pre> * except that it first checks that there is sufficient space in this * buffer and it is potentially much more efficient. </p> * The source buffer from which $type$s are to be read; * must not be this buffer * @throws BufferOverflowException * If there is insufficient space in this buffer * for the remaining $type$s in the source buffer * @throws IllegalArgumentException * If the source buffer is this buffer * @throws ReadOnlyBufferException * If this buffer is read-only for (
int i =
0; i < n; i++)
* Relative bulk <i>put</i> method <i>(optional operation)</i>. * <p> This method transfers $type$s into this buffer from the given * source array. If there are more $type$s to be copied from the array * than remain in this buffer, that is, if * <tt>length</tt> <tt>></tt> <tt>remaining()</tt>, then no * $type$s are transferred and a {@link BufferOverflowException} is * <p> Otherwise, this method copies <tt>length</tt> $type$s from the * given array into this buffer, starting at the given offset in the array * and at the current position of this buffer. The position of this buffer * is then incremented by <tt>length</tt>. * <p> In other words, an invocation of this method of the form * <tt>dst.put(src, off, len)</tt> has exactly the same effect as * for (int i = off; i < off + len; i++) * except that it first checks that there is sufficient space in this * buffer and it is potentially much more efficient. </p> * The array from which $type$s are to be read * The offset within the array of the first $type$ to be read; * must be non-negative and no larger than <tt>array.length</tt> * The number of $type$s to be read from the given array; * must be non-negative and no larger than * <tt>array.length - offset</tt> * @throws BufferOverflowException * If there is insufficient space in this buffer * @throws IndexOutOfBoundsException * If the preconditions on the <tt>offset</tt> and <tt>length</tt> * @throws ReadOnlyBufferException * If this buffer is read-only * Relative bulk <i>put</i> method <i>(optional operation)</i>. * <p> This method transfers the entire content of the given source * $type$ array into this buffer. An invocation of this method of the * form <tt>dst.put(a)</tt> behaves in exactly the same way as the * dst.put(a, 0, a.length) </pre> * @throws BufferOverflowException * If there is insufficient space in this buffer * @throws ReadOnlyBufferException * If this buffer is read-only * Relative bulk <i>put</i> method <i>(optional operation)</i>. * <p> This method transfers $type$s from the given string into this * buffer. If there are more $type$s to be copied from the string than * remain in this buffer, that is, if * <tt>end - start</tt> <tt>></tt> <tt>remaining()</tt>, * then no $type$s are transferred and a {@link * BufferOverflowException} is thrown. * <p> Otherwise, this method copies * <i>n</i> = <tt>end</tt> - <tt>start</tt> $type$s * from the given string into this buffer, starting at the given * <tt>start</tt> index and at the current position of this buffer. The * position of this buffer is then incremented by <i>n</i>. * <p> In other words, an invocation of this method of the form * <tt>dst.put(src, start, end)</tt> has exactly the same effect * for (int i = start; i < end; i++) * dst.put(src.charAt(i)); </pre> * except that it first checks that there is sufficient space in this * buffer and it is potentially much more efficient. </p> * The string from which $type$s are to be read * The offset within the string of the first $type$ to be read; * must be non-negative and no larger than * <tt>string.length()</tt> * The offset within the string of the last $type$ to be read, * plus one; must be non-negative and no larger than * <tt>string.length()</tt> * @throws BufferOverflowException * If there is insufficient space in this buffer * @throws IndexOutOfBoundsException * If the preconditions on the <tt>start</tt> and <tt>end</tt> * @throws ReadOnlyBufferException * If this buffer is read-only * Relative bulk <i>put</i> method <i>(optional operation)</i>. * <p> This method transfers the entire content of the given source string * into this buffer. An invocation of this method of the form * <tt>dst.put(s)</tt> behaves in exactly the same way as the invocation * dst.put(s, 0, s.length()) </pre> * @throws BufferOverflowException * If there is insufficient space in this buffer * @throws ReadOnlyBufferException * If this buffer is read-only * Tells whether or not this buffer is backed by an accessible $type$ * <p> If this method returns <tt>true</tt> then the {@link #array() array} * and {@link #arrayOffset() arrayOffset} methods may safely be invoked. * @return <tt>true</tt> if, and only if, this buffer * is backed by an array and is not read-only * Returns the $type$ array that backs this * buffer <i>(optional operation)</i>. * <p> Modifications to this buffer's content will cause the returned * array's content to be modified, and vice versa. * <p> Invoke the {@link #hasArray hasArray} method before invoking this * method in order to ensure that this buffer has an accessible backing * @return The array that backs this buffer * @throws ReadOnlyBufferException * If this buffer is backed by an array but is read-only * @throws UnsupportedOperationException * If this buffer is not backed by an accessible array * Returns the offset within this buffer's backing array of the first * element of the buffer <i>(optional operation)</i>. * <p> If this buffer is backed by an array then buffer position <i>p</i> * corresponds to array index <i>p</i> + <tt>arrayOffset()</tt>. * <p> Invoke the {@link #hasArray hasArray} method before invoking this * method in order to ensure that this buffer has an accessible backing * @return The offset within this buffer's array * of the first element of the buffer * @throws ReadOnlyBufferException * If this buffer is backed by an array but is read-only * @throws UnsupportedOperationException * If this buffer is not backed by an accessible array * Compacts this buffer <i>(optional operation)</i>. * <p> The $type$s between the buffer's current position and its limit, * if any, are copied to the beginning of the buffer. That is, the * $type$ at index <i>p</i> = <tt>position()</tt> is copied * to index zero, the $type$ at index <i>p</i> + 1 is copied * to index one, and so forth until the $type$ at index * <tt>limit()</tt> - 1 is copied to index * <i>n</i> = <tt>limit()</tt> - <tt>1</tt> - <i>p</i>. * The buffer's position is then set to <i>n+1</i> and its limit is set to * its capacity. The mark, if defined, is discarded. * <p> The buffer's position is set to the number of $type$s copied, * rather than to zero, so that an invocation of this method can be * followed immediately by an invocation of another relative <i>put</i> * <p> Invoke this method after writing data from a buffer in case the * write was incomplete. The following loop, for example, copies bytes * from one channel to another via the buffer <tt>buf</tt>: * buf.clear(); // Prepare buffer for use * while (in.read(buf) >= 0 || buf.position != 0) { * buf.compact(); // In case of partial write * @throws ReadOnlyBufferException * If this buffer is read-only * Tells whether or not this $type$ buffer is direct. </p> * @return <tt>true</tt> if, and only if, this buffer is direct * Returns a string summarizing the state of this buffer. </p> * @return A summary string // ## Should really use unchecked accessors here for speed * Returns the current hash code of this buffer. * <p> The hash code of a $type$ buffer depends only upon its remaining * elements; that is, upon the elements from <tt>position()</tt> up to, and * including, the element at <tt>limit()</tt> - <tt>1</tt>. * <p> Because buffer hash codes are content-dependent, it is inadvisable * to use buffers as keys in hash maps or similar data structures unless it * is known that their contents will not change. </p> * @return The current hash code of this buffer for (
int i =
limit() -
1; i >= p; i--)
h =
31 * h + (
int)
get(i);
* Tells whether or not this buffer is equal to another object. * <p> Two $type$ buffers are equal if, and only if, * <li><p> They have the same element type, </p></li> * <li><p> They have the same number of remaining elements, and * <li><p> The two sequences of remaining elements, considered * independently of their starting positions, are pointwise equal. * This method considers two $type$ elements {@code a} and {@code b} * {@code (a == b) || ($Fulltype$.isNaN(a) && $Fulltype$.isNaN(b))}. * The values {@code -0.0} and {@code +0.0} are considered to be * equal, unlike {@link $Fulltype$#equals(Object)}. * <p> A $type$ buffer is not equal to any other type of object. </p> * @param ob The object to which this buffer is to be compared * @return <tt>true</tt> if, and only if, this buffer is equal to the for (
int i =
this.
limit() -
1, j =
that.
limit() -
1; i >= p; i--, j--)
* Compares this buffer to another. * <p> Two $type$ buffers are compared by comparing their sequences of * remaining elements lexicographically, without regard to the starting * position of each sequence within its corresponding buffer. * Pairs of {@code $type$} elements are compared as if by invoking * {@link $Fulltype$#compare($type$,$type$)}, except that * {@code -0.0} and {@code 0.0} are considered to be equal. * {@code $Fulltype$.NaN} is considered by this method to be equal * to itself and greater than all other {@code $type$} values * (including {@code $Fulltype$.POSITIVE_INFINITY}). * Pairs of {@code $type$} elements are compared as if by invoking * {@link $Fulltype$#compare($type$,$type$)}. * <p> A $type$ buffer is not comparable to any other type of object. * @return A negative integer, zero, or a positive integer as this buffer * is less than, equal to, or greater than the given buffer // -- Other char stuff -- * Returns a string containing the characters in this buffer. * <p> The first character of the resulting string will be the character at * this buffer's position, while the last character will be the character * at index <tt>limit()</tt> - 1. Invoking this method does not * change the buffer's position. </p> * @return The specified string // --- Methods to support CharSequence --- * Returns the length of this character buffer. * <p> When viewed as a character sequence, the length of a character * buffer is simply the number of characters between the position * (inclusive) and the limit (exclusive); that is, it is equivalent to * <tt>remaining()</tt>. </p> * @return The length of this character buffer * Reads the character at the given index relative to the current * The index of the character to be read, relative to the position; * must be non-negative and smaller than <tt>remaining()</tt> * @return The character at index * <tt>position() + index</tt> * @throws IndexOutOfBoundsException * If the preconditions on <tt>index</tt> do not hold * Creates a new character buffer that represents the specified subsequence * of this buffer, relative to the current position. * <p> The new buffer will share this buffer's content; that is, if the * content of this buffer is mutable then modifications to one buffer will * cause the other to be modified. The new buffer's capacity will be that * of this buffer, its position will be * <tt>position()</tt> + <tt>start</tt>, and its limit will be * <tt>position()</tt> + <tt>end</tt>. The new buffer will be * direct if, and only if, this buffer is direct, and it will be read-only * if, and only if, this buffer is read-only. </p> * The index, relative to the current position, of the first * character in the subsequence; must be non-negative and no larger * than <tt>remaining()</tt> * The index, relative to the current position, of the character * following the last character in the subsequence; must be no * smaller than <tt>start</tt> and no larger than * @return The new character buffer * @throws IndexOutOfBoundsException * If the preconditions on <tt>start</tt> and <tt>end</tt> // --- Methods to support Appendable --- * Appends the specified character sequence to this * buffer <i>(optional operation)</i>. * <p> An invocation of this method of the form <tt>dst.append(csq)</tt> * behaves in exactly the same way as the invocation * dst.put(csq.toString()) </pre> * <p> Depending on the specification of <tt>toString</tt> for the * character sequence <tt>csq</tt>, the entire sequence may not be * appended. For instance, invoking the {@link $Type$Buffer#toString() * toString} method of a character buffer will return a subsequence whose * content depends upon the buffer's position and limit. * The character sequence to append. If <tt>csq</tt> is * <tt>null</tt>, then the four characters <tt>"null"</tt> are * appended to this character buffer. * @throws BufferOverflowException * If there is insufficient space in this buffer * @throws ReadOnlyBufferException * If this buffer is read-only * Appends a subsequence of the specified character sequence to this * buffer <i>(optional operation)</i>. * <p> An invocation of this method of the form <tt>dst.append(csq, start, * end)</tt> when <tt>csq</tt> is not <tt>null</tt>, behaves in exactly the * same way as the invocation * dst.put(csq.subSequence(start, end).toString()) </pre> * The character sequence from which a subsequence will be * appended. If <tt>csq</tt> is <tt>null</tt>, then characters * will be appended as if <tt>csq</tt> contained the four * characters <tt>"null"</tt>. * @throws BufferOverflowException * If there is insufficient space in this buffer * @throws IndexOutOfBoundsException * If <tt>start</tt> or <tt>end</tt> are negative, <tt>start</tt> * is greater than <tt>end</tt>, or <tt>end</tt> is greater than * @throws ReadOnlyBufferException * If this buffer is read-only * Appends the specified $type$ to this * buffer <i>(optional operation)</i>. * <p> An invocation of this method of the form <tt>dst.append($x$)</tt> * behaves in exactly the same way as the invocation * The 16-bit $type$ to append * @throws BufferOverflowException * If there is insufficient space in this buffer * @throws ReadOnlyBufferException * If this buffer is read-only // -- Other byte stuff: Access to binary data -- * Retrieves this buffer's byte order. * <p> The byte order of $a$ $type$ buffer created by allocation or by * wrapping an existing <tt>$type$</tt> array is the {@link * ByteOrder#nativeOrder </code>native order<code>} of the underlying * hardware. The byte order of $a$ $type$ buffer created as a <a * byte buffer at the moment that the view is created. </p> * @return This buffer's byte order * Retrieves this buffer's byte order. * <p> The byte order is used when reading or writing multibyte values, and * when creating buffers that are views of this byte buffer. The order of * a newly-created byte buffer is always {@link ByteOrder#BIG_ENDIAN * @return This buffer's byte order * Modifies this buffer's byte order. </p> * either {@link ByteOrder#BIG_ENDIAN BIG_ENDIAN} * or {@link ByteOrder#LITTLE_ENDIAN LITTLE_ENDIAN} // Unchecked accessors, for use by ByteBufferAs-X-Buffer classes abstract byte _get(
int i);
// package-private abstract void _put(
int i,
byte b);
// package-private // Binary-data access methods for short, char, int, long, float, // and double will be inserted here