1 /*
2  * Copyright (C) 2014 The Android Open Source Project
3  * Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This code is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License version 2 only, as
8  * published by the Free Software Foundation.  Oracle designates this
9  * particular file as subject to the "Classpath" exception as provided
10  * by Oracle in the LICENSE file that accompanied this code.
11  *
12  * This code is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15  * version 2 for more details (a copy is included in the LICENSE file that
16  * accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License version
19  * 2 along with this work; if not, write to the Free Software Foundation,
20  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21  *
22  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
23  * or visit www.oracle.com if you need additional information or have any
24  * questions.
25  */
26 
27 // -- This file was mechanically generated: Do not edit! -- //
28 // Android-note: This file is generated by ojluni/src/tools/gensrc_android.sh.
29 
30 package java.nio;
31 
32 import java.util.Objects;
33 import libcore.io.Memory;
34 
35 /**
36 
37  * A read/write HeapByteBuffer.
38 
39 
40 
41 
42 
43 
44  */
45 // Android-changed: Make it final as no subclasses exist.
46 final class HeapByteBuffer
47     extends ByteBuffer
48 {
49     // Android-removed: Removed unused constants.
50     /*
51     // Cached array base offset
52     private static final long ARRAY_BASE_OFFSET = UNSAFE.arrayBaseOffset(byte[].class);
53 
54     // Cached array index scale
55     private static final long ARRAY_INDEX_SCALE = UNSAFE.arrayIndexScale(byte[].class);
56     */
57 
58     // For speed these fields are actually declared in X-Buffer;
59     // these declarations are here as documentation
60     /*
61 
62     protected final byte[] hb;
63     protected final int offset;
64 
65     */
66     // Android-removed: Removed MemorySegmentProxy to be supported yet.
HeapByteBuffer(int cap, int lim)67     HeapByteBuffer(int cap, int lim) {            // package-private
68 
69         // Android-changed: Merge the Read-only buffer class with this Read-Write buffer class.
70         // super(-1, 0, lim, cap, new byte[cap], 0);
71         this(cap, lim, false);
72         /*
73         hb = new byte[cap];
74         offset = 0;
75         */
76         // Android-removed: buffer.address is only used by Direct*Buffer.
77         // this.address = ARRAY_BASE_OFFSET;
78 
79 
80 
81 
82     }
83 
84 
85    // Android-added: Merge the Read-only buffer class with this Read-Write buffer class.
HeapByteBuffer(int cap, int lim, boolean isReadOnly)86     private HeapByteBuffer(int cap, int lim, boolean isReadOnly) {
87         super(-1, 0, lim, cap, new byte[cap], 0);
88         this.isReadOnly = isReadOnly;
89     }
90 
91 
92     // Android-removed: Removed MemorySegmentProxy to be supported yet.
HeapByteBuffer(byte[] buf, int off, int len)93     HeapByteBuffer(byte[] buf, int off, int len) { // package-private
94 
95         // Android-changed: Merge the Read-only buffer class with this Read-Write buffer class.
96         // super(-1, off, off + len, buf.length, buf, 0);
97         this(buf, off, len, false);
98         /*
99         hb = buf;
100         offset = 0;
101         */
102         // Android-removed: buffer.address is only used by Direct*Buffer.
103         // this.address = ARRAY_BASE_OFFSET;
104 
105 
106 
107 
108     }
109 
110 
111    // Android-added: Merge the Read-only buffer class with this Read-Write buffer class.
HeapByteBuffer(byte[] buf, int off, int len, boolean isReadOnly)112     private HeapByteBuffer(byte[] buf, int off, int len, boolean isReadOnly) {
113         super(-1, off, off + len, buf.length, buf, 0);
114         this.isReadOnly = isReadOnly;
115     }
116 
117 
118     // Android-changed: Merge the Read-only buffer class with this Read-Write buffer class.
119     // Android-changed: Make the method private.
120     // Android-removed: Removed MemorySegmentProxy to be supported yet.
HeapByteBuffer(byte[] buf, int mark, int pos, int lim, int cap, int off, boolean isReadOnly)121     private HeapByteBuffer(byte[] buf,
122                                    int mark, int pos, int lim, int cap,
123                                    int off, boolean isReadOnly)
124     {
125 
126         super(mark, pos, lim, cap, buf, off);
127         // Android-changed: Merge the Read-only buffer class with this Read-Write buffer class.
128         this.isReadOnly = isReadOnly;
129         /*
130         hb = buf;
131         offset = off;
132         */
133         // Android-removed: buffer.address is only used by Direct*Buffer.
134         // this.address = ARRAY_BASE_OFFSET + off * ARRAY_INDEX_SCALE;
135 
136 
137 
138 
139     }
140 
slice()141     public ByteBuffer slice() {
142         int pos = this.position();
143         int lim = this.limit();
144         int rem = (pos <= lim ? lim - pos : 0);
145         return new HeapByteBuffer(hb,
146                 -1,
147                 0,
148                 rem,
149                 rem,
150         // Android-removed: Removed MemorySegmentProxy not supported yet.
151                 pos + offset,
152         // Android-changed: Merge the Read-only buffer class with this Read-Write buffer class.
153                 isReadOnly);
154     }
155 
156     @Override
slice(int index, int length)157     public ByteBuffer slice(int index, int length) {
158         Objects.checkFromIndexSize(index, length, limit());
159         return new HeapByteBuffer(hb,
160                 -1,
161                 0,
162                 length,
163                 length,
164         // Android-removed: Removed MemorySegmentProxy not supported yet.
165                 index + offset,
166         // Android-changed: Merge the Read-only buffer class with this Read-Write buffer class.
167                 isReadOnly);
168     }
169 
duplicate()170     public ByteBuffer duplicate() {
171         return new HeapByteBuffer(hb,
172                 this.markValue(),
173                 this.position(),
174                 this.limit(),
175                 this.capacity(),
176         // Android-removed: Removed MemorySegmentProxy not supported yet.
177                 offset,
178         // Android-changed: Merge the Read-only buffer class with this Read-Write buffer class.
179                 isReadOnly);
180     }
181 
asReadOnlyBuffer()182     public ByteBuffer asReadOnlyBuffer() {
183 
184         // Android-removed: Removed MemorySegmentProxy not supported yet.
185         // Android-changed: Merge the Read-only buffer class with this Read-Write buffer class.
186         /*
187         return new HeapByteBufferR(hb,
188                                      this.markValue(),
189                                      this.position(),
190                                      this.limit(),
191                                      this.capacity(),
192                                      offset, segment);
193         */
194         return new HeapByteBuffer(hb,
195                 this.markValue(),
196                 this.position(),
197                 this.limit(),
198                 this.capacity(),
199                 offset,
200                 true /* isReadOnly */);
201 
202 
203 
204     }
205 
206 
207 
208     // Android-changed:  Make it private as no subclasses exist.
ix(int i)209     private int ix(int i) {
210         return i + offset;
211     }
212 
213 
byteOffset(long i)214     private long byteOffset(long i) {
215         return address + i;
216     }
217 
218 
219     @Override
get()220     public byte get() {
221         return hb[ix(nextGetIndex())];
222     }
223 
224     @Override
get(int i)225     public byte get(int i) {
226         return hb[ix(checkIndex(i))];
227     }
228 
229 
230 
231 
232 
233 
234 
235 
236     @Override
get(byte[] dst, int offset, int length)237     public ByteBuffer get(byte[] dst, int offset, int length) {
238         checkScope();
239         Objects.checkFromIndexSize(offset, length, dst.length);
240         int pos = position();
241         if (length > limit() - pos)
242             throw new BufferUnderflowException();
243         System.arraycopy(hb, ix(pos), dst, offset, length);
244         position(pos + length);
245         return this;
246     }
247 
248     @Override
get(int index, byte[] dst, int offset, int length)249     public ByteBuffer get(int index, byte[] dst, int offset, int length) {
250         checkScope();
251         Objects.checkFromIndexSize(index, length, limit());
252         Objects.checkFromIndexSize(offset, length, dst.length);
253         System.arraycopy(hb, ix(index), dst, offset, length);
254         return this;
255     }
256 
isDirect()257     public boolean isDirect() {
258         return false;
259     }
260 
261 
262 
263     @Override
isReadOnly()264     public boolean isReadOnly() {
265         // Android-changed: Merge the Read-only buffer class with this Read-Write buffer class.
266         return isReadOnly;
267     }
268 
269     @Override
put(byte x)270     public ByteBuffer put(byte x) {
271 
272         // Android-added: Merge the Read-only buffer class with this Read-Write buffer class.
273         throwIfReadOnly();
274         hb[ix(nextPutIndex())] = x;
275         return this;
276 
277 
278 
279     }
280 
281     @Override
put(int i, byte x)282     public ByteBuffer put(int i, byte x) {
283 
284         // Android-added: Merge the Read-only buffer class with this Read-Write buffer class.
285         throwIfReadOnly();
286         hb[ix(checkIndex(i))] = x;
287         return this;
288 
289 
290 
291     }
292 
293     @Override
put(byte[] src, int offset, int length)294     public ByteBuffer put(byte[] src, int offset, int length) {
295 
296         // Android-added: Merge the Read-only buffer class with this Read-Write buffer class.
297         throwIfReadOnly();
298         checkScope();
299         Objects.checkFromIndexSize(offset, length, src.length);
300         int pos = position();
301         if (length > limit() - pos)
302             throw new BufferOverflowException();
303         System.arraycopy(src, offset, hb, ix(pos), length);
304         position(pos + length);
305         return this;
306 
307 
308 
309     }
310 
311     @Override
put(ByteBuffer src)312     public ByteBuffer put(ByteBuffer src) {
313 
314         checkScope();
315 
316         // Android-note: The super class speed-up this operation with Memory.memmove, and arraycopy.
317         super.put(src);
318 
319 
320 
321 
322 
323 
324 
325 
326 
327 
328 
329 
330 
331 
332 
333 
334 
335 
336 
337 
338 
339 
340 
341 
342 
343 
344         return this;
345 
346 
347 
348     }
349 
350     @Override
put(int index, ByteBuffer src, int offset, int length)351     public ByteBuffer put(int index, ByteBuffer src, int offset, int length) {
352 
353         checkScope();
354         super.put(index, src, offset, length);
355         return this;
356 
357 
358 
359     }
360 
361     @Override
put(int index, byte[] src, int offset, int length)362     public ByteBuffer put(int index, byte[] src, int offset, int length) {
363 
364         checkScope();
365         Objects.checkFromIndexSize(index, length, limit());
366         Objects.checkFromIndexSize(offset, length, src.length);
367         // Android-added: Merge the Read-only buffer class with this Read-Write buffer class.
368         throwIfReadOnly();
369         System.arraycopy(src, offset, hb, ix(index), length);
370         return this;
371 
372 
373 
374     }
375 
376 
377 
378 
379 
380 
381 
382 
383 
384 
385 
386 
387 
388 
389 
390 
391 
392 
393 
394 
395 
396 
397 
398 
399 
400 
401     @Override
compact()402     public ByteBuffer compact() {
403 
404         // Android-added: Merge the Read-only buffer class with this Read-Write buffer class.
405         throwIfReadOnly();
406         int pos = position();
407         int lim = limit();
408         assert (pos <= lim);
409         int rem = (pos <= lim ? lim - pos : 0);
410         System.arraycopy(hb, ix(pos), hb, ix(0), rem);
411         position(rem);
412         limit(capacity());
413         discardMark();
414         return this;
415 
416 
417 
418     }
419 
420 
421 
422 
423 
424     @Override
_get(int i)425     byte _get(int i) {                          // package-private
426         return hb[i];
427     }
428 
429     @Override
_put(int i, byte b)430     void _put(int i, byte b) {                  // package-private
431 
432         // Android-added: Merge the Read-only buffer class with this Read-Write buffer class.
433         throwIfReadOnly();
434         hb[i] = b;
435 
436 
437 
438     }
439 
440     // char
441 
442 
443 
444     @Override
getChar()445     public char getChar() {
446         // Android-changed: Use Bits instead of ScopedMemoryAccess to be supported yet.
447         // return SCOPED_MEMORY_ACCESS.getCharUnaligned(scope(), hb, byteOffset(nextGetIndex(2)), bigEndian);
448         return Bits.getChar(this, ix(nextGetIndex(2)), bigEndian);
449     }
450 
451     @Override
getChar(int i)452     public char getChar(int i) {
453         // Android-changed: Use Bits instead of ScopedMemoryAccess to be supported yet.
454         // return SCOPED_MEMORY_ACCESS.getCharUnaligned(scope(), hb, byteOffset(checkIndex(i, 2)), bigEndian);
455         return Bits.getChar(this, ix(checkIndex(i, 2)), bigEndian);
456     }
457 
458 
459 
460     @Override
putChar(char x)461     public ByteBuffer putChar(char x) {
462 
463         // Android-added: Merge the Read-only buffer class with this Read-Write buffer class.
464         throwIfReadOnly();
465         // Android-changed: Use Bits instead of ScopedMemoryAccess to be supported yet.
466         // SCOPED_MEMORY_ACCESS.putCharUnaligned(scope(), hb, byteOffset(nextPutIndex(2)), x, bigEndian);
467         Bits.putChar(this, ix(nextPutIndex(2)), x, bigEndian);
468         return this;
469 
470 
471 
472     }
473 
474     // BEGIN Android-added: {get,put}*Unchecked() accessors.
475     @Override
getCharUnchecked(int i)476     char getCharUnchecked(int i) {
477         return Bits.getChar(this, ix(i), bigEndian);
478     }
479 
480     @Override
getUnchecked(int pos, char[] dst, int dstOffset, int length)481     void getUnchecked(int pos, char[] dst, int dstOffset, int length) {
482         Memory.unsafeBulkGet(dst, dstOffset, length * 2, hb, ix(pos), 2, !nativeByteOrder);
483     }
484     // END Android-added: {get,put}*Unchecked() accessors.
485 
486     @Override
putChar(int i, char x)487     public ByteBuffer putChar(int i, char x) {
488 
489         // Android-added: Merge the Read-only buffer class with this Read-Write buffer class.
490         throwIfReadOnly();
491         // Android-changed: Use Bits instead of ScopedMemoryAccess to be supported yet.
492         // SSCOPED_MEMORY_ACCESS.putCharUnaligned(scope(), hb, byteOffset(checkIndex(i, 2)), x, bigEndian);
493         Bits.putChar(this, ix(checkIndex(i, 2)), x, bigEndian);
494         return this;
495 
496 
497 
498     }
499 
500     // BEGIN Android-added: {get,put}*Unchecked() accessors.
501     @Override
putCharUnchecked(int i, char x)502     void putCharUnchecked(int i, char x) {
503         Bits.putChar(this, ix(i), x, bigEndian);
504     }
505 
506     @Override
putUnchecked(int pos, char[] src, int srcOffset, int length)507     void putUnchecked(int pos, char[] src, int srcOffset, int length) {
508         Memory.unsafeBulkPut(hb, ix(pos), length * 2, src, srcOffset, 2, !nativeByteOrder);
509     }
510     // END Android-added: {get,put}*Unchecked() accessors.
511 
512     @Override
asCharBuffer()513     public CharBuffer asCharBuffer() {
514         int pos = position();
515         int size = (limit() - pos) >> 1;
516         // Android-removed: buffer.address is only used by Direct*Buffer.
517         // long addr = address + pos;
518         // Android-changed: Merge the big and little endian buffer class.
519         /*
520         return (bigEndian
521                 ? (CharBuffer)(new ByteBufferAsCharBufferB(this,
522                                                                -1,
523                                                                0,
524                                                                size,
525                                                                size,
526                                                                addr, segment))
527                 : (CharBuffer)(new ByteBufferAsCharBufferL(this,
528                                                                -1,
529                                                                0,
530                                                                size,
531                                                                size,
532                                                                addr, segment)));
533         */
534         return new ByteBufferAsCharBuffer(this,
535                 -1,
536                 0,
537                 size,
538                 size,
539                 pos,
540                 order());
541     }
542 
543 
544     // short
545 
546 
547 
548     @Override
getShort()549     public short getShort() {
550         // Android-changed: Use Bits instead of ScopedMemoryAccess to be supported yet.
551         // return SCOPED_MEMORY_ACCESS.getShortUnaligned(scope(), hb, byteOffset(nextGetIndex(2)), bigEndian);
552         return Bits.getShort(this, ix(nextGetIndex(2)), bigEndian);
553     }
554 
555     @Override
getShort(int i)556     public short getShort(int i) {
557         // Android-changed: Use Bits instead of ScopedMemoryAccess to be supported yet.
558         // return SCOPED_MEMORY_ACCESS.getShortUnaligned(scope(), hb, byteOffset(checkIndex(i, 2)), bigEndian);
559         return Bits.getShort(this, ix(checkIndex(i, 2)), bigEndian);
560     }
561 
562 
563 
564     // BEGIN Android-added: {get,put}*Unchecked() accessors.
565     @Override
getShortUnchecked(int i)566     short getShortUnchecked(int i) {
567         return Bits.getShort(this, ix(i), bigEndian);
568     }
569 
570     @Override
getUnchecked(int pos, short[] dst, int dstOffset, int length)571     void getUnchecked(int pos, short[] dst, int dstOffset, int length) {
572         Memory.unsafeBulkGet(dst, dstOffset, length * 2, hb, ix(pos), 2, !nativeByteOrder);
573     }
574     // END Android-added: {get,put}*Unchecked() accessors.
575 
576     @Override
putShort(short x)577     public ByteBuffer putShort(short x) {
578 
579         // Android-added: Merge the Read-only buffer class with this Read-Write buffer class.
580         throwIfReadOnly();
581         // Android-changed: Use Bits instead of ScopedMemoryAccess to be supported yet.
582         // SCOPED_MEMORY_ACCESS.putShortUnaligned(scope(), hb, byteOffset(nextPutIndex(2)), x, bigEndian);
583         Bits.putShort(this, ix(nextPutIndex(2)), x, bigEndian);
584         return this;
585 
586 
587 
588     }
589 
590     @Override
putShort(int i, short x)591     public ByteBuffer putShort(int i, short x) {
592 
593         // Android-changed: Use Bits instead of ScopedMemoryAccess to be supported yet.
594         // SCOPED_MEMORY_ACCESS.putShortUnaligned(scope(), hb, byteOffset(checkIndex(i, 2)), x, bigEndian);
595         Bits.putShort(this, ix(checkIndex(i, 2)), x, bigEndian);
596         return this;
597 
598 
599 
600     }
601 
602     // BEGIN Android-added: {get,put}*Unchecked() accessors.
603     @Override
putShortUnchecked(int i, short x)604     void putShortUnchecked(int i, short x) {
605         Bits.putShort(this, ix(i), x, bigEndian);
606     }
607 
608     @Override
putUnchecked(int pos, short[] src, int srcOffset, int length)609     void putUnchecked(int pos, short[] src, int srcOffset, int length) {
610         Memory.unsafeBulkPut(hb, ix(pos), length * 2, src, srcOffset, 2, !nativeByteOrder);
611     }
612     // END Android-added: {get,put}*Unchecked() accessors.
613 
614     @Override
asShortBuffer()615     public ShortBuffer asShortBuffer() {
616         int pos = position();
617         int size = (limit() - pos) >> 1;
618         // Android-removed: buffer.address is only used by Direct*Buffer.
619         // long addr = address + pos;
620         // Android-changed: Merge the big and little endian buffer class.
621         /*
622         return (bigEndian
623                 ? (ShortBuffer)(new ByteBufferAsShortBufferB(this,
624                                                                  -1,
625                                                                  0,
626                                                                  size,
627                                                                  size,
628                                                                  addr, segment))
629                 : (ShortBuffer)(new ByteBufferAsShortBufferL(this,
630                                                                  -1,
631                                                                  0,
632                                                                  size,
633                                                                  size,
634                                                                  addr, segment)));
635         */
636         return new ByteBufferAsShortBuffer(this,
637                 -1,
638                 0,
639                 size,
640                 size,
641                 pos,
642                 order());
643     }
644 
645 
646     // int
647 
648 
649 
650     @Override
getInt()651     public int getInt() {
652         // Android-changed: Use Bits instead of ScopedMemoryAccess to be supported yet.
653         // return SCOPED_MEMORY_ACCESS.getIntUnaligned(scope(), hb, byteOffset(nextGetIndex(4)), bigEndian);
654         return Bits.getInt(this, ix(nextGetIndex(4)), bigEndian);
655     }
656 
657     @Override
getInt(int i)658     public int getInt(int i) {
659         // Android-changed: Use Bits instead of ScopedMemoryAccess to be supported yet.
660         // return SCOPED_MEMORY_ACCESS.getIntUnaligned(scope(), hb, byteOffset(checkIndex(i, 4)), bigEndian);
661         return Bits.getInt(this, ix(checkIndex(i, 4)), bigEndian);
662     }
663 
664 
665 
666     // BEGIN Android-added: {get,put}*Unchecked() accessors.
667     @Override
getIntUnchecked(int i)668     int getIntUnchecked(int i) {
669         return Bits.getInt(this, ix(i), bigEndian);
670     }
671 
672     @Override
getUnchecked(int pos, int[] dst, int dstOffset, int length)673     void getUnchecked(int pos, int[] dst, int dstOffset, int length) {
674         Memory.unsafeBulkGet(dst, dstOffset, length * 4, hb, ix(pos), 4, !nativeByteOrder);
675     }
676     // END Android-added: {get,put}*Unchecked() accessors.
677 
678     @Override
putInt(int x)679     public ByteBuffer putInt(int x) {
680 
681         // Android-added: Merge the Read-only buffer class with this Read-Write buffer class.
682         throwIfReadOnly();
683         // Android-changed: Use Bits instead of ScopedMemoryAccess to be supported yet.
684         // SCOPED_MEMORY_ACCESS.putIntUnaligned(scope(), hb, byteOffset(nextPutIndex(4)), x, bigEndian);
685         Bits.putInt(this, ix(nextPutIndex(4)), x, bigEndian);
686         return this;
687 
688 
689 
690     }
691 
692     @Override
putInt(int i, int x)693     public ByteBuffer putInt(int i, int x) {
694 
695         // Android-added: Merge the Read-only buffer class with this Read-Write buffer class.
696         throwIfReadOnly();
697         // Android-changed: Use Bits instead of ScopedMemoryAccess to be supported yet.
698         // SCOPED_MEMORY_ACCESS.putIntUnaligned(scope(), hb, byteOffset(checkIndex(i, 4)), x, bigEndian);
699         Bits.putInt(this, ix(checkIndex(i, 4)), x, bigEndian);
700         return this;
701 
702 
703 
704     }
705 
706     // BEGIN Android-added: {get,put}*Unchecked() accessors.
707     @Override
putIntUnchecked(int i, int x)708     void putIntUnchecked(int i, int x) {
709         Bits.putInt(this, ix(i), x, bigEndian);
710     }
711 
712     @Override
putUnchecked(int pos, int[] src, int srcOffset, int length)713     void putUnchecked(int pos, int[] src, int srcOffset, int length) {
714         Memory.unsafeBulkPut(hb, ix(pos), length * 4, src, srcOffset, 4, !nativeByteOrder);
715     }
716     // END Android-added: {get,put}*Unchecked() accessors.
717 
718     @Override
asIntBuffer()719     public IntBuffer asIntBuffer() {
720         int pos = position();
721         int size = (limit() - pos) >> 2;
722         // Android-removed: buffer.address is only used by Direct*Buffer.
723         // long addr = address + pos;
724         // Android-changed: Merge the big and little endian buffer class.
725         /*
726         return (bigEndian
727                 ? (IntBuffer)(new ByteBufferAsIntBufferB(this,
728                                                              -1,
729                                                              0,
730                                                              size,
731                                                              size,
732                                                              addr, segment))
733                 : (IntBuffer)(new ByteBufferAsIntBufferL(this,
734                                                              -1,
735                                                              0,
736                                                              size,
737                                                              addr, segment)));
738         */
739         return new ByteBufferAsIntBuffer(this,
740                 -1,
741                 0,
742                 size,
743                 size,
744                 pos,
745                 order());
746     }
747 
748 
749     // long
750 
751 
752 
753     @Override
getLong()754     public long getLong() {
755         // Android-changed: Use Bits instead of ScopedMemoryAccess to be supported yet.
756         // return SCOPED_MEMORY_ACCESS.getLongUnaligned(scope(), hb, byteOffset(nextGetIndex(8)), bigEndian);
757         return Bits.getLong(this, ix(nextGetIndex(8)), bigEndian);
758     }
759 
760     @Override
getLong(int i)761     public long getLong(int i) {
762         // Android-changed: Use Bits instead of ScopedMemoryAccess to be supported yet.
763         // return SCOPED_MEMORY_ACCESS.getLongUnaligned(scope(), hb, byteOffset(checkIndex(i, 8)), bigEndian);
764         return Bits.getLong(this, ix(checkIndex(i, 8)), bigEndian);
765     }
766 
767 
768 
769     // BEGIN Android-added: {get,put}*Unchecked() accessors.
770     @Override
getLongUnchecked(int i)771     long getLongUnchecked(int i) {
772         return Bits.getLong(this, ix(i), bigEndian);
773     }
774 
775     @Override
getUnchecked(int pos, long[] dst, int dstOffset, int length)776     void getUnchecked(int pos, long[] dst, int dstOffset, int length) {
777         Memory.unsafeBulkGet(dst, dstOffset, length * 8, hb, ix(pos), 8, !nativeByteOrder);
778     }
779     // END Android-added: {get,put}*Unchecked() accessors.
780 
781     @Override
putLong(long x)782     public ByteBuffer putLong(long x) {
783 
784         // Android-added: Merge the Read-only buffer class with this Read-Write buffer class.
785         throwIfReadOnly();
786         // Android-changed: Use Bits instead of ScopedMemoryAccess to be supported yet.
787         // SCOPED_MEMORY_ACCESS.putLongUnaligned(scope(), hb, byteOffset(nextPutIndex(8)), x, bigEndian);
788         Bits.putLong(this, ix(nextPutIndex(8)), x, bigEndian);
789         return this;
790 
791 
792 
793     }
794 
795     @Override
putLong(int i, long x)796     public ByteBuffer putLong(int i, long x) {
797 
798         // Android-added: Merge the Read-only buffer class with this Read-Write buffer class.
799         throwIfReadOnly();
800         // Android-changed: Use Bits instead of ScopedMemoryAccess to be supported yet.
801         // SCOPED_MEMORY_ACCESS.putLongUnaligned(scope(), hb, byteOffset(checkIndex(i, 8)), x, bigEndian);
802         Bits.putLong(this, ix(checkIndex(i, 8)), x, bigEndian);
803         return this;
804 
805 
806 
807     }
808 
809     // BEGIN Android-added: {get,put}*Unchecked() accessors.
810     @Override
putLongUnchecked(int i, long x)811     void putLongUnchecked(int i, long x) {
812         Bits.putLong(this, ix(i), x, bigEndian);
813     }
814 
815     @Override
putUnchecked(int pos, long[] src, int srcOffset, int length)816     void putUnchecked(int pos, long[] src, int srcOffset, int length) {
817         Memory.unsafeBulkPut(hb, ix(pos), length * 8, src, srcOffset, 8, !nativeByteOrder);
818     }
819     // END Android-added: {get,put}*Unchecked() accessors.
820 
821     @Override
asLongBuffer()822     public LongBuffer asLongBuffer() {
823         int pos = position();
824         int size = (limit() - pos) >> 3;
825         // Android-removed: buffer.address is only used by Direct*Buffer.
826         // long addr = address + pos;
827         // Android-changed: Merge the big and little endian buffer class.
828         /*
829         return (bigEndian
830                 ? (LongBuffer)(new ByteBufferAsLongBufferB(this,
831                                                                -1,
832                                                                0,
833                                                                size,
834                                                                size,
835                                                                addr, segment))
836                 : (LongBuffer)(new ByteBufferAsLongBufferL(this,
837                                                                -1,
838                                                                0,
839                                                                size,
840                                                                size,
841                                                                addr, segment)));
842         */
843         return new ByteBufferAsLongBuffer(this,
844                 -1,
845                 0,
846                 size,
847                 size,
848                 pos,
849                 order());
850     }
851 
852 
853     // float
854 
855 
856 
857     @Override
getFloat()858     public float getFloat() {
859         // Android-changed: Use Bits instead of ScopedMemoryAccess to be supported yet.
860         // int x = SCOPED_MEMORY_ACCESS.getIntUnaligned(scope(), hb, byteOffset(nextGetIndex(4)), bigEndian);
861         // return Float.intBitsToFloat(x);
862         return Bits.getFloat(this, ix(nextGetIndex(4)), bigEndian);
863     }
864 
865     @Override
getFloat(int i)866     public float getFloat(int i) {
867         // Android-changed: Use Bits instead of ScopedMemoryAccess to be supported yet.
868         // int x = SCOPED_MEMORY_ACCESS.getIntUnaligned(scope(), hb, byteOffset(checkIndex(i, 4)), bigEndian);
869         // return Float.intBitsToFloat(x);
870         return Bits.getFloat(this, ix(checkIndex(i, 4)), bigEndian);
871     }
872 
873 
874 
875     // BEGIN Android-added: {get,put}*Unchecked() accessors.
876     @Override
getFloatUnchecked(int i)877     float getFloatUnchecked(int i) {
878         return Bits.getFloat(this, ix(i), bigEndian);
879     }
880 
881     @Override
getUnchecked(int pos, float[] dst, int dstOffset, int length)882     void getUnchecked(int pos, float[] dst, int dstOffset, int length) {
883         Memory.unsafeBulkGet(dst, dstOffset, length * 4, hb, ix(pos), 4, !nativeByteOrder);
884     }
885     // END Android-added: {get,put}*Unchecked() accessors.
886 
887     @Override
putFloat(float x)888     public ByteBuffer putFloat(float x) {
889 
890         // Android-added: Merge the Read-only buffer class with this Read-Write buffer class.
891         throwIfReadOnly();
892         // Android-changed: Use Bits instead of ScopedMemoryAccess to be supported yet.
893         // int y = Float.floatToRawIntBits(x);
894         // SCOPED_MEMORY_ACCESS.putIntUnaligned(scope(), hb, byteOffset(nextPutIndex(4)), y, bigEndian);
895         Bits.putFloat(this, ix(nextPutIndex(4)), x, bigEndian);
896         return this;
897 
898 
899 
900     }
901 
902     @Override
putFloat(int i, float x)903     public ByteBuffer putFloat(int i, float x) {
904 
905         // Android-added: Merge the Read-only buffer class with this Read-Write buffer class.
906         throwIfReadOnly();
907         // Android-changed: Use Bits instead of ScopedMemoryAccess to be supported yet.
908         // int y = Float.floatToRawIntBits(x);
909         // SCOPED_MEMORY_ACCESS.putIntUnaligned(scope(), hb, byteOffset(checkIndex(i, 4)), y, bigEndian);
910         Bits.putFloat(this, ix(checkIndex(i, 4)), x, bigEndian);
911         return this;
912 
913 
914 
915     }
916 
917     // BEGIN Android-added: {get,put}*Unchecked() accessors.
918     @Override
putFloatUnchecked(int i, float x)919     void putFloatUnchecked(int i, float x) {
920         Bits.putFloat(this, ix(i), x, bigEndian);
921     }
922 
923     @Override
putUnchecked(int pos, float[] src, int srcOffset, int length)924     void putUnchecked(int pos, float[] src, int srcOffset, int length) {
925         Memory.unsafeBulkPut(hb, ix(pos), length * 4, src, srcOffset, 4, !nativeByteOrder);
926     }
927     // END Android-added: {get,put}*Unchecked() accessors.
928 
929     @Override
asFloatBuffer()930     public FloatBuffer asFloatBuffer() {
931         int pos = position();
932         int size = (limit() - pos) >> 2;
933         // Android-removed: buffer.address is only used by Direct*Buffer.
934         // long addr = address + pos;
935         // Android-changed: Merge the big and little endian buffer class.
936         /*
937         return (bigEndian
938                 ? (FloatBuffer)(new ByteBufferAsFloatBufferB(this,
939                                                                  -1,
940                                                                  0,
941                                                                  size,
942                                                                  size,
943                                                                  addr, segment))
944                 : (FloatBuffer)(new ByteBufferAsFloatBufferL(this,
945                                                                  -1,
946                                                                  0,
947                                                                  size,
948                                                                  size,
949                                                                  addr, segment)));
950         */
951         return new ByteBufferAsFloatBuffer(this,
952                 -1,
953                 0,
954                 size,
955                 size,
956                 pos,
957                 order());
958     }
959 
960 
961     // double
962 
963 
964 
965     @Override
getDouble()966     public double getDouble() {
967         // Android-changed: Use Bits instead of ScopedMemoryAccess to be supported yet.
968         // long x = SCOPED_MEMORY_ACCESS.getLongUnaligned(scope(), hb, byteOffset(nextGetIndex(8)), bigEndian);
969         // return Double.longBitsToDouble(x);
970         return Bits.getDouble(this, ix(nextGetIndex(8)), bigEndian);
971     }
972 
973     @Override
getDouble(int i)974     public double getDouble(int i) {
975         // Android-changed: Use Bits instead of ScopedMemoryAccess to be supported yet.
976         // long x = SCOPED_MEMORY_ACCESS.getLongUnaligned(scope(), hb, byteOffset(checkIndex(i, 8)), bigEndian);
977         // return Double.longBitsToDouble(x);
978         return Bits.getDouble(this, ix(checkIndex(i, 8)), bigEndian);
979     }
980 
981 
982 
983     // BEGIN Android-added: {get,put}*Unchecked() accessors.
984     @Override
getDoubleUnchecked(int i)985     double getDoubleUnchecked(int i) {
986         return Bits.getDouble(this, ix(i), bigEndian);
987     }
988 
989     @Override
getUnchecked(int pos, double[] dst, int dstOffset, int length)990     void getUnchecked(int pos, double[] dst, int dstOffset, int length) {
991         Memory.unsafeBulkGet(dst, dstOffset, length * 8, hb, ix(pos), 8, !nativeByteOrder);
992     }
993     // END Android-added: {get,put}*Unchecked() accessors.
994 
995     @Override
putDouble(double x)996     public ByteBuffer putDouble(double x) {
997 
998         // Android-added: Merge the Read-only buffer class with this Read-Write buffer class.
999         throwIfReadOnly();
1000         // Android-changed: Use Bits instead of ScopedMemoryAccess to be supported yet.
1001         // long y = Double.doubleToRawLongBits(x);
1002         // SCOPED_MEMORY_ACCESS.putLongUnaligned(scope(), hb, byteOffset(nextPutIndex(8)), y, bigEndian);
1003         Bits.putDouble(this, ix(nextPutIndex(8)), x, bigEndian);
1004         return this;
1005 
1006 
1007 
1008     }
1009 
1010     @Override
putDouble(int i, double x)1011     public ByteBuffer putDouble(int i, double x) {
1012 
1013         // Android-added: Merge the Read-only buffer class with this Read-Write buffer class.
1014         throwIfReadOnly();
1015         // Android-changed: Use Bits instead of ScopedMemoryAccess to be supported yet.
1016         // long y = Double.doubleToRawLongBits(x);
1017         // SCOPED_MEMORY_ACCESS.putLongUnaligned(scope(), hb, byteOffset(checkIndex(i, 8)), y, bigEndian);
1018         Bits.putDouble(this, ix(checkIndex(i, 8)), x, bigEndian);
1019         return this;
1020 
1021 
1022 
1023     }
1024 
1025     // BEGIN Android-added: {get,put}*Unchecked() accessors.
1026     @Override
putDoubleUnchecked(int i, double x)1027     void putDoubleUnchecked(int i, double x) {
1028         Bits.putDouble(this, ix(i), x, bigEndian);
1029     }
1030 
1031     @Override
putUnchecked(int pos, double[] src, int srcOffset, int length)1032     void putUnchecked(int pos, double[] src, int srcOffset, int length) {
1033         Memory.unsafeBulkPut(hb, ix(pos), length * 8, src, srcOffset, 8, !nativeByteOrder);
1034     }
1035     // END Android-added: {get,put}*Unchecked() accessors.
1036 
1037     @Override
asDoubleBuffer()1038     public DoubleBuffer asDoubleBuffer() {
1039         int pos = position();
1040         int size = (limit() - pos) >> 3;
1041         // Android-removed: buffer.address is only used by Direct*Buffer.
1042         // long addr = address + pos;
1043         // Android-changed: Merge the big and little endian buffer class.
1044         /*
1045         return (bigEndian
1046                 ? (DoubleBuffer)(new ByteBufferAsDoubleBufferB(this,
1047                                                                    -1,
1048                                                                    0,
1049                                                                    size,
1050                                                                    size,
1051                                                                    addr, segment))
1052                 : (DoubleBuffer)(new ByteBufferAsDoubleBufferL(this,
1053                                                                    -1,
1054                                                                    0,
1055                                                                    size,
1056                                                                    size,
1057                                                                    addr, segment)));
1058         */
1059         return new ByteBufferAsDoubleBuffer(this,
1060                 -1,
1061                 0,
1062                 size,
1063                 size,
1064                 pos,
1065                 order());
1066     }
1067 
1068 
1069 
1070 
1071 
1072 
1073 
1074 
1075 
1076 
1077 
1078 
1079 
1080 
1081 
1082 
1083 
1084 
1085 
1086 
1087 
1088 
1089 
1090 
1091 
1092 
1093 
1094 
1095 
1096 
1097 
1098 
1099 
1100 
1101 
1102 
1103 
1104 
1105 
1106 
1107 
1108 
1109 
1110 
1111 
1112 
1113 
1114 
1115     // Android-added: Merge the Read-only buffer class with this Read-Write buffer class.
throwIfReadOnly()1116     private void throwIfReadOnly() {
1117         if (isReadOnly) {
1118             throw new ReadOnlyBufferException();
1119         }
1120     }
1121 }
1122