while (src.hasRemaining())
dst.put(src.get());
For example, the output of the following test class is:
0 1 2 3 0 1 2 3 0 1 2 3 12 13 14 15
instead of, as might be expected:
0 1 2 3 0 1 2 3 4 5 6 7 12 13 14 15
It would be better if this operation behaved like array copy and have a result as if the content of the argument buffer were first copied to a separate location and then copied into the target.
import java.nio.*;
public class OverlapTest {
public static void main(String[] args) throws Throwable {
byte[] array = new byte[32];
for (int i = 0; i < array.length; i++) {
if (i % 2 == 1)
array[i] = (byte)(i/2);;
}
ByteBuffer buf = ByteBuffer.wrap(array);
ShortBuffer shortBuf = buf.asShortBuffer();
int cap = shortBuf.capacity();
for (int i = 0; i < cap; i++) {
System.out.format("%d ", shortBuf.get(i));
}
System.out.println();
ShortBuffer lower = shortBuf.slice(0, cap/2);
ShortBuffer middle = shortBuf.slice(cap/4, cap/2);
middle.put(lower);
for (int i = 0; i < cap; i++) {
System.out.format("%d ", shortBuf.get(i));
}
System.out.println();
}
}
- csr for
-
JDK-8245866 (bf) XBuffer.put(Xbuffer src) can give unexpected result when storage overlaps
-
- Closed
-
- relates to
-
JDK-8246282 [REDO] JDK-8245121 (bf) XBuffer.put(Xbuffer src) can give unexpected result when storage overlaps
-
- Resolved
-
-
JDK-8219014 (bf) Add absolute bulk put methods which accept a source Buffer
-
- Resolved
-
-
JDK-8246183 Scanner/ScanTest.java fails due to SIGSEGV in StubRoutines::jshort_disjoint_arraycopy
-
- Closed
-
-
JDK-8242477 (bf) MappedByteBuffer should clarify copying between overlapping mappings
-
- Closed
-
-
JDK-8301195 (bf) Bulk put not consistent with API docs when buffers overlap
-
- Closed
-
- links to