< prev index next >
src/java.base/share/classes/java/nio/Heap-X-Buffer.java.template
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
@@ -36,10 +36,12 @@
* ReadOnlyBufferException} and overriding the view-buffer methods to return an
* instance of this class rather than of the superclass.
#end[rw]
*/
+import java.util.Objects;
+
class Heap$Type$Buffer$RW$
extends {#if[ro]?Heap}$Type$Buffer
{
// Cached array base offset
private static final long ARRAY_BASE_OFFSET = UNSAFE.arrayBaseOffset($type$[].class);
@@ -179,10 +181,18 @@
System.arraycopy(hb, ix(position()), dst, offset, length);
position(position() + length);
return this;
}
+ public $Type$Buffer get(int index, $type$[] dst, int offset, int length) {
+ //System.out.println("Heap absolute bulk get");
+ Objects.checkFromIndexSize(index, length, limit());
+ Objects.checkFromIndexSize(offset, length, dst.length);
+ System.arraycopy(hb, ix(index), dst, offset, length);
+ return this;
+ }
+
public boolean isDirect() {
return false;
}
#end[rw]
@@ -248,10 +258,49 @@
#else[rw]
throw new ReadOnlyBufferException();
#end[rw]
}
+ public $Type$Buffer put(int index, $type$[] src, int offset, int length) {
+ //System.out.println("Heap absolute bulk put array");
+#if[rw]
+ Objects.checkFromIndexSize(index, length, limit());
+ Objects.checkFromIndexSize(offset, length, src.length);
+ System.arraycopy(src, offset, hb, ix(index), length);
+ return this;
+#else[rw]
+ throw new ReadOnlyBufferException();
+#end[rw]
+ }
+
+ public $Type$Buffer put(int index, $Type$Buffer src, int offset,
+ int length) {
+ //System.out.println("Heap absolute bulk put buffer");
+#if[rw]
+ if (src instanceof Heap$Type$Buffer) {
+ if (index < 0)
+ throw new IndexOutOfBoundsException("Index negative: " + index);
+ Heap$Type$Buffer sb = (Heap$Type$Buffer)src;
+ Objects.checkFromIndexSize(index, length, limit());
+ Objects.checkFromIndexSize(offset, length, sb.limit());
+ System.arraycopy(sb.hb, sb.ix(offset),
+ hb, ix(index), length);
+ } else if (src.isDirect()) {
+ if (index < 0)
+ throw new IndexOutOfBoundsException("Index negative: " + index);
+ Objects.checkFromIndexSize(index, length, limit());
+ Objects.checkFromIndexSize(offset, length, src.limit());
+ src.get(offset, hb, ix(index), length);
+ } else {
+ super.put(index, src, offset, length);
+ }
+ return this;
+#else[rw]
+ throw new ReadOnlyBufferException();
+#end[rw]
+ }
+
public $Type$Buffer compact() {
#if[rw]
System.arraycopy(hb, ix(position()), hb, ix(0), remaining());
position(remaining());
limit(capacity());
< prev index next >