jdk/src/java.base/share/classes/java/nio/X-Buffer.java.template
author bpb
Fri, 24 Jul 2015 11:52:30 -0700
changeset 31873 87b015c2cd36
parent 31723 2e16a59cc5cb
child 32143 394ab6a6658d
permissions -rw-r--r--
8065556: (bf) Buffer.position and other methods should include detail in IAE Summary: Add messages to IAEs which have none. Reviewed-by: alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
31723
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
     2
 * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4502
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4502
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4502
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4502
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4502
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#warn This file is preprocessed before being compiled
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
package java.nio;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#if[char]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#end[char]
17922
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 14342
diff changeset
    33
#if[streamableType]
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 14342
diff changeset
    34
import java.util.Spliterator;
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 14342
diff changeset
    35
import java.util.stream.StreamSupport;
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 14342
diff changeset
    36
import java.util.stream.$Streamtype$Stream;
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 14342
diff changeset
    37
#end[streamableType]
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
/**
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
    40
 * $A$ $type$ buffer.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <p> This class defines {#if[byte]?six:four} categories of operations upon
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
    43
 * $type$ buffers:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *
18574
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18164
diff changeset
    47
 *   <li><p> Absolute and relative {@link #get() <i>get</i>} and
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18164
diff changeset
    48
 *   {@link #put($type$) <i>put</i>} methods that read and write
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
    49
 *   single $type$s; </p></li>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *
18574
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18164
diff changeset
    51
 *   <li><p> Relative {@link #get($type$[]) <i>bulk get</i>}
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
    52
 *   methods that transfer contiguous sequences of $type$s from this buffer
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *   into an array; {#if[!byte]?and}</p></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *
18574
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18164
diff changeset
    55
 *   <li><p> Relative {@link #put($type$[]) <i>bulk put</i>}
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
    56
 *   methods that transfer contiguous sequences of $type$s from $a$
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
    57
 *   $type$ array{#if[char]?,&#32;a&#32;string,} or some other $type$
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *   buffer into this buffer;{#if[!byte]?&#32;and} </p></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
#if[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *
18574
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18164
diff changeset
    62
 *   <li><p> Absolute and relative {@link #getChar() <i>get</i>}
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18164
diff changeset
    63
 *   and {@link #putChar(char) <i>put</i>} methods that read and
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *   write values of other primitive types, translating them to and from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *   sequences of bytes in a particular byte order; </p></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *   <li><p> Methods for creating <i><a href="#views">view buffers</a></i>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *   which allow a byte buffer to be viewed as a buffer containing values of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *   some other primitive type; and </p></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
#end[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *
18574
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18164
diff changeset
    73
 *   <li><p> Methods for {@link #compact compacting}, {@link
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18164
diff changeset
    74
 *   #duplicate duplicating}, and {@link #slice slicing}
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18164
diff changeset
    75
 *   $a$ $type$ buffer.  </p></li>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 *
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
    79
 * <p> $Type$ buffers can be created either by {@link #allocate
18574
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18164
diff changeset
    80
 * <i>allocation</i>}, which allocates space for the buffer's
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
#if[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 *
18574
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18164
diff changeset
    84
 * content, or by {@link #wrap($type$[]) <i>wrapping</i>} an
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
    85
 * existing $type$ array {#if[char]?or&#32;string} into a buffer.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
#else[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 *
18574
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18164
diff changeset
    89
 * content, by {@link #wrap($type$[]) <i>wrapping</i>} an existing
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
    90
 * $type$ array {#if[char]?or&#32;string} into a buffer, or by creating a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * <a href="ByteBuffer.html#views"><i>view</i></a> of an existing byte buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
#end[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
#if[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 *
18574
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18164
diff changeset
    97
 * <a name="direct"></a>
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18164
diff changeset
    98
 * <h2> Direct <i>vs.</i> non-direct buffers </h2>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * <p> A byte buffer is either <i>direct</i> or <i>non-direct</i>.  Given a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * direct byte buffer, the Java virtual machine will make a best effort to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * perform native I/O operations directly upon it.  That is, it will attempt to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * avoid copying the buffer's content to (or from) an intermediate buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * before (or after) each invocation of one of the underlying operating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * system's native I/O operations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * <p> A direct byte buffer may be created by invoking the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * #allocateDirect(int) allocateDirect} factory method of this class.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * buffers returned by this method typically have somewhat higher allocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * and deallocation costs than non-direct buffers.  The contents of direct
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * buffers may reside outside of the normal garbage-collected heap, and so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * their impact upon the memory footprint of an application might not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * obvious.  It is therefore recommended that direct buffers be allocated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * primarily for large, long-lived buffers that are subject to the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * system's native I/O operations.  In general it is best to allocate direct
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * buffers only when they yield a measureable gain in program performance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * <p> A direct byte buffer may also be created by {@link
18574
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18164
diff changeset
   119
 * java.nio.channels.FileChannel#map mapping} a region of a file
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * directly into memory.  An implementation of the Java platform may optionally
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * support the creation of direct byte buffers from native code via JNI.  If an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * instance of one of these kinds of buffers refers to an inaccessible region
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * of memory then an attempt to access that region will not change the buffer's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * content and will cause an unspecified exception to be thrown either at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 * time of the access or at some later time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 * <p> Whether a byte buffer is direct or non-direct may be determined by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 * invoking its {@link #isDirect isDirect} method.  This method is provided so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 * that explicit buffer management can be done in performance-critical code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 *
18574
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18164
diff changeset
   132
 * <a name="bin"></a>
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18164
diff changeset
   133
 * <h2> Access to binary data </h2>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 * <p> This class defines methods for reading and writing values of all other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 * primitive types, except <tt>boolean</tt>.  Primitive values are translated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 * to (or from) sequences of bytes according to the buffer's current byte
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 * order, which may be retrieved and modified via the {@link #order order}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 * methods.  Specific byte orders are represented by instances of the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 * ByteOrder} class.  The initial order of a byte buffer is always {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * ByteOrder#BIG_ENDIAN BIG_ENDIAN}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * <p> For access to heterogeneous binary data, that is, sequences of values of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * different types, this class defines a family of absolute and relative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 * <i>get</i> and <i>put</i> methods for each type.  For 32-bit floating-point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 * values, for example, this class defines:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 * float  {@link #getFloat()}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 * float  {@link #getFloat(int) getFloat(int index)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 *  void  {@link #putFloat(float) putFloat(float f)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
 *  void  {@link #putFloat(int,float) putFloat(int index, float f)}</pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 * <p> Corresponding methods are defined for the types <tt>char</tt>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 * <tt>short</tt>, <tt>int</tt>, <tt>long</tt>, and <tt>double</tt>.  The index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
 * parameters of the absolute <i>get</i> and <i>put</i> methods are in terms of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
 * bytes rather than of the type being read or written.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
 *
18574
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18164
diff changeset
   159
 * <a name="views"></a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
 * <p> For access to homogeneous binary data, that is, sequences of values of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
 * the same type, this class defines methods that can create <i>views</i> of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 * given byte buffer.  A <i>view buffer</i> is simply another buffer whose
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
 * content is backed by the byte buffer.  Changes to the byte buffer's content
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
 * will be visible in the view buffer, and vice versa; the two buffers'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
 * position, limit, and mark values are independent.  The {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
 * #asFloatBuffer() asFloatBuffer} method, for example, creates an instance of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
 * the {@link FloatBuffer} class that is backed by the byte buffer upon which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
 * the method is invoked.  Corresponding view-creation methods are defined for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
 * the types <tt>char</tt>, <tt>short</tt>, <tt>int</tt>, <tt>long</tt>, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
 * <tt>double</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
 * <p> View buffers have three important advantages over the families of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
 * type-specific <i>get</i> and <i>put</i> methods described above:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
 *   <li><p> A view buffer is indexed not in terms of bytes but rather in terms
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
 *   of the type-specific size of its values;  </p></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
 *   <li><p> A view buffer provides relative bulk <i>get</i> and <i>put</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
 *   methods that can transfer contiguous sequences of values between a buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
 *   and an array or some other buffer of the same type; and  </p></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
 *   <li><p> A view buffer is potentially much more efficient because it will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
 *   be direct if, and only if, its backing byte buffer is direct.  </p></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
 * <p> The byte order of a view buffer is fixed to be that of its byte buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
 * at the time that the view is created.  </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
#end[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
#if[!byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
 *
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   197
 * <p> Like a byte buffer, $a$ $type$ buffer is either <a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
 * href="ByteBuffer.html#direct"><i>direct</i> or <i>non-direct</i></a>.  A
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   199
 * $type$ buffer created via the <tt>wrap</tt> methods of this class will
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   200
 * be non-direct.  $A$ $type$ buffer created as a view of a byte buffer will
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
 * be direct if, and only if, the byte buffer itself is direct.  Whether or not
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   202
 * $a$ $type$ buffer is direct may be determined by invoking the {@link
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
 * #isDirect isDirect} method.  </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
#end[!byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
#if[char]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
 * <p> This class implements the {@link CharSequence} interface so that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
 * character buffers may be used wherever character sequences are accepted, for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
 * example in the regular-expression package <tt>{@link java.util.regex}</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
 * </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
#end[char]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
#if[byte]
18574
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18164
diff changeset
   217
 * <h2> Invocation chaining </h2>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
#end[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
 * <p> Methods in this class that do not otherwise have a value to return are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
 * specified to return the buffer upon which they are invoked.  This allows
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
 * method invocations to be chained.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
#if[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
 * The sequence of statements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
 * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
 * bb.putInt(0xCAFEBABE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
 * bb.putShort(3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
 * bb.putShort(45);</pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
 * can, for example, be replaced by the single statement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
 * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
 * bb.putInt(0xCAFEBABE).putShort(3).putShort(45);</pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
#end[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
#if[char]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
 * The sequence of statements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
 * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
 * cb.put("text/");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
 * cb.put(subtype);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
 * cb.put("; charset=");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
 * cb.put(enc);</pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
 * can, for example, be replaced by the single statement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
 * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
 * cb.put("text/").put(subtype).put("; charset=").put(enc);</pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
#end[char]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
 * @author Mark Reinhold
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
 * @author JSR-51 Expert Group
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
public abstract class $Type$Buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    extends Buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    implements Comparable<$Type$Buffer>{#if[char]?, Appendable, CharSequence, Readable}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    // These fields are declared here rather than in Heap-X-Buffer in order to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    // reduce the number of virtual method invocations needed to access these
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    // values, which is especially costly when coding small buffers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    final $type$[] hb;                  // Non-null only for heap buffers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    final int offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    boolean isReadOnly;                 // Valid only for heap buffers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    // Creates a new buffer with the given mark, position, limit, capacity,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    // backing array, and array offset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    $Type$Buffer(int mark, int pos, int lim, int cap,   // package-private
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                 $type$[] hb, int offset)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        super(mark, pos, lim, cap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        this.hb = hb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        this.offset = offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    // Creates a new buffer with the given mark, position, limit, and capacity
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    $Type$Buffer(int mark, int pos, int lim, int cap) { // package-private
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        this(mark, pos, lim, cap, null, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
#if[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    /**
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   295
     * Allocates a new direct $type$ buffer.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * <p> The new buffer's position will be zero, its limit will be its
31723
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   298
     * capacity, its mark will be undefined, each of its elements will be
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   299
     * initialized to zero, and its byte order will be
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   300
     * {@link ByteOrder#BIG_ENDIAN BIG_ENDIAN}.  Whether or not it has a
18574
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18164
diff changeset
   301
     * {@link #hasArray backing array} is unspecified.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * @param  capacity
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   304
     *         The new buffer's capacity, in $type$s
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     *
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   306
     * @return  The new $type$ buffer
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * @throws  IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     *          If the <tt>capacity</tt> is a negative integer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    public static $Type$Buffer allocateDirect(int capacity) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        return new Direct$Type$Buffer(capacity);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
#end[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    /**
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   318
     * Allocates a new $type$ buffer.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * <p> The new buffer's position will be zero, its limit will be its
31723
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   321
     * capacity, its mark will be undefined, each of its elements will be
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   322
     * initialized to zero, and its byte order will be
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   323
#if[byte]
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   324
     * {@link ByteOrder#BIG_ENDIAN BIG_ENDIAN}.
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   325
#else[byte]
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   326
     * the {@link ByteOrder#nativeOrder native order} of the underlying
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   327
     * hardware.
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   328
#end[byte]
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   329
     * It will have a {@link #array backing array}, and its
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   330
     * {@link #arrayOffset array offset} will be zero.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * @param  capacity
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   333
     *         The new buffer's capacity, in $type$s
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     *
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   335
     * @return  The new $type$ buffer
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * @throws  IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     *          If the <tt>capacity</tt> is a negative integer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    public static $Type$Buffer allocate(int capacity) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        if (capacity < 0)
31873
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 31723
diff changeset
   342
            throw createCapacityException(capacity);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        return new Heap$Type$Buffer(capacity, capacity);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    /**
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   347
     * Wraps $a$ $type$ array into a buffer.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     *
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   349
     * <p> The new buffer will be backed by the given $type$ array;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * that is, modifications to the buffer will cause the array to be modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * and vice versa.  The new buffer's capacity will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * <tt>array.length</tt>, its position will be <tt>offset</tt>, its limit
31723
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   353
     * will be <tt>offset + length</tt>, its mark will be undefined, and its
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   354
     * byte order will be
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   355
#if[byte]
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   356
     * {@link ByteOrder#BIG_ENDIAN BIG_ENDIAN}.
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   357
#else[byte]
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   358
     * the {@link ByteOrder#nativeOrder native order} of the underlying
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   359
     * hardware.
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   360
#end[byte]
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   361
     * Its {@link #array backing array} will be the given array, and
18574
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18164
diff changeset
   362
     * its {@link #arrayOffset array offset} will be zero.  </p>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * @param  array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     *         The array that will back the new buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * @param  offset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     *         The offset of the subarray to be used; must be non-negative and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     *         no larger than <tt>array.length</tt>.  The new buffer's position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     *         will be set to this value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * @param  length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     *         The length of the subarray to be used;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     *         must be non-negative and no larger than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     *         <tt>array.length - offset</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     *         The new buffer's limit will be set to <tt>offset + length</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     *
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   378
     * @return  The new $type$ buffer
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * @throws  IndexOutOfBoundsException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     *          If the preconditions on the <tt>offset</tt> and <tt>length</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     *          parameters do not hold
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    public static $Type$Buffer wrap($type$[] array,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                                    int offset, int length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            return new Heap$Type$Buffer(array, offset, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        } catch (IllegalArgumentException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            throw new IndexOutOfBoundsException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    /**
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   395
     * Wraps $a$ $type$ array into a buffer.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     *
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   397
     * <p> The new buffer will be backed by the given $type$ array;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * that is, modifications to the buffer will cause the array to be modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * and vice versa.  The new buffer's capacity and limit will be
31723
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   400
     * <tt>array.length</tt>, its position will be zero, its mark will be
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   401
     * undefined, and its byte order will be
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   402
#if[byte]
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   403
     * {@link ByteOrder#BIG_ENDIAN BIG_ENDIAN}.
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   404
#else[byte]
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   405
     * the {@link ByteOrder#nativeOrder native order} of the underlying
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   406
     * hardware.
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   407
#end[byte]
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   408
     * Its {@link #array backing array} will be the given array, and its
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   409
     * {@link #arrayOffset array offset} will be zero.  </p>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * @param  array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     *         The array that will back this buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     *
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   414
     * @return  The new $type$ buffer
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    public static $Type$Buffer wrap($type$[] array) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        return wrap(array, 0, array.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
#if[char]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * Attempts to read characters into the specified character buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * The buffer is used as a repository of characters as-is: the only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * changes made are the results of a put operation. No flipping or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * rewinding of the buffer is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * @param target the buffer to read characters into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * @return The number of characters added to the buffer, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     *         -1 if this source of characters is at its end
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * @throws IOException if an I/O error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * @throws NullPointerException if target is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * @throws ReadOnlyBufferException if target is a read only buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    public int read(CharBuffer target) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        // Determine the number of bytes n that can be transferred
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        int targetRemaining = target.remaining();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        int remaining = remaining();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        if (remaining == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        int n = Math.min(remaining, targetRemaining);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        int limit = limit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        // Set source limit to prevent target overflow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        if (targetRemaining < remaining)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            limit(position() + n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            if (n > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                target.put(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            limit(limit); // restore real limit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        return n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * Wraps a character sequence into a buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * <p> The content of the new, read-only buffer will be the content of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * given character sequence.  The buffer's capacity will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * <tt>csq.length()</tt>, its position will be <tt>start</tt>, its limit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * will be <tt>end</tt>, and its mark will be undefined.  </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * @param  csq
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     *         The character sequence from which the new character buffer is to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     *         be created
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * @param  start
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     *         The index of the first character to be used;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     *         must be non-negative and no larger than <tt>csq.length()</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     *         The new buffer's position will be set to this value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * @param  end
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     *         The index of the character following the last character to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     *         used; must be no smaller than <tt>start</tt> and no larger
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     *         than <tt>csq.length()</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     *         The new buffer's limit will be set to this value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * @return  The new character buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * @throws  IndexOutOfBoundsException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     *          If the preconditions on the <tt>start</tt> and <tt>end</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     *          parameters do not hold
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    public static CharBuffer wrap(CharSequence csq, int start, int end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
            return new StringCharBuffer(csq, start, end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        } catch (IllegalArgumentException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            throw new IndexOutOfBoundsException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * Wraps a character sequence into a buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * <p> The content of the new, read-only buffer will be the content of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * given character sequence.  The new buffer's capacity and limit will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * <tt>csq.length()</tt>, its position will be zero, and its mark will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * undefined.  </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * @param  csq
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     *         The character sequence from which the new character buffer is to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     *         be created
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * @return  The new character buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    public static CharBuffer wrap(CharSequence csq) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        return wrap(csq, 0, csq.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
#end[char]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    /**
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   514
     * Creates a new $type$ buffer whose content is a shared subsequence of
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * this buffer's content.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * <p> The content of the new buffer will start at this buffer's current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * position.  Changes to this buffer's content will be visible in the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * buffer, and vice versa; the two buffers' position, limit, and mark
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * values will be independent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * <p> The new buffer's position will be zero, its capacity and its limit
31723
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   523
     * will be the number of $type$s remaining in this buffer, its mark will be
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   524
     * undefined, and its byte order will be
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   525
#if[byte]
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   526
     * {@link ByteOrder#BIG_ENDIAN BIG_ENDIAN}.
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   527
#else[byte]
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   528
     * identical to that of this buffer.
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   529
#end[byte]
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   530
     * The new buffer will be direct if, and only if, this buffer is direct, and
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   531
     * it will be read-only if, and only if, this buffer is read-only.  </p>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     *
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   533
     * @return  The new $type$ buffer
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    public abstract $Type$Buffer slice();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    /**
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   538
     * Creates a new $type$ buffer that shares this buffer's content.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * <p> The content of the new buffer will be that of this buffer.  Changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     * to this buffer's content will be visible in the new buffer, and vice
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     * versa; the two buffers' position, limit, and mark values will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * independent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     *
31723
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   545
     * <p> The new buffer's capacity, limit, position,
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   546
#if[byte]
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   547
     * and mark values will be identical to those of this buffer, and its byte
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   548
     * order will be {@link ByteOrder#BIG_ENDIAN BIG_ENDIAN}.
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   549
#else[byte]
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   550
     * mark values, and byte order will be identical to those of this buffer.
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   551
#end[byte]
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   552
     * The new buffer will be direct if, and only if, this buffer is direct, and
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   553
     * it will be read-only if, and only if, this buffer is read-only.  </p>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     *
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   555
     * @return  The new $type$ buffer
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    public abstract $Type$Buffer duplicate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    /**
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   560
     * Creates a new, read-only $type$ buffer that shares this buffer's
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * content.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * <p> The content of the new buffer will be that of this buffer.  Changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     * to this buffer's content will be visible in the new buffer; the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * buffer itself, however, will be read-only and will not allow the shared
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     * content to be modified.  The two buffers' position, limit, and mark
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * values will be independent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     *
31723
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   569
     * <p> The new buffer's capacity, limit, position,
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   570
#if[byte]
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   571
     * and mark values will be identical to those of this buffer, and its byte
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   572
     * order will be {@link ByteOrder#BIG_ENDIAN BIG_ENDIAN}.
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   573
#else[byte]
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   574
     * mark values, and byte order will be identical to those of this buffer.
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents: 27292
diff changeset
   575
#end[byte]
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * <p> If this buffer is itself read-only then this method behaves in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * exactly the same way as the {@link #duplicate duplicate} method.  </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     *
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   580
     * @return  The new, read-only $type$ buffer
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    public abstract $Type$Buffer asReadOnlyBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    // -- Singleton get/put methods --
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    /**
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   588
     * Relative <i>get</i> method.  Reads the $type$ at this buffer's
18164
68f1bc4eadd4 8016370: javadoc warnings, unexpected </p> mostly
alanb
parents: 18156
diff changeset
   589
     * current position, and then increments the position.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     *
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   591
     * @return  The $type$ at the buffer's current position
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * @throws  BufferUnderflowException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     *          If the buffer's current position is not smaller than its limit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    public abstract $type$ get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * Relative <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     *
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   601
     * <p> Writes the given $type$ into this buffer at the current
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     * position, and then increments the position. </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     * @param  $x$
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   605
     *         The $type$ to be written
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * @return  This buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     * @throws  BufferOverflowException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     *          If this buffer's current position is not smaller than its limit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * @throws  ReadOnlyBufferException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     *          If this buffer is read-only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
    public abstract $Type$Buffer put($type$ $x$);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
    /**
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   618
     * Absolute <i>get</i> method.  Reads the $type$ at the given
18164
68f1bc4eadd4 8016370: javadoc warnings, unexpected </p> mostly
alanb
parents: 18156
diff changeset
   619
     * index.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     * @param  index
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   622
     *         The index from which the $type$ will be read
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     *
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   624
     * @return  The $type$ at the given index
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     * @throws  IndexOutOfBoundsException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     *          If <tt>index</tt> is negative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     *          or not smaller than the buffer's limit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    public abstract $type$ get(int index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
17922
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 14342
diff changeset
   632
#if[streamableType]
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 14342
diff changeset
   633
    /**
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 14342
diff changeset
   634
     * Absolute <i>get</i> method.  Reads the $type$ at the given
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 14342
diff changeset
   635
     * index without any validation of the index.
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 14342
diff changeset
   636
     *
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 14342
diff changeset
   637
     * @param  index
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 14342
diff changeset
   638
     *         The index from which the $type$ will be read
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 14342
diff changeset
   639
     *
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 14342
diff changeset
   640
     * @return  The $type$ at the given index
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 14342
diff changeset
   641
     */
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 14342
diff changeset
   642
    abstract $type$ getUnchecked(int index);   // package-private
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 14342
diff changeset
   643
#end[streamableType]
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 14342
diff changeset
   644
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     * Absolute <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     *
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   648
     * <p> Writes the given $type$ into this buffer at the given
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * index. </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     * @param  index
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   652
     *         The index at which the $type$ will be written
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * @param  $x$
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   655
     *         The $type$ value to be written
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     * @return  This buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     * @throws  IndexOutOfBoundsException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     *          If <tt>index</tt> is negative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     *          or not smaller than the buffer's limit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     * @throws  ReadOnlyBufferException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     *          If this buffer is read-only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
    public abstract $Type$Buffer put(int index, $type$ $x$);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    // -- Bulk get operations --
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     * Relative bulk <i>get</i> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     *
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   674
     * <p> This method transfers $type$s from this buffer into the given
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   675
     * destination array.  If there are fewer $type$s remaining in the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     * buffer than are required to satisfy the request, that is, if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     * <tt>length</tt>&nbsp;<tt>&gt;</tt>&nbsp;<tt>remaining()</tt>, then no
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   678
     * $type$s are transferred and a {@link BufferUnderflowException} is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     *
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   681
     * <p> Otherwise, this method copies <tt>length</tt> $type$s from this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * buffer into the given array, starting at the current position of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     * buffer and at the given offset in the array.  The position of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     * buffer is then incremented by <tt>length</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     * <p> In other words, an invocation of this method of the form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     * <tt>src.get(dst,&nbsp;off,&nbsp;len)</tt> has exactly the same effect as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     * the loop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     *
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 17922
diff changeset
   690
     * <pre>{@code
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     *     for (int i = off; i < off + len; i++)
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 17922
diff changeset
   692
     *         dst[i] = src.get():
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 17922
diff changeset
   693
     * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     *
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   695
     * except that it first checks that there are sufficient $type$s in
18164
68f1bc4eadd4 8016370: javadoc warnings, unexpected </p> mostly
alanb
parents: 18156
diff changeset
   696
     * this buffer and it is potentially much more efficient.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     * @param  dst
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   699
     *         The array into which $type$s are to be written
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     * @param  offset
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   702
     *         The offset within the array of the first $type$ to be
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     *         written; must be non-negative and no larger than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     *         <tt>dst.length</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * @param  length
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   707
     *         The maximum number of $type$s to be written to the given
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     *         array; must be non-negative and no larger than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     *         <tt>dst.length - offset</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     * @return  This buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     * @throws  BufferUnderflowException
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   714
     *          If there are fewer than <tt>length</tt> $type$s
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     *          remaining in this buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     * @throws  IndexOutOfBoundsException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     *          If the preconditions on the <tt>offset</tt> and <tt>length</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     *          parameters do not hold
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
    public $Type$Buffer get($type$[] dst, int offset, int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        checkBounds(offset, length, dst.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
        if (length > remaining())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
            throw new BufferUnderflowException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        int end = offset + length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        for (int i = offset; i < end; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
            dst[i] = get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     * Relative bulk <i>get</i> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     *
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   734
     * <p> This method transfers $type$s from this buffer into the given
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     * destination array.  An invocation of this method of the form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     * <tt>src.get(a)</tt> behaves in exactly the same way as the invocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     *     src.get(a, 0, a.length) </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     *
18574
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18164
diff changeset
   741
     * @param   dst
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18164
diff changeset
   742
     *          The destination array
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18164
diff changeset
   743
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     * @return  This buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     * @throws  BufferUnderflowException
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   747
     *          If there are fewer than <tt>length</tt> $type$s
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     *          remaining in this buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    public $Type$Buffer get($type$[] dst) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        return get(dst, 0, dst.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
    // -- Bulk put operations --
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     * Relative bulk <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     *
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   760
     * <p> This method transfers the $type$s remaining in the given source
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   761
     * buffer into this buffer.  If there are more $type$s remaining in the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
     * source buffer than in this buffer, that is, if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
     * <tt>src.remaining()</tt>&nbsp;<tt>&gt;</tt>&nbsp;<tt>remaining()</tt>,
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   764
     * then no $type$s are transferred and a {@link
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
     * BufferOverflowException} is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
     * <p> Otherwise, this method copies
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   768
     * <i>n</i>&nbsp;=&nbsp;<tt>src.remaining()</tt> $type$s from the given
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
     * buffer into this buffer, starting at each buffer's current position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
     * The positions of both buffers are then incremented by <i>n</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
     * <p> In other words, an invocation of this method of the form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
     * <tt>dst.put(src)</tt> has exactly the same effect as the loop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
     *     while (src.hasRemaining())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     *         dst.put(src.get()); </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     * except that it first checks that there is sufficient space in this
18164
68f1bc4eadd4 8016370: javadoc warnings, unexpected </p> mostly
alanb
parents: 18156
diff changeset
   780
     * buffer and it is potentially much more efficient.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     * @param  src
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   783
     *         The source buffer from which $type$s are to be read;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
     *         must not be this buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
     * @return  This buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
     * @throws  BufferOverflowException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     *          If there is insufficient space in this buffer
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   790
     *          for the remaining $type$s in the source buffer
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     * @throws  IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     *          If the source buffer is this buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     * @throws  ReadOnlyBufferException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     *          If this buffer is read-only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
    public $Type$Buffer put($Type$Buffer src) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
        if (src == this)
31873
87b015c2cd36 8065556: (bf) Buffer.position and other methods should include detail in IAE
bpb
parents: 31723
diff changeset
   800
            throw createSameBufferException();
14001
e8e8413ad49a 7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents: 13563
diff changeset
   801
        if (isReadOnly())
e8e8413ad49a 7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents: 13563
diff changeset
   802
            throw new ReadOnlyBufferException();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
        int n = src.remaining();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        if (n > remaining())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
            throw new BufferOverflowException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
        for (int i = 0; i < n; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
            put(src.get());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
     * Relative bulk <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
     *
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   814
     * <p> This method transfers $type$s into this buffer from the given
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   815
     * source array.  If there are more $type$s to be copied from the array
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     * than remain in this buffer, that is, if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
     * <tt>length</tt>&nbsp;<tt>&gt;</tt>&nbsp;<tt>remaining()</tt>, then no
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   818
     * $type$s are transferred and a {@link BufferOverflowException} is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
     * thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     *
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   821
     * <p> Otherwise, this method copies <tt>length</tt> $type$s from the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
     * given array into this buffer, starting at the given offset in the array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
     * and at the current position of this buffer.  The position of this buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
     * is then incremented by <tt>length</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
     * <p> In other words, an invocation of this method of the form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
     * <tt>dst.put(src,&nbsp;off,&nbsp;len)</tt> has exactly the same effect as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
     * the loop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
     *
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 17922
diff changeset
   830
     * <pre>{@code
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     *     for (int i = off; i < off + len; i++)
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 17922
diff changeset
   832
     *         dst.put(a[i]);
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 17922
diff changeset
   833
     * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     * except that it first checks that there is sufficient space in this
18164
68f1bc4eadd4 8016370: javadoc warnings, unexpected </p> mostly
alanb
parents: 18156
diff changeset
   836
     * buffer and it is potentially much more efficient.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
     * @param  src
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   839
     *         The array from which $type$s are to be read
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
     * @param  offset
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   842
     *         The offset within the array of the first $type$ to be read;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     *         must be non-negative and no larger than <tt>array.length</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     * @param  length
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   846
     *         The number of $type$s to be read from the given array;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     *         must be non-negative and no larger than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     *         <tt>array.length - offset</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
     * @return  This buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
     * @throws  BufferOverflowException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
     *          If there is insufficient space in this buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
     * @throws  IndexOutOfBoundsException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
     *          If the preconditions on the <tt>offset</tt> and <tt>length</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
     *          parameters do not hold
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     * @throws  ReadOnlyBufferException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     *          If this buffer is read-only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
    public $Type$Buffer put($type$[] src, int offset, int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        checkBounds(offset, length, src.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        if (length > remaining())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
            throw new BufferOverflowException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        int end = offset + length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
        for (int i = offset; i < end; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
            this.put(src[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
     * Relative bulk <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
     * <p> This method transfers the entire content of the given source
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   876
     * $type$ array into this buffer.  An invocation of this method of the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     * form <tt>dst.put(a)</tt> behaves in exactly the same way as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     * invocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
     *     dst.put(a, 0, a.length) </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
     *
18574
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18164
diff changeset
   883
     * @param   src
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18164
diff changeset
   884
     *          The source array
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18164
diff changeset
   885
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
     * @return  This buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
     * @throws  BufferOverflowException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
     *          If there is insufficient space in this buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
     * @throws  ReadOnlyBufferException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
     *          If this buffer is read-only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
    public final $Type$Buffer put($type$[] src) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        return put(src, 0, src.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
#if[char]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
     * Relative bulk <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
     *
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   903
     * <p> This method transfers $type$s from the given string into this
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   904
     * buffer.  If there are more $type$s to be copied from the string than
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
     * remain in this buffer, that is, if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
     * <tt>end&nbsp;-&nbsp;start</tt>&nbsp;<tt>&gt;</tt>&nbsp;<tt>remaining()</tt>,
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   907
     * then no $type$s are transferred and a {@link
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
     * BufferOverflowException} is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
     * <p> Otherwise, this method copies
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   911
     * <i>n</i>&nbsp;=&nbsp;<tt>end</tt>&nbsp;-&nbsp;<tt>start</tt> $type$s
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
     * from the given string into this buffer, starting at the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
     * <tt>start</tt> index and at the current position of this buffer.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
     * position of this buffer is then incremented by <i>n</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
     * <p> In other words, an invocation of this method of the form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
     * <tt>dst.put(src,&nbsp;start,&nbsp;end)</tt> has exactly the same effect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
     * as the loop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
     *
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 17922
diff changeset
   920
     * <pre>{@code
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
     *     for (int i = start; i < end; i++)
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 17922
diff changeset
   922
     *         dst.put(src.charAt(i));
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 17922
diff changeset
   923
     * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
     * except that it first checks that there is sufficient space in this
18164
68f1bc4eadd4 8016370: javadoc warnings, unexpected </p> mostly
alanb
parents: 18156
diff changeset
   926
     * buffer and it is potentially much more efficient.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
     * @param  src
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   929
     *         The string from which $type$s are to be read
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
     * @param  start
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   932
     *         The offset within the string of the first $type$ to be read;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
     *         must be non-negative and no larger than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
     *         <tt>string.length()</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
     * @param  end
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   937
     *         The offset within the string of the last $type$ to be read,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
     *         plus one; must be non-negative and no larger than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
     *         <tt>string.length()</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
     * @return  This buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
     * @throws  BufferOverflowException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
     *          If there is insufficient space in this buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
     * @throws  IndexOutOfBoundsException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
     *          If the preconditions on the <tt>start</tt> and <tt>end</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
     *          parameters do not hold
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
     * @throws  ReadOnlyBufferException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
     *          If this buffer is read-only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
    public $Type$Buffer put(String src, int start, int end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
        checkBounds(start, end - start, src.length());
14001
e8e8413ad49a 7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents: 13563
diff changeset
   955
        if (isReadOnly())
e8e8413ad49a 7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
alanb
parents: 13563
diff changeset
   956
            throw new ReadOnlyBufferException();
13563
13c8e8f0302b 7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown
luchsh
parents: 10137
diff changeset
   957
        if (end - start > remaining())
13c8e8f0302b 7190219: (bf) CharBuffer.put(String,int,int) modifies position even if BufferOverflowException thrown
luchsh
parents: 10137
diff changeset
   958
            throw new BufferOverflowException();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
        for (int i = start; i < end; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
            this.put(src.charAt(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
     * Relative bulk <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
     * <p> This method transfers the entire content of the given source string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
     * into this buffer.  An invocation of this method of the form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
     * <tt>dst.put(s)</tt> behaves in exactly the same way as the invocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
     *     dst.put(s, 0, s.length()) </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
     *
18574
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18164
diff changeset
   974
     * @param   src
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18164
diff changeset
   975
     *          The source string
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18164
diff changeset
   976
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
     * @return  This buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
     * @throws  BufferOverflowException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
     *          If there is insufficient space in this buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
     * @throws  ReadOnlyBufferException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
     *          If this buffer is read-only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
    public final $Type$Buffer put(String src) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
        return put(src, 0, src.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
#end[char]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
    // -- Other stuff --
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
    /**
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
   995
     * Tells whether or not this buffer is backed by an accessible $type$
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
     * array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
     * <p> If this method returns <tt>true</tt> then the {@link #array() array}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
     * and {@link #arrayOffset() arrayOffset} methods may safely be invoked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
     * </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
     * @return  <tt>true</tt> if, and only if, this buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
     *          is backed by an array and is not read-only
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
    public final boolean hasArray() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
        return (hb != null) && !isReadOnly;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
    /**
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
  1010
     * Returns the $type$ array that backs this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
     * buffer&nbsp;&nbsp;<i>(optional operation)</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
     * <p> Modifications to this buffer's content will cause the returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
     * array's content to be modified, and vice versa.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
     * <p> Invoke the {@link #hasArray hasArray} method before invoking this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
     * method in order to ensure that this buffer has an accessible backing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
     * array.  </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
     * @return  The array that backs this buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
     * @throws  ReadOnlyBufferException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
     *          If this buffer is backed by an array but is read-only
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
     * @throws  UnsupportedOperationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
     *          If this buffer is not backed by an accessible array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
    public final $type$[] array() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
        if (hb == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
            throw new UnsupportedOperationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
        if (isReadOnly)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
            throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
        return hb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
     * Returns the offset within this buffer's backing array of the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
     * element of the buffer&nbsp;&nbsp;<i>(optional operation)</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
     * <p> If this buffer is backed by an array then buffer position <i>p</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
     * corresponds to array index <i>p</i>&nbsp;+&nbsp;<tt>arrayOffset()</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
     * <p> Invoke the {@link #hasArray hasArray} method before invoking this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
     * method in order to ensure that this buffer has an accessible backing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
     * array.  </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
     * @return  The offset within this buffer's array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
     *          of the first element of the buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
     * @throws  ReadOnlyBufferException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
     *          If this buffer is backed by an array but is read-only
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
     * @throws  UnsupportedOperationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
     *          If this buffer is not backed by an accessible array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
    public final int arrayOffset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
        if (hb == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
            throw new UnsupportedOperationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
        if (isReadOnly)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
            throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
        return offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
27292
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1064
    // -- Covariant return type overrides
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1065
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1066
    /**
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1067
     * {@inheritDoc}
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1068
     * @since 1.9
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1069
     */
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1070
    @Override
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1071
    public
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1072
#if[!byte]
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1073
    final
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1074
#end[!byte]
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1075
    $Type$Buffer position(int newPosition) {
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1076
        super.position(newPosition);
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1077
        return this;
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1078
    }
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1079
    
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1080
    /**
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1081
     * {@inheritDoc}
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1082
     * @since 1.9
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1083
     */
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1084
    @Override
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1085
    public
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1086
#if[!byte]
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1087
    final
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1088
#end[!byte]
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1089
    $Type$Buffer limit(int newLimit) {
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1090
        super.limit(newLimit);
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1091
        return this;
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1092
    }
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1093
    
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1094
    /**
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1095
     * {@inheritDoc}
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1096
     * @since 1.9
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1097
     */
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1098
    @Override
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1099
    public 
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1100
#if[!byte]
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1101
    final
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1102
#end[!byte]
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1103
    $Type$Buffer mark() {
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1104
        super.mark();
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1105
        return this;
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1106
    }
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1107
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1108
    /**
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1109
     * {@inheritDoc}
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1110
     * @since 1.9
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1111
     */
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1112
    @Override
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1113
    public 
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1114
#if[!byte]
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1115
    final
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1116
#end[!byte]
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1117
    $Type$Buffer reset() {
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1118
        super.reset();
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1119
        return this;
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1120
    }
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1121
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1122
    /**
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1123
     * {@inheritDoc}
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1124
     * @since 1.9
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1125
     */
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1126
    @Override
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1127
    public 
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1128
#if[!byte]
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1129
    final
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1130
#end[!byte]
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1131
    $Type$Buffer clear() {
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1132
        super.clear();
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1133
        return this;
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1134
    }
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1135
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1136
    /**
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1137
     * {@inheritDoc}
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1138
     * @since 1.9
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1139
     */
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1140
    @Override
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1141
    public 
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1142
#if[!byte]
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1143
    final
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1144
#end[!byte]
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1145
    $Type$Buffer flip() {
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1146
        super.flip();
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1147
        return this;
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1148
    }
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1149
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1150
    /**
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1151
     * {@inheritDoc}
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1152
     * @since 1.9
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1153
     */
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1154
    @Override
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1155
    public 
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1156
#if[!byte]
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1157
    final
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1158
#end[!byte]
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1159
    $Type$Buffer rewind() {
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1160
        super.rewind();
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1161
        return this;
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1162
    }
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 26960
diff changeset
  1163
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
     * Compacts this buffer&nbsp;&nbsp;<i>(optional operation)</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
     *
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
  1167
     * <p> The $type$s between the buffer's current position and its limit,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
     * if any, are copied to the beginning of the buffer.  That is, the
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
  1169
     * $type$ at index <i>p</i>&nbsp;=&nbsp;<tt>position()</tt> is copied
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
  1170
     * to index zero, the $type$ at index <i>p</i>&nbsp;+&nbsp;1 is copied
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
  1171
     * to index one, and so forth until the $type$ at index
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
     * <tt>limit()</tt>&nbsp;-&nbsp;1 is copied to index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
     * <i>n</i>&nbsp;=&nbsp;<tt>limit()</tt>&nbsp;-&nbsp;<tt>1</tt>&nbsp;-&nbsp;<i>p</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
     * The buffer's position is then set to <i>n+1</i> and its limit is set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
     * its capacity.  The mark, if defined, is discarded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
     *
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
  1177
     * <p> The buffer's position is set to the number of $type$s copied,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
     * rather than to zero, so that an invocation of this method can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
     * followed immediately by an invocation of another relative <i>put</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
     * method. </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
#if[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
     * <p> Invoke this method after writing data from a buffer in case the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
     * write was incomplete.  The following loop, for example, copies bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
     * from one channel to another via the buffer <tt>buf</tt>:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
     *
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 17922
diff changeset
  1188
     * <blockquote><pre>{@code
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 17922
diff changeset
  1189
     *   buf.clear();          // Prepare buffer for use
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 17922
diff changeset
  1190
     *   while (in.read(buf) >= 0 || buf.position != 0) {
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 17922
diff changeset
  1191
     *       buf.flip();
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 17922
diff changeset
  1192
     *       out.write(buf);
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 17922
diff changeset
  1193
     *       buf.compact();    // In case of partial write
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 17922
diff changeset
  1194
     *   }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
     * }</pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
#end[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
     * @return  This buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
     * @throws  ReadOnlyBufferException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
     *          If this buffer is read-only
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
    public abstract $Type$Buffer compact();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
    /**
18164
68f1bc4eadd4 8016370: javadoc warnings, unexpected </p> mostly
alanb
parents: 18156
diff changeset
  1207
     * Tells whether or not this $type$ buffer is direct.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
     * @return  <tt>true</tt> if, and only if, this buffer is direct
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
    public abstract boolean isDirect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
#if[!char]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
    /**
18164
68f1bc4eadd4 8016370: javadoc warnings, unexpected </p> mostly
alanb
parents: 18156
diff changeset
  1216
     * Returns a string summarizing the state of this buffer.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
     * @return  A summary string
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
        StringBuffer sb = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
        sb.append(getClass().getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
        sb.append("[pos=");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
        sb.append(position());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
        sb.append(" lim=");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
        sb.append(limit());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
        sb.append(" cap=");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
        sb.append(capacity());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
        sb.append("]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
        return sb.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
#end[!char]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
    // ## Should really use unchecked accessors here for speed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
     * Returns the current hash code of this buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
     * <p> The hash code of a $type$ buffer depends only upon its remaining
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
     * elements; that is, upon the elements from <tt>position()</tt> up to, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
     * including, the element at <tt>limit()</tt>&nbsp;-&nbsp;<tt>1</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
     * <p> Because buffer hash codes are content-dependent, it is inadvisable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
     * to use buffers as keys in hash maps or similar data structures unless it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
     * is known that their contents will not change.  </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
     * @return  The current hash code of this buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
        int h = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
        int p = position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
        for (int i = limit() - 1; i >= p; i--)
10137
d92637d3d673 7068616: NIO libraries do not build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
  1255
#if[int]
d92637d3d673 7068616: NIO libraries do not build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
  1256
            h = 31 * h + get(i);
d92637d3d673 7068616: NIO libraries do not build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
  1257
#else[int]
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
            h = 31 * h + (int)get(i);
10137
d92637d3d673 7068616: NIO libraries do not build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
  1259
#end[int]
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
        return h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
     * Tells whether or not this buffer is equal to another object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
     * <p> Two $type$ buffers are equal if, and only if,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
     *
21334
c60dfce46a77 8026982: javadoc errors in core libs
rriggs
parents: 18822
diff changeset
  1268
     * <ol>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
     *   <li><p> They have the same element type,  </p></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
     *   <li><p> They have the same number of remaining elements, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
     *   </p></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
     *   <li><p> The two sequences of remaining elements, considered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
     *   independently of their starting positions, are pointwise equal.
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
  1277
#if[floatingPointType]
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
  1278
     *   This method considers two $type$ elements {@code a} and {@code b}
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
  1279
     *   to be equal if
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
  1280
     *   {@code (a == b) || ($Fulltype$.isNaN(a) && $Fulltype$.isNaN(b))}.
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
  1281
     *   The values {@code -0.0} and {@code +0.0} are considered to be
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
  1282
     *   equal, unlike {@link $Fulltype$#equals(Object)}.
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
  1283
#end[floatingPointType]
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
     *   </p></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
     * </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
     * <p> A $type$ buffer is not equal to any other type of object.  </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
     * @param  ob  The object to which this buffer is to be compared
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
     * @return  <tt>true</tt> if, and only if, this buffer is equal to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
     *           given object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
    public boolean equals(Object ob) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
        if (this == ob)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
        if (!(ob instanceof $Type$Buffer))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
        $Type$Buffer that = ($Type$Buffer)ob;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
        if (this.remaining() != that.remaining())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
        int p = this.position();
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
  1304
        for (int i = this.limit() - 1, j = that.limit() - 1; i >= p; i--, j--)
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
  1305
            if (!equals(this.get(i), that.get(j)))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
  1310
    private static boolean equals($type$ x, $type$ y) {
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
  1311
#if[floatingPointType]
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
  1312
        return (x == y) || ($Fulltype$.isNaN(x) && $Fulltype$.isNaN(y));
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
  1313
#else[floatingPointType]
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
  1314
        return x == y;
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
  1315
#end[floatingPointType]
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
  1316
    }
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
  1317
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
     * Compares this buffer to another.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
     * <p> Two $type$ buffers are compared by comparing their sequences of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
     * remaining elements lexicographically, without regard to the starting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
     * position of each sequence within its corresponding buffer.
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
  1324
#if[floatingPointType]
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
  1325
     * Pairs of {@code $type$} elements are compared as if by invoking
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
  1326
     * {@link $Fulltype$#compare($type$,$type$)}, except that
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
  1327
     * {@code -0.0} and {@code 0.0} are considered to be equal.
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
  1328
     * {@code $Fulltype$.NaN} is considered by this method to be equal
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
  1329
     * to itself and greater than all other {@code $type$} values
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
  1330
     * (including {@code $Fulltype$.POSITIVE_INFINITY}).
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
  1331
#else[floatingPointType]
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
  1332
     * Pairs of {@code $type$} elements are compared as if by invoking
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
  1333
     * {@link $Fulltype$#compare($type$,$type$)}.
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
  1334
#end[floatingPointType]
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
     * <p> A $type$ buffer is not comparable to any other type of object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
     * @return  A negative integer, zero, or a positive integer as this buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
     *          is less than, equal to, or greater than the given buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
    public int compareTo($Type$Buffer that) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
        int n = this.position() + Math.min(this.remaining(), that.remaining());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
        for (int i = this.position(), j = that.position(); i < n; i++, j++) {
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
  1344
            int cmp = compare(this.get(i), that.get(j));
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
  1345
            if (cmp != 0)
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
  1346
                return cmp;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
        return this.remaining() - that.remaining();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
  1351
    private static int compare($type$ x, $type$ y) {
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
  1352
#if[floatingPointType]
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
  1353
        return ((x < y)  ? -1 :
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
  1354
                (x > y)  ? +1 :
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
  1355
                (x == y) ?  0 :
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
  1356
                $Fulltype$.isNaN(x) ? ($Fulltype$.isNaN(y) ? 0 : +1) : -1);
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
  1357
#else[floatingPointType]
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
  1358
        return $Fulltype$.compare(x, y);
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
  1359
#end[floatingPointType]
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
  1360
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
    // -- Other char stuff --
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
#if[char]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
     * Returns a string containing the characters in this buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
     * <p> The first character of the resulting string will be the character at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
     * this buffer's position, while the last character will be the character
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
     * at index <tt>limit()</tt>&nbsp;-&nbsp;1.  Invoking this method does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
     * change the buffer's position. </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
     * @return  The specified string
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
        return toString(position(), limit());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
    abstract String toString(int start, int end);       // package-private
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
    // --- Methods to support CharSequence ---
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
     * Returns the length of this character buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
     * <p> When viewed as a character sequence, the length of a character
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
     * buffer is simply the number of characters between the position
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
     * (inclusive) and the limit (exclusive); that is, it is equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
     * <tt>remaining()</tt>. </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
     * @return  The length of this character buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
    public final int length() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
        return remaining();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
     * Reads the character at the given index relative to the current
18164
68f1bc4eadd4 8016370: javadoc warnings, unexpected </p> mostly
alanb
parents: 18156
diff changeset
  1401
     * position.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
     * @param  index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
     *         The index of the character to be read, relative to the position;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
     *         must be non-negative and smaller than <tt>remaining()</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
     * @return  The character at index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
     *          <tt>position()&nbsp;+&nbsp;index</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
     * @throws  IndexOutOfBoundsException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
     *          If the preconditions on <tt>index</tt> do not hold
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
    public final char charAt(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
        return get(position() + checkIndex(index, 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
     * Creates a new character buffer that represents the specified subsequence
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
     * of this buffer, relative to the current position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
     * <p> The new buffer will share this buffer's content; that is, if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
     * content of this buffer is mutable then modifications to one buffer will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
     * cause the other to be modified.  The new buffer's capacity will be that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
     * of this buffer, its position will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
     * <tt>position()</tt>&nbsp;+&nbsp;<tt>start</tt>, and its limit will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
     * <tt>position()</tt>&nbsp;+&nbsp;<tt>end</tt>.  The new buffer will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
     * direct if, and only if, this buffer is direct, and it will be read-only
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
     * if, and only if, this buffer is read-only.  </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
     * @param  start
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
     *         The index, relative to the current position, of the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
     *         character in the subsequence; must be non-negative and no larger
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
     *         than <tt>remaining()</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
     * @param  end
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
     *         The index, relative to the current position, of the character
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
     *         following the last character in the subsequence; must be no
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
     *         smaller than <tt>start</tt> and no larger than
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
     *         <tt>remaining()</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
     *
1224
8c1bc7c5dd00 6733145: (bf) CharBuffer.subSequence can be updated to take advantage of covariant returns
martin
parents: 2
diff changeset
  1441
     * @return  The new character buffer
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
     * @throws  IndexOutOfBoundsException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
     *          If the preconditions on <tt>start</tt> and <tt>end</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
     *          do not hold
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
     */
1224
8c1bc7c5dd00 6733145: (bf) CharBuffer.subSequence can be updated to take advantage of covariant returns
martin
parents: 2
diff changeset
  1447
    public abstract CharBuffer subSequence(int start, int end);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
    // --- Methods to support Appendable ---
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
     * Appends the specified character sequence  to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
     * buffer&nbsp;&nbsp;<i>(optional operation)</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
     * <p> An invocation of this method of the form <tt>dst.append(csq)</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
     * behaves in exactly the same way as the invocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
     *     dst.put(csq.toString()) </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
     * <p> Depending on the specification of <tt>toString</tt> for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
     * character sequence <tt>csq</tt>, the entire sequence may not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
     * appended.  For instance, invoking the {@link $Type$Buffer#toString()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
     * toString} method of a character buffer will return a subsequence whose
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
     * content depends upon the buffer's position and limit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
     * @param  csq
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
     *         The character sequence to append.  If <tt>csq</tt> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
     *         <tt>null</tt>, then the four characters <tt>"null"</tt> are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
     *         appended to this character buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
     * @return  This buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
     * @throws  BufferOverflowException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
     *          If there is insufficient space in this buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
     * @throws  ReadOnlyBufferException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
     *          If this buffer is read-only
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
     * @since  1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
    public $Type$Buffer append(CharSequence csq) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
        if (csq == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
            return put("null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
            return put(csq.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
     * Appends a subsequence of the  specified character sequence  to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
     * buffer&nbsp;&nbsp;<i>(optional operation)</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
     * <p> An invocation of this method of the form <tt>dst.append(csq, start,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
     * end)</tt> when <tt>csq</tt> is not <tt>null</tt>, behaves in exactly the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
     * same way as the invocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
     *     dst.put(csq.subSequence(start, end).toString()) </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
     * @param  csq
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
     *         The character sequence from which a subsequence will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
     *         appended.  If <tt>csq</tt> is <tt>null</tt>, then characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
     *         will be appended as if <tt>csq</tt> contained the four
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
     *         characters <tt>"null"</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
     * @return  This buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
     * @throws  BufferOverflowException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
     *          If there is insufficient space in this buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
     * @throws  IndexOutOfBoundsException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
     *          If <tt>start</tt> or <tt>end</tt> are negative, <tt>start</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
     *          is greater than <tt>end</tt>, or <tt>end</tt> is greater than
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
     *          <tt>csq.length()</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
     * @throws  ReadOnlyBufferException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
     *          If this buffer is read-only
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
     * @since  1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
    public $Type$Buffer append(CharSequence csq, int start, int end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
        CharSequence cs = (csq == null ? "null" : csq);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
        return put(cs.subSequence(start, end).toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
    /**
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
  1528
     * Appends the specified $type$  to this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
     * buffer&nbsp;&nbsp;<i>(optional operation)</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
     * <p> An invocation of this method of the form <tt>dst.append($x$)</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
     * behaves in exactly the same way as the invocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
     *     dst.put($x$) </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
     * @param  $x$
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
  1538
     *         The 16-bit $type$ to append
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
     * @return  This buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
     * @throws  BufferOverflowException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
     *          If there is insufficient space in this buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
     * @throws  ReadOnlyBufferException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
     *          If this buffer is read-only
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
     * @since  1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
    public $Type$Buffer append($type$ $x$) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
        return put($x$);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
#end[char]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
    // -- Other byte stuff: Access to binary data --
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
#if[!byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
     * Retrieves this buffer's byte order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
     *
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
  1564
     * <p> The byte order of $a$ $type$ buffer created by allocation or by
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
     * wrapping an existing <tt>$type$</tt> array is the {@link
18574
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18164
diff changeset
  1566
     * ByteOrder#nativeOrder native order} of the underlying
4502
18f387917b89 6903754: (bf) Improve floating-point buffer comparison
martin
parents: 4115
diff changeset
  1567
     * hardware.  The byte order of $a$ $type$ buffer created as a <a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
     * href="ByteBuffer.html#views">view</a> of a byte buffer is that of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
     * byte buffer at the moment that the view is created.  </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
     * @return  This buffer's byte order
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
    public abstract ByteOrder order();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
#end[!byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
#if[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
    boolean bigEndian                                   // package-private
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
        = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
    boolean nativeByteOrder                             // package-private
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
        = (Bits.byteOrder() == ByteOrder.BIG_ENDIAN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
     * Retrieves this buffer's byte order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
     * <p> The byte order is used when reading or writing multibyte values, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
     * when creating buffers that are views of this byte buffer.  The order of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
     * a newly-created byte buffer is always {@link ByteOrder#BIG_ENDIAN
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
     * BIG_ENDIAN}.  </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
     * @return  This buffer's byte order
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
    public final ByteOrder order() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
        return bigEndian ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
    /**
18164
68f1bc4eadd4 8016370: javadoc warnings, unexpected </p> mostly
alanb
parents: 18156
diff changeset
  1599
     * Modifies this buffer's byte order.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
     * @param  bo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
     *         The new byte order,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
     *         either {@link ByteOrder#BIG_ENDIAN BIG_ENDIAN}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
     *         or {@link ByteOrder#LITTLE_ENDIAN LITTLE_ENDIAN}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
     * @return  This buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
    public final $Type$Buffer order(ByteOrder bo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
        bigEndian = (bo == ByteOrder.BIG_ENDIAN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
        nativeByteOrder =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
            (bigEndian == (Bits.byteOrder() == ByteOrder.BIG_ENDIAN));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
    // Unchecked accessors, for use by ByteBufferAs-X-Buffer classes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
    abstract byte _get(int i);                          // package-private
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
    abstract void _put(int i, byte b);                  // package-private
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
    // #BIN
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
    // Binary-data access methods  for short, char, int, long, float,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
    // and double will be inserted here
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
#end[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
17922
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 14342
diff changeset
  1627
#if[streamableType]
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 14342
diff changeset
  1628
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 14342
diff changeset
  1629
#if[char]
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 14342
diff changeset
  1630
    @Override
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 14342
diff changeset
  1631
#end[char]
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 14342
diff changeset
  1632
    public $Streamtype$Stream $type$s() {
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 14342
diff changeset
  1633
        return StreamSupport.$streamtype$Stream(() -> new $Type$BufferSpliterator(this),
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 18574
diff changeset
  1634
            Buffer.SPLITERATOR_CHARACTERISTICS, false);
17922
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 14342
diff changeset
  1635
    }
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 14342
diff changeset
  1636
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 14342
diff changeset
  1637
#end[streamableType]
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 14342
diff changeset
  1638
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
}