author | bpb |
Fri, 24 Jul 2015 11:52:30 -0700 | |
changeset 31873 | 87b015c2cd36 |
parent 31723 | 2e16a59cc5cb |
child 32143 | 394ab6a6658d |
permissions | -rw-r--r-- |
2 | 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 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
#warn This file is preprocessed before being compiled |
|
27 |
||
28 |
package java.nio; |
|
29 |
||
30 |
#if[char] |
|
31 |
import java.io.IOException; |
|
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 | 38 |
|
39 |
/** |
|
4502
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
4115
diff
changeset
|
40 |
* $A$ $type$ buffer. |
2 | 41 |
* |
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 | 44 |
* |
45 |
* <ul> |
|
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 | 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 | 53 |
* into an array; {#if[!byte]?and}</p></li> |
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]?, a string,} or some other $type$ |
2 | 58 |
* buffer into this buffer;{#if[!byte]? and} </p></li> |
59 |
* |
|
60 |
#if[byte] |
|
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 | 64 |
* write values of other primitive types, translating them to and from |
65 |
* sequences of bytes in a particular byte order; </p></li> |
|
66 |
* |
|
67 |
* <li><p> Methods for creating <i><a href="#views">view buffers</a></i>, |
|
68 |
* which allow a byte buffer to be viewed as a buffer containing values of |
|
69 |
* some other primitive type; and </p></li> |
|
70 |
* |
|
71 |
#end[byte] |
|
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 | 76 |
* |
77 |
* </ul> |
|
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 | 81 |
* |
82 |
#if[byte] |
|
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 string} into a buffer. |
2 | 86 |
* |
87 |
#else[byte] |
|
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 string} into a buffer, or by creating a |
2 | 91 |
* <a href="ByteBuffer.html#views"><i>view</i></a> of an existing byte buffer. |
92 |
* |
|
93 |
#end[byte] |
|
94 |
* |
|
95 |
#if[byte] |
|
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 | 99 |
* |
100 |
* <p> A byte buffer is either <i>direct</i> or <i>non-direct</i>. Given a |
|
101 |
* direct byte buffer, the Java virtual machine will make a best effort to |
|
102 |
* perform native I/O operations directly upon it. That is, it will attempt to |
|
103 |
* avoid copying the buffer's content to (or from) an intermediate buffer |
|
104 |
* before (or after) each invocation of one of the underlying operating |
|
105 |
* system's native I/O operations. |
|
106 |
* |
|
107 |
* <p> A direct byte buffer may be created by invoking the {@link |
|
108 |
* #allocateDirect(int) allocateDirect} factory method of this class. The |
|
109 |
* buffers returned by this method typically have somewhat higher allocation |
|
110 |
* and deallocation costs than non-direct buffers. The contents of direct |
|
111 |
* buffers may reside outside of the normal garbage-collected heap, and so |
|
112 |
* their impact upon the memory footprint of an application might not be |
|
113 |
* obvious. It is therefore recommended that direct buffers be allocated |
|
114 |
* primarily for large, long-lived buffers that are subject to the underlying |
|
115 |
* system's native I/O operations. In general it is best to allocate direct |
|
116 |
* buffers only when they yield a measureable gain in program performance. |
|
117 |
* |
|
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 | 120 |
* directly into memory. An implementation of the Java platform may optionally |
121 |
* support the creation of direct byte buffers from native code via JNI. If an |
|
122 |
* instance of one of these kinds of buffers refers to an inaccessible region |
|
123 |
* of memory then an attempt to access that region will not change the buffer's |
|
124 |
* content and will cause an unspecified exception to be thrown either at the |
|
125 |
* time of the access or at some later time. |
|
126 |
* |
|
127 |
* <p> Whether a byte buffer is direct or non-direct may be determined by |
|
128 |
* invoking its {@link #isDirect isDirect} method. This method is provided so |
|
129 |
* that explicit buffer management can be done in performance-critical code. |
|
130 |
* |
|
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 | 134 |
* |
135 |
* <p> This class defines methods for reading and writing values of all other |
|
136 |
* primitive types, except <tt>boolean</tt>. Primitive values are translated |
|
137 |
* to (or from) sequences of bytes according to the buffer's current byte |
|
138 |
* order, which may be retrieved and modified via the {@link #order order} |
|
139 |
* methods. Specific byte orders are represented by instances of the {@link |
|
140 |
* ByteOrder} class. The initial order of a byte buffer is always {@link |
|
141 |
* ByteOrder#BIG_ENDIAN BIG_ENDIAN}. |
|
142 |
* |
|
143 |
* <p> For access to heterogeneous binary data, that is, sequences of values of |
|
144 |
* different types, this class defines a family of absolute and relative |
|
145 |
* <i>get</i> and <i>put</i> methods for each type. For 32-bit floating-point |
|
146 |
* values, for example, this class defines: |
|
147 |
* |
|
148 |
* <blockquote><pre> |
|
149 |
* float {@link #getFloat()} |
|
150 |
* float {@link #getFloat(int) getFloat(int index)} |
|
151 |
* void {@link #putFloat(float) putFloat(float f)} |
|
152 |
* void {@link #putFloat(int,float) putFloat(int index, float f)}</pre></blockquote> |
|
153 |
* |
|
154 |
* <p> Corresponding methods are defined for the types <tt>char</tt>, |
|
155 |
* <tt>short</tt>, <tt>int</tt>, <tt>long</tt>, and <tt>double</tt>. The index |
|
156 |
* parameters of the absolute <i>get</i> and <i>put</i> methods are in terms of |
|
157 |
* bytes rather than of the type being read or written. |
|
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 | 160 |
* |
161 |
* <p> For access to homogeneous binary data, that is, sequences of values of |
|
162 |
* the same type, this class defines methods that can create <i>views</i> of a |
|
163 |
* given byte buffer. A <i>view buffer</i> is simply another buffer whose |
|
164 |
* content is backed by the byte buffer. Changes to the byte buffer's content |
|
165 |
* will be visible in the view buffer, and vice versa; the two buffers' |
|
166 |
* position, limit, and mark values are independent. The {@link |
|
167 |
* #asFloatBuffer() asFloatBuffer} method, for example, creates an instance of |
|
168 |
* the {@link FloatBuffer} class that is backed by the byte buffer upon which |
|
169 |
* the method is invoked. Corresponding view-creation methods are defined for |
|
170 |
* the types <tt>char</tt>, <tt>short</tt>, <tt>int</tt>, <tt>long</tt>, and |
|
171 |
* <tt>double</tt>. |
|
172 |
* |
|
173 |
* <p> View buffers have three important advantages over the families of |
|
174 |
* type-specific <i>get</i> and <i>put</i> methods described above: |
|
175 |
* |
|
176 |
* <ul> |
|
177 |
* |
|
178 |
* <li><p> A view buffer is indexed not in terms of bytes but rather in terms |
|
179 |
* of the type-specific size of its values; </p></li> |
|
180 |
* |
|
181 |
* <li><p> A view buffer provides relative bulk <i>get</i> and <i>put</i> |
|
182 |
* methods that can transfer contiguous sequences of values between a buffer |
|
183 |
* and an array or some other buffer of the same type; and </p></li> |
|
184 |
* |
|
185 |
* <li><p> A view buffer is potentially much more efficient because it will |
|
186 |
* be direct if, and only if, its backing byte buffer is direct. </p></li> |
|
187 |
* |
|
188 |
* </ul> |
|
189 |
* |
|
190 |
* <p> The byte order of a view buffer is fixed to be that of its byte buffer |
|
191 |
* at the time that the view is created. </p> |
|
192 |
* |
|
193 |
#end[byte] |
|
194 |
* |
|
195 |
#if[!byte] |
|
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 | 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 | 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 | 203 |
* #isDirect isDirect} method. </p> |
204 |
* |
|
205 |
#end[!byte] |
|
206 |
* |
|
207 |
#if[char] |
|
208 |
* |
|
209 |
* <p> This class implements the {@link CharSequence} interface so that |
|
210 |
* character buffers may be used wherever character sequences are accepted, for |
|
211 |
* example in the regular-expression package <tt>{@link java.util.regex}</tt>. |
|
212 |
* </p> |
|
213 |
* |
|
214 |
#end[char] |
|
215 |
* |
|
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 | 218 |
#end[byte] |
219 |
* |
|
220 |
* <p> Methods in this class that do not otherwise have a value to return are |
|
221 |
* specified to return the buffer upon which they are invoked. This allows |
|
222 |
* method invocations to be chained. |
|
223 |
* |
|
224 |
#if[byte] |
|
225 |
* |
|
226 |
* The sequence of statements |
|
227 |
* |
|
228 |
* <blockquote><pre> |
|
229 |
* bb.putInt(0xCAFEBABE); |
|
230 |
* bb.putShort(3); |
|
231 |
* bb.putShort(45);</pre></blockquote> |
|
232 |
* |
|
233 |
* can, for example, be replaced by the single statement |
|
234 |
* |
|
235 |
* <blockquote><pre> |
|
236 |
* bb.putInt(0xCAFEBABE).putShort(3).putShort(45);</pre></blockquote> |
|
237 |
* |
|
238 |
#end[byte] |
|
239 |
#if[char] |
|
240 |
* |
|
241 |
* The sequence of statements |
|
242 |
* |
|
243 |
* <blockquote><pre> |
|
244 |
* cb.put("text/"); |
|
245 |
* cb.put(subtype); |
|
246 |
* cb.put("; charset="); |
|
247 |
* cb.put(enc);</pre></blockquote> |
|
248 |
* |
|
249 |
* can, for example, be replaced by the single statement |
|
250 |
* |
|
251 |
* <blockquote><pre> |
|
252 |
* cb.put("text/").put(subtype).put("; charset=").put(enc);</pre></blockquote> |
|
253 |
* |
|
254 |
#end[char] |
|
255 |
* |
|
256 |
* |
|
257 |
* @author Mark Reinhold |
|
258 |
* @author JSR-51 Expert Group |
|
259 |
* @since 1.4 |
|
260 |
*/ |
|
261 |
||
262 |
public abstract class $Type$Buffer |
|
263 |
extends Buffer |
|
264 |
implements Comparable<$Type$Buffer>{#if[char]?, Appendable, CharSequence, Readable} |
|
265 |
{ |
|
266 |
||
267 |
// These fields are declared here rather than in Heap-X-Buffer in order to |
|
268 |
// reduce the number of virtual method invocations needed to access these |
|
269 |
// values, which is especially costly when coding small buffers. |
|
270 |
// |
|
271 |
final $type$[] hb; // Non-null only for heap buffers |
|
272 |
final int offset; |
|
273 |
boolean isReadOnly; // Valid only for heap buffers |
|
274 |
||
275 |
// Creates a new buffer with the given mark, position, limit, capacity, |
|
276 |
// backing array, and array offset |
|
277 |
// |
|
278 |
$Type$Buffer(int mark, int pos, int lim, int cap, // package-private |
|
279 |
$type$[] hb, int offset) |
|
280 |
{ |
|
281 |
super(mark, pos, lim, cap); |
|
282 |
this.hb = hb; |
|
283 |
this.offset = offset; |
|
284 |
} |
|
285 |
||
286 |
// Creates a new buffer with the given mark, position, limit, and capacity |
|
287 |
// |
|
288 |
$Type$Buffer(int mark, int pos, int lim, int cap) { // package-private |
|
289 |
this(mark, pos, lim, cap, null, 0); |
|
290 |
} |
|
291 |
||
292 |
#if[byte] |
|
293 |
||
294 |
/** |
|
4502
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
4115
diff
changeset
|
295 |
* Allocates a new direct $type$ buffer. |
2 | 296 |
* |
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 | 302 |
* |
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 | 305 |
* |
4502
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
4115
diff
changeset
|
306 |
* @return The new $type$ buffer |
2 | 307 |
* |
308 |
* @throws IllegalArgumentException |
|
309 |
* If the <tt>capacity</tt> is a negative integer |
|
310 |
*/ |
|
311 |
public static $Type$Buffer allocateDirect(int capacity) { |
|
312 |
return new Direct$Type$Buffer(capacity); |
|
313 |
} |
|
314 |
||
315 |
#end[byte] |
|
316 |
||
317 |
/** |
|
4502
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
4115
diff
changeset
|
318 |
* Allocates a new $type$ buffer. |
2 | 319 |
* |
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 | 331 |
* |
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 | 334 |
* |
4502
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
4115
diff
changeset
|
335 |
* @return The new $type$ buffer |
2 | 336 |
* |
337 |
* @throws IllegalArgumentException |
|
338 |
* If the <tt>capacity</tt> is a negative integer |
|
339 |
*/ |
|
340 |
public static $Type$Buffer allocate(int capacity) { |
|
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 | 343 |
return new Heap$Type$Buffer(capacity, capacity); |
344 |
} |
|
345 |
||
346 |
/** |
|
4502
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
4115
diff
changeset
|
347 |
* Wraps $a$ $type$ array into a buffer. |
2 | 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 | 350 |
* that is, modifications to the buffer will cause the array to be modified |
351 |
* and vice versa. The new buffer's capacity will be |
|
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 | 363 |
* |
364 |
* @param array |
|
365 |
* The array that will back the new buffer |
|
366 |
* |
|
367 |
* @param offset |
|
368 |
* The offset of the subarray to be used; must be non-negative and |
|
369 |
* no larger than <tt>array.length</tt>. The new buffer's position |
|
370 |
* will be set to this value. |
|
371 |
* |
|
372 |
* @param length |
|
373 |
* The length of the subarray to be used; |
|
374 |
* must be non-negative and no larger than |
|
375 |
* <tt>array.length - offset</tt>. |
|
376 |
* The new buffer's limit will be set to <tt>offset + length</tt>. |
|
377 |
* |
|
4502
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
4115
diff
changeset
|
378 |
* @return The new $type$ buffer |
2 | 379 |
* |
380 |
* @throws IndexOutOfBoundsException |
|
381 |
* If the preconditions on the <tt>offset</tt> and <tt>length</tt> |
|
382 |
* parameters do not hold |
|
383 |
*/ |
|
384 |
public static $Type$Buffer wrap($type$[] array, |
|
385 |
int offset, int length) |
|
386 |
{ |
|
387 |
try { |
|
388 |
return new Heap$Type$Buffer(array, offset, length); |
|
389 |
} catch (IllegalArgumentException x) { |
|
390 |
throw new IndexOutOfBoundsException(); |
|
391 |
} |
|
392 |
} |
|
393 |
||
394 |
/** |
|
4502
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
4115
diff
changeset
|
395 |
* Wraps $a$ $type$ array into a buffer. |
2 | 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 | 398 |
* that is, modifications to the buffer will cause the array to be modified |
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 | 410 |
* |
411 |
* @param array |
|
412 |
* The array that will back this buffer |
|
413 |
* |
|
4502
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
4115
diff
changeset
|
414 |
* @return The new $type$ buffer |
2 | 415 |
*/ |
416 |
public static $Type$Buffer wrap($type$[] array) { |
|
417 |
return wrap(array, 0, array.length); |
|
418 |
} |
|
419 |
||
420 |
#if[char] |
|
421 |
||
422 |
/** |
|
423 |
* Attempts to read characters into the specified character buffer. |
|
424 |
* The buffer is used as a repository of characters as-is: the only |
|
425 |
* changes made are the results of a put operation. No flipping or |
|
426 |
* rewinding of the buffer is performed. |
|
427 |
* |
|
428 |
* @param target the buffer to read characters into |
|
429 |
* @return The number of characters added to the buffer, or |
|
430 |
* -1 if this source of characters is at its end |
|
431 |
* @throws IOException if an I/O error occurs |
|
432 |
* @throws NullPointerException if target is null |
|
433 |
* @throws ReadOnlyBufferException if target is a read only buffer |
|
434 |
* @since 1.5 |
|
435 |
*/ |
|
436 |
public int read(CharBuffer target) throws IOException { |
|
437 |
// Determine the number of bytes n that can be transferred |
|
438 |
int targetRemaining = target.remaining(); |
|
439 |
int remaining = remaining(); |
|
440 |
if (remaining == 0) |
|
441 |
return -1; |
|
442 |
int n = Math.min(remaining, targetRemaining); |
|
443 |
int limit = limit(); |
|
444 |
// Set source limit to prevent target overflow |
|
445 |
if (targetRemaining < remaining) |
|
446 |
limit(position() + n); |
|
447 |
try { |
|
448 |
if (n > 0) |
|
449 |
target.put(this); |
|
450 |
} finally { |
|
451 |
limit(limit); // restore real limit |
|
452 |
} |
|
453 |
return n; |
|
454 |
} |
|
455 |
||
456 |
/** |
|
457 |
* Wraps a character sequence into a buffer. |
|
458 |
* |
|
459 |
* <p> The content of the new, read-only buffer will be the content of the |
|
460 |
* given character sequence. The buffer's capacity will be |
|
461 |
* <tt>csq.length()</tt>, its position will be <tt>start</tt>, its limit |
|
462 |
* will be <tt>end</tt>, and its mark will be undefined. </p> |
|
463 |
* |
|
464 |
* @param csq |
|
465 |
* The character sequence from which the new character buffer is to |
|
466 |
* be created |
|
467 |
* |
|
468 |
* @param start |
|
469 |
* The index of the first character to be used; |
|
470 |
* must be non-negative and no larger than <tt>csq.length()</tt>. |
|
471 |
* The new buffer's position will be set to this value. |
|
472 |
* |
|
473 |
* @param end |
|
474 |
* The index of the character following the last character to be |
|
475 |
* used; must be no smaller than <tt>start</tt> and no larger |
|
476 |
* than <tt>csq.length()</tt>. |
|
477 |
* The new buffer's limit will be set to this value. |
|
478 |
* |
|
479 |
* @return The new character buffer |
|
480 |
* |
|
481 |
* @throws IndexOutOfBoundsException |
|
482 |
* If the preconditions on the <tt>start</tt> and <tt>end</tt> |
|
483 |
* parameters do not hold |
|
484 |
*/ |
|
485 |
public static CharBuffer wrap(CharSequence csq, int start, int end) { |
|
486 |
try { |
|
487 |
return new StringCharBuffer(csq, start, end); |
|
488 |
} catch (IllegalArgumentException x) { |
|
489 |
throw new IndexOutOfBoundsException(); |
|
490 |
} |
|
491 |
} |
|
492 |
||
493 |
/** |
|
494 |
* Wraps a character sequence into a buffer. |
|
495 |
* |
|
496 |
* <p> The content of the new, read-only buffer will be the content of the |
|
497 |
* given character sequence. The new buffer's capacity and limit will be |
|
498 |
* <tt>csq.length()</tt>, its position will be zero, and its mark will be |
|
499 |
* undefined. </p> |
|
500 |
* |
|
501 |
* @param csq |
|
502 |
* The character sequence from which the new character buffer is to |
|
503 |
* be created |
|
504 |
* |
|
505 |
* @return The new character buffer |
|
506 |
*/ |
|
507 |
public static CharBuffer wrap(CharSequence csq) { |
|
508 |
return wrap(csq, 0, csq.length()); |
|
509 |
} |
|
510 |
||
511 |
#end[char] |
|
512 |
||
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 | 515 |
* this buffer's content. |
516 |
* |
|
517 |
* <p> The content of the new buffer will start at this buffer's current |
|
518 |
* position. Changes to this buffer's content will be visible in the new |
|
519 |
* buffer, and vice versa; the two buffers' position, limit, and mark |
|
520 |
* values will be independent. |
|
521 |
* |
|
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 | 532 |
* |
4502
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
4115
diff
changeset
|
533 |
* @return The new $type$ buffer |
2 | 534 |
*/ |
535 |
public abstract $Type$Buffer slice(); |
|
536 |
||
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 | 539 |
* |
540 |
* <p> The content of the new buffer will be that of this buffer. Changes |
|
541 |
* to this buffer's content will be visible in the new buffer, and vice |
|
542 |
* versa; the two buffers' position, limit, and mark values will be |
|
543 |
* independent. |
|
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 | 554 |
* |
4502
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
4115
diff
changeset
|
555 |
* @return The new $type$ buffer |
2 | 556 |
*/ |
557 |
public abstract $Type$Buffer duplicate(); |
|
558 |
||
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 | 561 |
* content. |
562 |
* |
|
563 |
* <p> The content of the new buffer will be that of this buffer. Changes |
|
564 |
* to this buffer's content will be visible in the new buffer; the new |
|
565 |
* buffer itself, however, will be read-only and will not allow the shared |
|
566 |
* content to be modified. The two buffers' position, limit, and mark |
|
567 |
* values will be independent. |
|
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 | 576 |
* |
577 |
* <p> If this buffer is itself read-only then this method behaves in |
|
578 |
* exactly the same way as the {@link #duplicate duplicate} method. </p> |
|
579 |
* |
|
4502
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
4115
diff
changeset
|
580 |
* @return The new, read-only $type$ buffer |
2 | 581 |
*/ |
582 |
public abstract $Type$Buffer asReadOnlyBuffer(); |
|
583 |
||
584 |
||
585 |
// -- Singleton get/put methods -- |
|
586 |
||
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 | 589 |
* current position, and then increments the position. |
2 | 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 | 592 |
* |
593 |
* @throws BufferUnderflowException |
|
594 |
* If the buffer's current position is not smaller than its limit |
|
595 |
*/ |
|
596 |
public abstract $type$ get(); |
|
597 |
||
598 |
/** |
|
599 |
* Relative <i>put</i> method <i>(optional operation)</i>. |
|
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 | 602 |
* position, and then increments the position. </p> |
603 |
* |
|
604 |
* @param $x$ |
|
4502
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
4115
diff
changeset
|
605 |
* The $type$ to be written |
2 | 606 |
* |
607 |
* @return This buffer |
|
608 |
* |
|
609 |
* @throws BufferOverflowException |
|
610 |
* If this buffer's current position is not smaller than its limit |
|
611 |
* |
|
612 |
* @throws ReadOnlyBufferException |
|
613 |
* If this buffer is read-only |
|
614 |
*/ |
|
615 |
public abstract $Type$Buffer put($type$ $x$); |
|
616 |
||
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 | 619 |
* index. |
2 | 620 |
* |
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 | 623 |
* |
4502
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
4115
diff
changeset
|
624 |
* @return The $type$ at the given index |
2 | 625 |
* |
626 |
* @throws IndexOutOfBoundsException |
|
627 |
* If <tt>index</tt> is negative |
|
628 |
* or not smaller than the buffer's limit |
|
629 |
*/ |
|
630 |
public abstract $type$ get(int index); |
|
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 | 645 |
/** |
646 |
* Absolute <i>put</i> method <i>(optional operation)</i>. |
|
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 | 649 |
* index. </p> |
650 |
* |
|
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 | 653 |
* |
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 | 656 |
* |
657 |
* @return This buffer |
|
658 |
* |
|
659 |
* @throws IndexOutOfBoundsException |
|
660 |
* If <tt>index</tt> is negative |
|
661 |
* or not smaller than the buffer's limit |
|
662 |
* |
|
663 |
* @throws ReadOnlyBufferException |
|
664 |
* If this buffer is read-only |
|
665 |
*/ |
|
666 |
public abstract $Type$Buffer put(int index, $type$ $x$); |
|
667 |
||
668 |
||
669 |
// -- Bulk get operations -- |
|
670 |
||
671 |
/** |
|
672 |
* Relative bulk <i>get</i> method. |
|
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 | 676 |
* buffer than are required to satisfy the request, that is, if |
677 |
* <tt>length</tt> <tt>></tt> <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 | 679 |
* thrown. |
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 | 682 |
* buffer into the given array, starting at the current position of this |
683 |
* buffer and at the given offset in the array. The position of this |
|
684 |
* buffer is then incremented by <tt>length</tt>. |
|
685 |
* |
|
686 |
* <p> In other words, an invocation of this method of the form |
|
687 |
* <tt>src.get(dst, off, len)</tt> has exactly the same effect as |
|
688 |
* the loop |
|
689 |
* |
|
18156 | 690 |
* <pre>{@code |
2 | 691 |
* for (int i = off; i < off + len; i++) |
18156 | 692 |
* dst[i] = src.get(): |
693 |
* }</pre> |
|
2 | 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 | 696 |
* this buffer and it is potentially much more efficient. |
2 | 697 |
* |
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 | 700 |
* |
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 | 703 |
* written; must be non-negative and no larger than |
704 |
* <tt>dst.length</tt> |
|
705 |
* |
|
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 | 708 |
* array; must be non-negative and no larger than |
709 |
* <tt>dst.length - offset</tt> |
|
710 |
* |
|
711 |
* @return This buffer |
|
712 |
* |
|
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 | 715 |
* remaining in this buffer |
716 |
* |
|
717 |
* @throws IndexOutOfBoundsException |
|
718 |
* If the preconditions on the <tt>offset</tt> and <tt>length</tt> |
|
719 |
* parameters do not hold |
|
720 |
*/ |
|
721 |
public $Type$Buffer get($type$[] dst, int offset, int length) { |
|
722 |
checkBounds(offset, length, dst.length); |
|
723 |
if (length > remaining()) |
|
724 |
throw new BufferUnderflowException(); |
|
725 |
int end = offset + length; |
|
726 |
for (int i = offset; i < end; i++) |
|
727 |
dst[i] = get(); |
|
728 |
return this; |
|
729 |
} |
|
730 |
||
731 |
/** |
|
732 |
* Relative bulk <i>get</i> method. |
|
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 | 735 |
* destination array. An invocation of this method of the form |
736 |
* <tt>src.get(a)</tt> behaves in exactly the same way as the invocation |
|
737 |
* |
|
738 |
* <pre> |
|
739 |
* src.get(a, 0, a.length) </pre> |
|
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 | 744 |
* @return This buffer |
745 |
* |
|
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 | 748 |
* remaining in this buffer |
749 |
*/ |
|
750 |
public $Type$Buffer get($type$[] dst) { |
|
751 |
return get(dst, 0, dst.length); |
|
752 |
} |
|
753 |
||
754 |
||
755 |
// -- Bulk put operations -- |
|
756 |
||
757 |
/** |
|
758 |
* Relative bulk <i>put</i> method <i>(optional operation)</i>. |
|
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 | 762 |
* source buffer than in this buffer, that is, if |
763 |
* <tt>src.remaining()</tt> <tt>></tt> <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 | 765 |
* BufferOverflowException} is thrown. |
766 |
* |
|
767 |
* <p> Otherwise, this method copies |
|
4502
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
4115
diff
changeset
|
768 |
* <i>n</i> = <tt>src.remaining()</tt> $type$s from the given |
2 | 769 |
* buffer into this buffer, starting at each buffer's current position. |
770 |
* The positions of both buffers are then incremented by <i>n</i>. |
|
771 |
* |
|
772 |
* <p> In other words, an invocation of this method of the form |
|
773 |
* <tt>dst.put(src)</tt> has exactly the same effect as the loop |
|
774 |
* |
|
775 |
* <pre> |
|
776 |
* while (src.hasRemaining()) |
|
777 |
* dst.put(src.get()); </pre> |
|
778 |
* |
|
779 |
* except that it first checks that there is sufficient space in this |
|
18164 | 780 |
* buffer and it is potentially much more efficient. |
2 | 781 |
* |
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 | 784 |
* must not be this buffer |
785 |
* |
|
786 |
* @return This buffer |
|
787 |
* |
|
788 |
* @throws BufferOverflowException |
|
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 | 791 |
* |
792 |
* @throws IllegalArgumentException |
|
793 |
* If the source buffer is this buffer |
|
794 |
* |
|
795 |
* @throws ReadOnlyBufferException |
|
796 |
* If this buffer is read-only |
|
797 |
*/ |
|
798 |
public $Type$Buffer put($Type$Buffer src) { |
|
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 | 803 |
int n = src.remaining(); |
804 |
if (n > remaining()) |
|
805 |
throw new BufferOverflowException(); |
|
806 |
for (int i = 0; i < n; i++) |
|
807 |
put(src.get()); |
|
808 |
return this; |
|
809 |
} |
|
810 |
||
811 |
/** |
|
812 |
* Relative bulk <i>put</i> method <i>(optional operation)</i>. |
|
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 | 816 |
* than remain in this buffer, that is, if |
817 |
* <tt>length</tt> <tt>></tt> <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 | 819 |
* thrown. |
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 | 822 |
* given array into this buffer, starting at the given offset in the array |
823 |
* and at the current position of this buffer. The position of this buffer |
|
824 |
* is then incremented by <tt>length</tt>. |
|
825 |
* |
|
826 |
* <p> In other words, an invocation of this method of the form |
|
827 |
* <tt>dst.put(src, off, len)</tt> has exactly the same effect as |
|
828 |
* the loop |
|
829 |
* |
|
18156 | 830 |
* <pre>{@code |
2 | 831 |
* for (int i = off; i < off + len; i++) |
18156 | 832 |
* dst.put(a[i]); |
833 |
* }</pre> |
|
2 | 834 |
* |
835 |
* except that it first checks that there is sufficient space in this |
|
18164 | 836 |
* buffer and it is potentially much more efficient. |
2 | 837 |
* |
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 | 840 |
* |
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 | 843 |
* must be non-negative and no larger than <tt>array.length</tt> |
844 |
* |
|
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 | 847 |
* must be non-negative and no larger than |
848 |
* <tt>array.length - offset</tt> |
|
849 |
* |
|
850 |
* @return This buffer |
|
851 |
* |
|
852 |
* @throws BufferOverflowException |
|
853 |
* If there is insufficient space in this buffer |
|
854 |
* |
|
855 |
* @throws IndexOutOfBoundsException |
|
856 |
* If the preconditions on the <tt>offset</tt> and <tt>length</tt> |
|
857 |
* parameters do not hold |
|
858 |
* |
|
859 |
* @throws ReadOnlyBufferException |
|
860 |
* If this buffer is read-only |
|
861 |
*/ |
|
862 |
public $Type$Buffer put($type$[] src, int offset, int length) { |
|
863 |
checkBounds(offset, length, src.length); |
|
864 |
if (length > remaining()) |
|
865 |
throw new BufferOverflowException(); |
|
866 |
int end = offset + length; |
|
867 |
for (int i = offset; i < end; i++) |
|
868 |
this.put(src[i]); |
|
869 |
return this; |
|
870 |
} |
|
871 |
||
872 |
/** |
|
873 |
* Relative bulk <i>put</i> method <i>(optional operation)</i>. |
|
874 |
* |
|
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 | 877 |
* form <tt>dst.put(a)</tt> behaves in exactly the same way as the |
878 |
* invocation |
|
879 |
* |
|
880 |
* <pre> |
|
881 |
* dst.put(a, 0, a.length) </pre> |
|
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 | 886 |
* @return This buffer |
887 |
* |
|
888 |
* @throws BufferOverflowException |
|
889 |
* If there is insufficient space in this buffer |
|
890 |
* |
|
891 |
* @throws ReadOnlyBufferException |
|
892 |
* If this buffer is read-only |
|
893 |
*/ |
|
894 |
public final $Type$Buffer put($type$[] src) { |
|
895 |
return put(src, 0, src.length); |
|
896 |
} |
|
897 |
||
898 |
#if[char] |
|
899 |
||
900 |
/** |
|
901 |
* Relative bulk <i>put</i> method <i>(optional operation)</i>. |
|
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 | 905 |
* remain in this buffer, that is, if |
906 |
* <tt>end - start</tt> <tt>></tt> <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 | 908 |
* BufferOverflowException} is thrown. |
909 |
* |
|
910 |
* <p> Otherwise, this method copies |
|
4502
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
4115
diff
changeset
|
911 |
* <i>n</i> = <tt>end</tt> - <tt>start</tt> $type$s |
2 | 912 |
* from the given string into this buffer, starting at the given |
913 |
* <tt>start</tt> index and at the current position of this buffer. The |
|
914 |
* position of this buffer is then incremented by <i>n</i>. |
|
915 |
* |
|
916 |
* <p> In other words, an invocation of this method of the form |
|
917 |
* <tt>dst.put(src, start, end)</tt> has exactly the same effect |
|
918 |
* as the loop |
|
919 |
* |
|
18156 | 920 |
* <pre>{@code |
2 | 921 |
* for (int i = start; i < end; i++) |
18156 | 922 |
* dst.put(src.charAt(i)); |
923 |
* }</pre> |
|
2 | 924 |
* |
925 |
* except that it first checks that there is sufficient space in this |
|
18164 | 926 |
* buffer and it is potentially much more efficient. |
2 | 927 |
* |
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 | 930 |
* |
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 | 933 |
* must be non-negative and no larger than |
934 |
* <tt>string.length()</tt> |
|
935 |
* |
|
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 | 938 |
* plus one; must be non-negative and no larger than |
939 |
* <tt>string.length()</tt> |
|
940 |
* |
|
941 |
* @return This buffer |
|
942 |
* |
|
943 |
* @throws BufferOverflowException |
|
944 |
* If there is insufficient space in this buffer |
|
945 |
* |
|
946 |
* @throws IndexOutOfBoundsException |
|
947 |
* If the preconditions on the <tt>start</tt> and <tt>end</tt> |
|
948 |
* parameters do not hold |
|
949 |
* |
|
950 |
* @throws ReadOnlyBufferException |
|
951 |
* If this buffer is read-only |
|
952 |
*/ |
|
953 |
public $Type$Buffer put(String src, int start, int end) { |
|
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 | 959 |
for (int i = start; i < end; i++) |
960 |
this.put(src.charAt(i)); |
|
961 |
return this; |
|
962 |
} |
|
963 |
||
964 |
/** |
|
965 |
* Relative bulk <i>put</i> method <i>(optional operation)</i>. |
|
966 |
* |
|
967 |
* <p> This method transfers the entire content of the given source string |
|
968 |
* into this buffer. An invocation of this method of the form |
|
969 |
* <tt>dst.put(s)</tt> behaves in exactly the same way as the invocation |
|
970 |
* |
|
971 |
* <pre> |
|
972 |
* dst.put(s, 0, s.length()) </pre> |
|
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 | 977 |
* @return This buffer |
978 |
* |
|
979 |
* @throws BufferOverflowException |
|
980 |
* If there is insufficient space in this buffer |
|
981 |
* |
|
982 |
* @throws ReadOnlyBufferException |
|
983 |
* If this buffer is read-only |
|
984 |
*/ |
|
985 |
public final $Type$Buffer put(String src) { |
|
986 |
return put(src, 0, src.length()); |
|
987 |
} |
|
988 |
||
989 |
#end[char] |
|
990 |
||
991 |
||
992 |
// -- Other stuff -- |
|
993 |
||
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 | 996 |
* array. |
997 |
* |
|
998 |
* <p> If this method returns <tt>true</tt> then the {@link #array() array} |
|
999 |
* and {@link #arrayOffset() arrayOffset} methods may safely be invoked. |
|
1000 |
* </p> |
|
1001 |
* |
|
1002 |
* @return <tt>true</tt> if, and only if, this buffer |
|
1003 |
* is backed by an array and is not read-only |
|
1004 |
*/ |
|
1005 |
public final boolean hasArray() { |
|
1006 |
return (hb != null) && !isReadOnly; |
|
1007 |
} |
|
1008 |
||
1009 |
/** |
|
4502
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
4115
diff
changeset
|
1010 |
* Returns the $type$ array that backs this |
2 | 1011 |
* buffer <i>(optional operation)</i>. |
1012 |
* |
|
1013 |
* <p> Modifications to this buffer's content will cause the returned |
|
1014 |
* array's content to be modified, and vice versa. |
|
1015 |
* |
|
1016 |
* <p> Invoke the {@link #hasArray hasArray} method before invoking this |
|
1017 |
* method in order to ensure that this buffer has an accessible backing |
|
1018 |
* array. </p> |
|
1019 |
* |
|
1020 |
* @return The array that backs this buffer |
|
1021 |
* |
|
1022 |
* @throws ReadOnlyBufferException |
|
1023 |
* If this buffer is backed by an array but is read-only |
|
1024 |
* |
|
1025 |
* @throws UnsupportedOperationException |
|
1026 |
* If this buffer is not backed by an accessible array |
|
1027 |
*/ |
|
1028 |
public final $type$[] array() { |
|
1029 |
if (hb == null) |
|
1030 |
throw new UnsupportedOperationException(); |
|
1031 |
if (isReadOnly) |
|
1032 |
throw new ReadOnlyBufferException(); |
|
1033 |
return hb; |
|
1034 |
} |
|
1035 |
||
1036 |
/** |
|
1037 |
* Returns the offset within this buffer's backing array of the first |
|
1038 |
* element of the buffer <i>(optional operation)</i>. |
|
1039 |
* |
|
1040 |
* <p> If this buffer is backed by an array then buffer position <i>p</i> |
|
1041 |
* corresponds to array index <i>p</i> + <tt>arrayOffset()</tt>. |
|
1042 |
* |
|
1043 |
* <p> Invoke the {@link #hasArray hasArray} method before invoking this |
|
1044 |
* method in order to ensure that this buffer has an accessible backing |
|
1045 |
* array. </p> |
|
1046 |
* |
|
1047 |
* @return The offset within this buffer's array |
|
1048 |
* of the first element of the buffer |
|
1049 |
* |
|
1050 |
* @throws ReadOnlyBufferException |
|
1051 |
* If this buffer is backed by an array but is read-only |
|
1052 |
* |
|
1053 |
* @throws UnsupportedOperationException |
|
1054 |
* If this buffer is not backed by an accessible array |
|
1055 |
*/ |
|
1056 |
public final int arrayOffset() { |
|
1057 |
if (hb == null) |
|
1058 |
throw new UnsupportedOperationException(); |
|
1059 |
if (isReadOnly) |
|
1060 |
throw new ReadOnlyBufferException(); |
|
1061 |
return offset; |
|
1062 |
} |
|
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 | 1164 |
/** |
1165 |
* Compacts this buffer <i>(optional operation)</i>. |
|
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 | 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> = <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> + 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 | 1172 |
* <tt>limit()</tt> - 1 is copied to index |
1173 |
* <i>n</i> = <tt>limit()</tt> - <tt>1</tt> - <i>p</i>. |
|
1174 |
* The buffer's position is then set to <i>n+1</i> and its limit is set to |
|
1175 |
* its capacity. The mark, if defined, is discarded. |
|
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 | 1178 |
* rather than to zero, so that an invocation of this method can be |
1179 |
* followed immediately by an invocation of another relative <i>put</i> |
|
1180 |
* method. </p> |
|
1181 |
* |
|
1182 |
#if[byte] |
|
1183 |
* |
|
1184 |
* <p> Invoke this method after writing data from a buffer in case the |
|
1185 |
* write was incomplete. The following loop, for example, copies bytes |
|
1186 |
* from one channel to another via the buffer <tt>buf</tt>: |
|
1187 |
* |
|
18156 | 1188 |
* <blockquote><pre>{@code |
1189 |
* buf.clear(); // Prepare buffer for use |
|
1190 |
* while (in.read(buf) >= 0 || buf.position != 0) { |
|
1191 |
* buf.flip(); |
|
1192 |
* out.write(buf); |
|
1193 |
* buf.compact(); // In case of partial write |
|
1194 |
* } |
|
2 | 1195 |
* }</pre></blockquote> |
1196 |
* |
|
1197 |
#end[byte] |
|
1198 |
* |
|
1199 |
* @return This buffer |
|
1200 |
* |
|
1201 |
* @throws ReadOnlyBufferException |
|
1202 |
* If this buffer is read-only |
|
1203 |
*/ |
|
1204 |
public abstract $Type$Buffer compact(); |
|
1205 |
||
1206 |
/** |
|
18164 | 1207 |
* Tells whether or not this $type$ buffer is direct. |
2 | 1208 |
* |
1209 |
* @return <tt>true</tt> if, and only if, this buffer is direct |
|
1210 |
*/ |
|
1211 |
public abstract boolean isDirect(); |
|
1212 |
||
1213 |
#if[!char] |
|
1214 |
||
1215 |
/** |
|
18164 | 1216 |
* Returns a string summarizing the state of this buffer. |
2 | 1217 |
* |
1218 |
* @return A summary string |
|
1219 |
*/ |
|
1220 |
public String toString() { |
|
1221 |
StringBuffer sb = new StringBuffer(); |
|
1222 |
sb.append(getClass().getName()); |
|
1223 |
sb.append("[pos="); |
|
1224 |
sb.append(position()); |
|
1225 |
sb.append(" lim="); |
|
1226 |
sb.append(limit()); |
|
1227 |
sb.append(" cap="); |
|
1228 |
sb.append(capacity()); |
|
1229 |
sb.append("]"); |
|
1230 |
return sb.toString(); |
|
1231 |
} |
|
1232 |
||
1233 |
#end[!char] |
|
1234 |
||
1235 |
||
1236 |
// ## Should really use unchecked accessors here for speed |
|
1237 |
||
1238 |
/** |
|
1239 |
* Returns the current hash code of this buffer. |
|
1240 |
* |
|
1241 |
* <p> The hash code of a $type$ buffer depends only upon its remaining |
|
1242 |
* elements; that is, upon the elements from <tt>position()</tt> up to, and |
|
1243 |
* including, the element at <tt>limit()</tt> - <tt>1</tt>. |
|
1244 |
* |
|
1245 |
* <p> Because buffer hash codes are content-dependent, it is inadvisable |
|
1246 |
* to use buffers as keys in hash maps or similar data structures unless it |
|
1247 |
* is known that their contents will not change. </p> |
|
1248 |
* |
|
1249 |
* @return The current hash code of this buffer |
|
1250 |
*/ |
|
1251 |
public int hashCode() { |
|
1252 |
int h = 1; |
|
1253 |
int p = position(); |
|
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 | 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 | 1260 |
return h; |
1261 |
} |
|
1262 |
||
1263 |
/** |
|
1264 |
* Tells whether or not this buffer is equal to another object. |
|
1265 |
* |
|
1266 |
* <p> Two $type$ buffers are equal if, and only if, |
|
1267 |
* |
|
21334 | 1268 |
* <ol> |
2 | 1269 |
* |
1270 |
* <li><p> They have the same element type, </p></li> |
|
1271 |
* |
|
1272 |
* <li><p> They have the same number of remaining elements, and |
|
1273 |
* </p></li> |
|
1274 |
* |
|
1275 |
* <li><p> The two sequences of remaining elements, considered |
|
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 | 1284 |
* </p></li> |
1285 |
* |
|
1286 |
* </ol> |
|
1287 |
* |
|
1288 |
* <p> A $type$ buffer is not equal to any other type of object. </p> |
|
1289 |
* |
|
1290 |
* @param ob The object to which this buffer is to be compared |
|
1291 |
* |
|
1292 |
* @return <tt>true</tt> if, and only if, this buffer is equal to the |
|
1293 |
* given object |
|
1294 |
*/ |
|
1295 |
public boolean equals(Object ob) { |
|
1296 |
if (this == ob) |
|
1297 |
return true; |
|
1298 |
if (!(ob instanceof $Type$Buffer)) |
|
1299 |
return false; |
|
1300 |
$Type$Buffer that = ($Type$Buffer)ob; |
|
1301 |
if (this.remaining() != that.remaining()) |
|
1302 |
return false; |
|
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 | 1306 |
return false; |
1307 |
return true; |
|
1308 |
} |
|
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 | 1318 |
/** |
1319 |
* Compares this buffer to another. |
|
1320 |
* |
|
1321 |
* <p> Two $type$ buffers are compared by comparing their sequences of |
|
1322 |
* remaining elements lexicographically, without regard to the starting |
|
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 | 1335 |
* |
1336 |
* <p> A $type$ buffer is not comparable to any other type of object. |
|
1337 |
* |
|
1338 |
* @return A negative integer, zero, or a positive integer as this buffer |
|
1339 |
* is less than, equal to, or greater than the given buffer |
|
1340 |
*/ |
|
1341 |
public int compareTo($Type$Buffer that) { |
|
1342 |
int n = this.position() + Math.min(this.remaining(), that.remaining()); |
|
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 | 1347 |
} |
1348 |
return this.remaining() - that.remaining(); |
|
1349 |
} |
|
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 | 1361 |
|
1362 |
// -- Other char stuff -- |
|
1363 |
||
1364 |
#if[char] |
|
1365 |
||
1366 |
/** |
|
1367 |
* Returns a string containing the characters in this buffer. |
|
1368 |
* |
|
1369 |
* <p> The first character of the resulting string will be the character at |
|
1370 |
* this buffer's position, while the last character will be the character |
|
1371 |
* at index <tt>limit()</tt> - 1. Invoking this method does not |
|
1372 |
* change the buffer's position. </p> |
|
1373 |
* |
|
1374 |
* @return The specified string |
|
1375 |
*/ |
|
1376 |
public String toString() { |
|
1377 |
return toString(position(), limit()); |
|
1378 |
} |
|
1379 |
||
1380 |
abstract String toString(int start, int end); // package-private |
|
1381 |
||
1382 |
||
1383 |
// --- Methods to support CharSequence --- |
|
1384 |
||
1385 |
/** |
|
1386 |
* Returns the length of this character buffer. |
|
1387 |
* |
|
1388 |
* <p> When viewed as a character sequence, the length of a character |
|
1389 |
* buffer is simply the number of characters between the position |
|
1390 |
* (inclusive) and the limit (exclusive); that is, it is equivalent to |
|
1391 |
* <tt>remaining()</tt>. </p> |
|
1392 |
* |
|
1393 |
* @return The length of this character buffer |
|
1394 |
*/ |
|
1395 |
public final int length() { |
|
1396 |
return remaining(); |
|
1397 |
} |
|
1398 |
||
1399 |
/** |
|
1400 |
* Reads the character at the given index relative to the current |
|
18164 | 1401 |
* position. |
2 | 1402 |
* |
1403 |
* @param index |
|
1404 |
* The index of the character to be read, relative to the position; |
|
1405 |
* must be non-negative and smaller than <tt>remaining()</tt> |
|
1406 |
* |
|
1407 |
* @return The character at index |
|
1408 |
* <tt>position() + index</tt> |
|
1409 |
* |
|
1410 |
* @throws IndexOutOfBoundsException |
|
1411 |
* If the preconditions on <tt>index</tt> do not hold |
|
1412 |
*/ |
|
1413 |
public final char charAt(int index) { |
|
1414 |
return get(position() + checkIndex(index, 1)); |
|
1415 |
} |
|
1416 |
||
1417 |
/** |
|
1418 |
* Creates a new character buffer that represents the specified subsequence |
|
1419 |
* of this buffer, relative to the current position. |
|
1420 |
* |
|
1421 |
* <p> The new buffer will share this buffer's content; that is, if the |
|
1422 |
* content of this buffer is mutable then modifications to one buffer will |
|
1423 |
* cause the other to be modified. The new buffer's capacity will be that |
|
1424 |
* of this buffer, its position will be |
|
1425 |
* <tt>position()</tt> + <tt>start</tt>, and its limit will be |
|
1426 |
* <tt>position()</tt> + <tt>end</tt>. The new buffer will be |
|
1427 |
* direct if, and only if, this buffer is direct, and it will be read-only |
|
1428 |
* if, and only if, this buffer is read-only. </p> |
|
1429 |
* |
|
1430 |
* @param start |
|
1431 |
* The index, relative to the current position, of the first |
|
1432 |
* character in the subsequence; must be non-negative and no larger |
|
1433 |
* than <tt>remaining()</tt> |
|
1434 |
* |
|
1435 |
* @param end |
|
1436 |
* The index, relative to the current position, of the character |
|
1437 |
* following the last character in the subsequence; must be no |
|
1438 |
* smaller than <tt>start</tt> and no larger than |
|
1439 |
* <tt>remaining()</tt> |
|
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 | 1442 |
* |
1443 |
* @throws IndexOutOfBoundsException |
|
1444 |
* If the preconditions on <tt>start</tt> and <tt>end</tt> |
|
1445 |
* do not hold |
|
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 | 1448 |
|
1449 |
||
1450 |
// --- Methods to support Appendable --- |
|
1451 |
||
1452 |
/** |
|
1453 |
* Appends the specified character sequence to this |
|
1454 |
* buffer <i>(optional operation)</i>. |
|
1455 |
* |
|
1456 |
* <p> An invocation of this method of the form <tt>dst.append(csq)</tt> |
|
1457 |
* behaves in exactly the same way as the invocation |
|
1458 |
* |
|
1459 |
* <pre> |
|
1460 |
* dst.put(csq.toString()) </pre> |
|
1461 |
* |
|
1462 |
* <p> Depending on the specification of <tt>toString</tt> for the |
|
1463 |
* character sequence <tt>csq</tt>, the entire sequence may not be |
|
1464 |
* appended. For instance, invoking the {@link $Type$Buffer#toString() |
|
1465 |
* toString} method of a character buffer will return a subsequence whose |
|
1466 |
* content depends upon the buffer's position and limit. |
|
1467 |
* |
|
1468 |
* @param csq |
|
1469 |
* The character sequence to append. If <tt>csq</tt> is |
|
1470 |
* <tt>null</tt>, then the four characters <tt>"null"</tt> are |
|
1471 |
* appended to this character buffer. |
|
1472 |
* |
|
1473 |
* @return This buffer |
|
1474 |
* |
|
1475 |
* @throws BufferOverflowException |
|
1476 |
* If there is insufficient space in this buffer |
|
1477 |
* |
|
1478 |
* @throws ReadOnlyBufferException |
|
1479 |
* If this buffer is read-only |
|
1480 |
* |
|
1481 |
* @since 1.5 |
|
1482 |
*/ |
|
1483 |
public $Type$Buffer append(CharSequence csq) { |
|
1484 |
if (csq == null) |
|
1485 |
return put("null"); |
|
1486 |
else |
|
1487 |
return put(csq.toString()); |
|
1488 |
} |
|
1489 |
||
1490 |
/** |
|
1491 |
* Appends a subsequence of the specified character sequence to this |
|
1492 |
* buffer <i>(optional operation)</i>. |
|
1493 |
* |
|
1494 |
* <p> An invocation of this method of the form <tt>dst.append(csq, start, |
|
1495 |
* end)</tt> when <tt>csq</tt> is not <tt>null</tt>, behaves in exactly the |
|
1496 |
* same way as the invocation |
|
1497 |
* |
|
1498 |
* <pre> |
|
1499 |
* dst.put(csq.subSequence(start, end).toString()) </pre> |
|
1500 |
* |
|
1501 |
* @param csq |
|
1502 |
* The character sequence from which a subsequence will be |
|
1503 |
* appended. If <tt>csq</tt> is <tt>null</tt>, then characters |
|
1504 |
* will be appended as if <tt>csq</tt> contained the four |
|
1505 |
* characters <tt>"null"</tt>. |
|
1506 |
* |
|
1507 |
* @return This buffer |
|
1508 |
* |
|
1509 |
* @throws BufferOverflowException |
|
1510 |
* If there is insufficient space in this buffer |
|
1511 |
* |
|
1512 |
* @throws IndexOutOfBoundsException |
|
1513 |
* If <tt>start</tt> or <tt>end</tt> are negative, <tt>start</tt> |
|
1514 |
* is greater than <tt>end</tt>, or <tt>end</tt> is greater than |
|
1515 |
* <tt>csq.length()</tt> |
|
1516 |
* |
|
1517 |
* @throws ReadOnlyBufferException |
|
1518 |
* If this buffer is read-only |
|
1519 |
* |
|
1520 |
* @since 1.5 |
|
1521 |
*/ |
|
1522 |
public $Type$Buffer append(CharSequence csq, int start, int end) { |
|
1523 |
CharSequence cs = (csq == null ? "null" : csq); |
|
1524 |
return put(cs.subSequence(start, end).toString()); |
|
1525 |
} |
|
1526 |
||
1527 |
/** |
|
4502
18f387917b89
6903754: (bf) Improve floating-point buffer comparison
martin
parents:
4115
diff
changeset
|
1528 |
* Appends the specified $type$ to this |
2 | 1529 |
* buffer <i>(optional operation)</i>. |
1530 |
* |
|
1531 |
* <p> An invocation of this method of the form <tt>dst.append($x$)</tt> |
|
1532 |
* behaves in exactly the same way as the invocation |
|
1533 |
* |
|
1534 |
* <pre> |
|
1535 |
* dst.put($x$) </pre> |
|
1536 |
* |
|
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 | 1539 |
* |
1540 |
* @return This buffer |
|
1541 |
* |
|
1542 |
* @throws BufferOverflowException |
|
1543 |
* If there is insufficient space in this buffer |
|
1544 |
* |
|
1545 |
* @throws ReadOnlyBufferException |
|
1546 |
* If this buffer is read-only |
|
1547 |
* |
|
1548 |
* @since 1.5 |
|
1549 |
*/ |
|
1550 |
public $Type$Buffer append($type$ $x$) { |
|
1551 |
return put($x$); |
|
1552 |
} |
|
1553 |
||
1554 |
#end[char] |
|
1555 |
||
1556 |
||
1557 |
// -- Other byte stuff: Access to binary data -- |
|
1558 |
||
1559 |
#if[!byte] |
|
1560 |
||
1561 |
/** |
|
1562 |
* Retrieves this buffer's byte order. |
|
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 | 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 | 1568 |
* href="ByteBuffer.html#views">view</a> of a byte buffer is that of the |
1569 |
* byte buffer at the moment that the view is created. </p> |
|
1570 |
* |
|
1571 |
* @return This buffer's byte order |
|
1572 |
*/ |
|
1573 |
public abstract ByteOrder order(); |
|
1574 |
||
1575 |
#end[!byte] |
|
1576 |
||
1577 |
#if[byte] |
|
1578 |
||
1579 |
boolean bigEndian // package-private |
|
1580 |
= true; |
|
1581 |
boolean nativeByteOrder // package-private |
|
1582 |
= (Bits.byteOrder() == ByteOrder.BIG_ENDIAN); |
|
1583 |
||
1584 |
/** |
|
1585 |
* Retrieves this buffer's byte order. |
|
1586 |
* |
|
1587 |
* <p> The byte order is used when reading or writing multibyte values, and |
|
1588 |
* when creating buffers that are views of this byte buffer. The order of |
|
1589 |
* a newly-created byte buffer is always {@link ByteOrder#BIG_ENDIAN |
|
1590 |
* BIG_ENDIAN}. </p> |
|
1591 |
* |
|
1592 |
* @return This buffer's byte order |
|
1593 |
*/ |
|
1594 |
public final ByteOrder order() { |
|
1595 |
return bigEndian ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN; |
|
1596 |
} |
|
1597 |
||
1598 |
/** |
|
18164 | 1599 |
* Modifies this buffer's byte order. |
2 | 1600 |
* |
1601 |
* @param bo |
|
1602 |
* The new byte order, |
|
1603 |
* either {@link ByteOrder#BIG_ENDIAN BIG_ENDIAN} |
|
1604 |
* or {@link ByteOrder#LITTLE_ENDIAN LITTLE_ENDIAN} |
|
1605 |
* |
|
1606 |
* @return This buffer |
|
1607 |
*/ |
|
1608 |
public final $Type$Buffer order(ByteOrder bo) { |
|
1609 |
bigEndian = (bo == ByteOrder.BIG_ENDIAN); |
|
1610 |
nativeByteOrder = |
|
1611 |
(bigEndian == (Bits.byteOrder() == ByteOrder.BIG_ENDIAN)); |
|
1612 |
return this; |
|
1613 |
} |
|
1614 |
||
1615 |
// Unchecked accessors, for use by ByteBufferAs-X-Buffer classes |
|
1616 |
// |
|
1617 |
abstract byte _get(int i); // package-private |
|
1618 |
abstract void _put(int i, byte b); // package-private |
|
1619 |
||
1620 |
// #BIN |
|
1621 |
// |
|
1622 |
// Binary-data access methods for short, char, int, long, float, |
|
1623 |
// and double will be inserted here |
|
1624 |
||
1625 |
#end[byte] |
|
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 | 1639 |
} |