5071718: (bf) Add ByteBuffer.slice(int offset, int length)
Reviewed-by: alanb, bchristi, darcy, rriggs
This commit is contained in:
parent
8f84ae5684
commit
fad1f059b0
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2000, 2018, 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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -134,8 +134,9 @@ import java.util.Spliterator;
|
|||||||
* it already contains: It leaves the limit unchanged and sets the position
|
* it already contains: It leaves the limit unchanged and sets the position
|
||||||
* to zero. </p></li>
|
* to zero. </p></li>
|
||||||
*
|
*
|
||||||
* <li><p> {@link #slice} creates a subsequence of a buffer: It leaves the
|
* <li><p> The {@link #slice} and {@link #slice(int,int) slice(index,length)}
|
||||||
* limit and the position unchanged. </p></li>
|
* methods create a subsequence of a buffer: They leave the limit and the
|
||||||
|
* position unchanged. </p></li>
|
||||||
*
|
*
|
||||||
* <li><p> {@link #duplicate} creates a shallow copy of a buffer: It leaves
|
* <li><p> {@link #duplicate} creates a shallow copy of a buffer: It leaves
|
||||||
* the limit and the position unchanged. </p></li>
|
* the limit and the position unchanged. </p></li>
|
||||||
@ -599,6 +600,39 @@ public abstract class Buffer {
|
|||||||
*/
|
*/
|
||||||
public abstract Buffer slice();
|
public abstract Buffer slice();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new buffer whose content is a shared subsequence of
|
||||||
|
* this buffer's content.
|
||||||
|
*
|
||||||
|
* <p> The content of the new buffer will start at position {@code index}
|
||||||
|
* in this buffer, and will contain {@code length} elements. Changes to
|
||||||
|
* this buffer's content will be visible in the new buffer, and vice versa;
|
||||||
|
* the two buffers' position, limit, and mark values will be independent.
|
||||||
|
*
|
||||||
|
* <p> The new buffer's position will be zero, its capacity and its limit
|
||||||
|
* will be {@code length}, its mark will be undefined. The new buffer will
|
||||||
|
* be direct if, and only if, this buffer is direct, and it will be
|
||||||
|
* read-only if, and only if, this buffer is read-only. </p>
|
||||||
|
*
|
||||||
|
* @param index
|
||||||
|
* The position in this buffer at which the content of the new
|
||||||
|
* buffer will start; must be non-negative and no larger than
|
||||||
|
* {@link #limit() limit()}
|
||||||
|
*
|
||||||
|
* @param length
|
||||||
|
* The number of elements the new buffer will contain; must be
|
||||||
|
* non-negative and no larger than {@code limit() - index}
|
||||||
|
*
|
||||||
|
* @return The new buffer
|
||||||
|
*
|
||||||
|
* @throws IndexOutOfBoundsException
|
||||||
|
* If {@code index} is negative or greater than {@code limit()},
|
||||||
|
* {@code length} is negative, or {@code length > limit() - index}
|
||||||
|
*
|
||||||
|
* @since 13
|
||||||
|
*/
|
||||||
|
public abstract Buffer slice(int index, int length);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new buffer that shares this buffer's content.
|
* Creates a new buffer that shares this buffer's content.
|
||||||
*
|
*
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* 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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -27,9 +27,9 @@
|
|||||||
|
|
||||||
package java.nio;
|
package java.nio;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
import jdk.internal.misc.Unsafe;
|
import jdk.internal.misc.Unsafe;
|
||||||
|
|
||||||
|
|
||||||
class ByteBufferAs$Type$Buffer$RW$$BO$ // package-private
|
class ByteBufferAs$Type$Buffer$RW$$BO$ // package-private
|
||||||
extends {#if[ro]?ByteBufferAs}$Type$Buffer{#if[ro]?$BO$}
|
extends {#if[ro]?ByteBufferAs}$Type$Buffer{#if[ro]?$BO$}
|
||||||
{
|
{
|
||||||
@ -85,6 +85,18 @@ class ByteBufferAs$Type$Buffer$RW$$BO$ // package-private
|
|||||||
return new ByteBufferAs$Type$Buffer$RW$$BO$(bb, -1, 0, rem, rem, addr);
|
return new ByteBufferAs$Type$Buffer$RW$$BO$(bb, -1, 0, rem, rem, addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public $Type$Buffer slice(int index, int length) {
|
||||||
|
Objects.checkIndex(index, limit() + 1);
|
||||||
|
Objects.checkIndex(length, limit() - index + 1);
|
||||||
|
return new ByteBufferAs$Type$Buffer$RW$$BO$(bb,
|
||||||
|
-1,
|
||||||
|
0,
|
||||||
|
length,
|
||||||
|
length,
|
||||||
|
byteOffset(index));
|
||||||
|
}
|
||||||
|
|
||||||
public $Type$Buffer duplicate() {
|
public $Type$Buffer duplicate() {
|
||||||
return new ByteBufferAs$Type$Buffer$RW$$BO$(bb,
|
return new ByteBufferAs$Type$Buffer$RW$$BO$(bb,
|
||||||
this.markValue(),
|
this.markValue(),
|
||||||
|
@ -218,14 +218,17 @@ class Direct$Type$Buffer$RW$$BO$
|
|||||||
return new Direct$Type$Buffer$RW$$BO$(this, -1, 0, rem, rem, off);
|
return new Direct$Type$Buffer$RW$$BO$(this, -1, 0, rem, rem, off);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if[byte]
|
@Override
|
||||||
public $Type$Buffer slice(int pos, int lim) {
|
public $Type$Buffer slice(int index, int length) {
|
||||||
assert (pos >= 0);
|
Objects.checkIndex(index, limit() + 1);
|
||||||
assert (pos <= lim);
|
Objects.checkIndex(length, limit() - index + 1);
|
||||||
int rem = lim - pos;
|
return new Direct$Type$Buffer$RW$$BO$(this,
|
||||||
return new Direct$Type$Buffer$RW$$BO$(this, -1, 0, rem, rem, pos);
|
-1,
|
||||||
|
0,
|
||||||
|
length,
|
||||||
|
length,
|
||||||
|
index);
|
||||||
}
|
}
|
||||||
#end[byte]
|
|
||||||
|
|
||||||
public $Type$Buffer duplicate() {
|
public $Type$Buffer duplicate() {
|
||||||
return new Direct$Type$Buffer$RW$$BO$(this,
|
return new Direct$Type$Buffer$RW$$BO$(this,
|
||||||
|
@ -27,6 +27,8 @@
|
|||||||
|
|
||||||
package java.nio;
|
package java.nio;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
#if[rw]
|
#if[rw]
|
||||||
* A read/write Heap$Type$Buffer.
|
* A read/write Heap$Type$Buffer.
|
||||||
@ -38,8 +40,6 @@ package java.nio;
|
|||||||
#end[rw]
|
#end[rw]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
class Heap$Type$Buffer$RW$
|
class Heap$Type$Buffer$RW$
|
||||||
extends {#if[ro]?Heap}$Type$Buffer
|
extends {#if[ro]?Heap}$Type$Buffer
|
||||||
{
|
{
|
||||||
@ -112,19 +112,17 @@ class Heap$Type$Buffer$RW$
|
|||||||
this.position() + offset);
|
this.position() + offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if[byte]
|
@Override
|
||||||
$Type$Buffer slice(int pos, int lim) {
|
public $Type$Buffer slice(int index, int length) {
|
||||||
assert (pos >= 0);
|
Objects.checkIndex(index, limit() + 1);
|
||||||
assert (pos <= lim);
|
Objects.checkIndex(length, limit() - index + 1);
|
||||||
int rem = lim - pos;
|
|
||||||
return new Heap$Type$Buffer$RW$(hb,
|
return new Heap$Type$Buffer$RW$(hb,
|
||||||
-1,
|
-1,
|
||||||
0,
|
0,
|
||||||
rem,
|
length,
|
||||||
rem,
|
length,
|
||||||
pos + offset);
|
index + offset);
|
||||||
}
|
}
|
||||||
#end[byte]
|
|
||||||
|
|
||||||
public $Type$Buffer duplicate() {
|
public $Type$Buffer duplicate() {
|
||||||
return new Heap$Type$Buffer$RW$(hb,
|
return new Heap$Type$Buffer$RW$(hb,
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2000, 2018, 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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
package java.nio;
|
package java.nio;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
// ## If the sequence is a string, use reflection to share its array
|
// ## If the sequence is a string, use reflection to share its array
|
||||||
|
|
||||||
@ -51,6 +52,18 @@ class StringCharBuffer // package-private
|
|||||||
offset + this.position());
|
offset + this.position());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CharBuffer slice(int index, int length) {
|
||||||
|
Objects.checkIndex(index, limit() + 1);
|
||||||
|
Objects.checkIndex(length, limit() - index + 1);
|
||||||
|
return new StringCharBuffer(str,
|
||||||
|
-1,
|
||||||
|
0,
|
||||||
|
length,
|
||||||
|
length,
|
||||||
|
offset + index);
|
||||||
|
}
|
||||||
|
|
||||||
private StringCharBuffer(CharSequence s,
|
private StringCharBuffer(CharSequence s,
|
||||||
int mark,
|
int mark,
|
||||||
int pos,
|
int pos,
|
||||||
|
@ -546,6 +546,46 @@ public abstract class $Type$Buffer
|
|||||||
@Override
|
@Override
|
||||||
public abstract $Type$Buffer slice();
|
public abstract $Type$Buffer slice();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new $type$ buffer whose content is a shared subsequence of
|
||||||
|
* this buffer's content.
|
||||||
|
*
|
||||||
|
* <p> The content of the new buffer will start at position {@code index}
|
||||||
|
* in this buffer, and will contain {@code length} elements. Changes to
|
||||||
|
* this buffer's content will be visible in the new buffer, and vice versa;
|
||||||
|
* the two buffers' position, limit, and mark values will be independent.
|
||||||
|
*
|
||||||
|
* <p> The new buffer's position will be zero, its capacity and its limit
|
||||||
|
* will be {@code length}, its mark will be undefined, and its byte order
|
||||||
|
* will be
|
||||||
|
#if[byte]
|
||||||
|
* {@link ByteOrder#BIG_ENDIAN BIG_ENDIAN}.
|
||||||
|
#else[byte]
|
||||||
|
* identical to that of this buffer.
|
||||||
|
#end[byte]
|
||||||
|
* The new buffer will be direct if, and only if, this buffer is direct,
|
||||||
|
* and it will be read-only if, and only if, this buffer is read-only. </p>
|
||||||
|
*
|
||||||
|
* @param index
|
||||||
|
* The position in this buffer at which the content of the new
|
||||||
|
* buffer will start; must be non-negative and no larger than
|
||||||
|
* {@link #limit() limit()}
|
||||||
|
*
|
||||||
|
* @param length
|
||||||
|
* The number of elements the new buffer will contain; must be
|
||||||
|
* non-negative and no larger than {@code limit() - index}
|
||||||
|
*
|
||||||
|
* @return The new buffer
|
||||||
|
*
|
||||||
|
* @throws IndexOutOfBoundsException
|
||||||
|
* If {@code index} is negative or greater than {@code limit()},
|
||||||
|
* {@code length} is negative, or {@code length > limit() - index}
|
||||||
|
*
|
||||||
|
* @since 13
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public abstract $Type$Buffer slice(int index, int length);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new $type$ buffer that shares this buffer's content.
|
* Creates a new $type$ buffer that shares this buffer's content.
|
||||||
*
|
*
|
||||||
@ -1950,11 +1990,9 @@ public abstract class $Type$Buffer
|
|||||||
aligned_pos = aligned_lim = pos;
|
aligned_pos = aligned_lim = pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
return slice(aligned_pos, aligned_lim);
|
return slice(aligned_pos, aligned_lim - aligned_pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract ByteBuffer slice(int pos, int lim);
|
|
||||||
|
|
||||||
// #BIN
|
// #BIN
|
||||||
//
|
//
|
||||||
// Binary-data access methods for short, char, int, long, float,
|
// Binary-data access methods for short, char, int, long, float,
|
||||||
|
@ -648,7 +648,7 @@ public class Basic$Type$
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exceptions in absolute bulk operations
|
// Exceptions in absolute bulk and slice operations
|
||||||
|
|
||||||
catchNullArgument(b, () -> b.get(7, null, 0, 42));
|
catchNullArgument(b, () -> b.get(7, null, 0, 42));
|
||||||
catchNullArgument(b, () -> b.put(7, ($type$[])null, 0, 42));
|
catchNullArgument(b, () -> b.put(7, ($type$[])null, 0, 42));
|
||||||
@ -668,6 +668,11 @@ public class Basic$Type$
|
|||||||
catchIndexOutOfBounds(b, () -> b.put(b.limit(), tmpa, 0, 1));
|
catchIndexOutOfBounds(b, () -> b.put(b.limit(), tmpa, 0, 1));
|
||||||
catchIndexOutOfBounds(b, () -> b.put(b.limit() - 41, tmpa, 0, 42));
|
catchIndexOutOfBounds(b, () -> b.put(b.limit() - 41, tmpa, 0, 42));
|
||||||
|
|
||||||
|
catchIndexOutOfBounds(b, () -> b.slice(-1, 7));
|
||||||
|
catchIndexOutOfBounds(b, () -> b.slice(b.limit() + 1, 7));
|
||||||
|
catchIndexOutOfBounds(b, () -> b.slice(0, -1));
|
||||||
|
catchIndexOutOfBounds(b, () -> b.slice(7, b.limit() - 7 + 1));
|
||||||
|
|
||||||
// Values
|
// Values
|
||||||
|
|
||||||
b.clear();
|
b.clear();
|
||||||
@ -832,6 +837,20 @@ public class Basic$Type$
|
|||||||
+ sb.arrayOffset() + " != " + sb2.arrayOffset(), sb, sb2);
|
+ sb.arrayOffset() + " != " + sb2.arrayOffset(), sb, sb2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int bPos = b.position();
|
||||||
|
int bLim = b.limit();
|
||||||
|
|
||||||
|
b.position(7);
|
||||||
|
b.limit(42);
|
||||||
|
$Type$Buffer rsb = b.slice();
|
||||||
|
b.position(0);
|
||||||
|
b.limit(b.capacity());
|
||||||
|
$Type$Buffer asb = b.slice(7, 35);
|
||||||
|
checkSlice(rsb, asb);
|
||||||
|
|
||||||
|
b.position(bPos);
|
||||||
|
b.limit(bLim);
|
||||||
|
|
||||||
#if[byte]
|
#if[byte]
|
||||||
|
|
||||||
// Views
|
// Views
|
||||||
|
@ -25,8 +25,8 @@
|
|||||||
* @summary Unit test for buffers
|
* @summary Unit test for buffers
|
||||||
* @bug 4413135 4414911 4416536 4416562 4418782 4471053 4472779 4490253 4523725
|
* @bug 4413135 4414911 4416536 4416562 4418782 4471053 4472779 4490253 4523725
|
||||||
* 4526177 4463011 4660660 4661219 4663521 4782970 4804304 4938424 5029431
|
* 4526177 4463011 4660660 4661219 4663521 4782970 4804304 4938424 5029431
|
||||||
* 6231529 6221101 6234263 6535542 6591971 6593946 6795561 7190219 7199551
|
* 5071718 6231529 6221101 6234263 6535542 6591971 6593946 6795561 7190219
|
||||||
* 8065556 8149469
|
* 7199551 8065556 8149469
|
||||||
* @modules java.base/java.nio:open
|
* @modules java.base/java.nio:open
|
||||||
* java.base/jdk.internal.misc
|
* java.base/jdk.internal.misc
|
||||||
* @author Mark Reinhold
|
* @author Mark Reinhold
|
||||||
|
@ -648,7 +648,7 @@ public class BasicByte
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exceptions in absolute bulk operations
|
// Exceptions in absolute bulk and slice operations
|
||||||
|
|
||||||
catchNullArgument(b, () -> b.get(7, null, 0, 42));
|
catchNullArgument(b, () -> b.get(7, null, 0, 42));
|
||||||
catchNullArgument(b, () -> b.put(7, (byte[])null, 0, 42));
|
catchNullArgument(b, () -> b.put(7, (byte[])null, 0, 42));
|
||||||
@ -668,6 +668,11 @@ public class BasicByte
|
|||||||
catchIndexOutOfBounds(b, () -> b.put(b.limit(), tmpa, 0, 1));
|
catchIndexOutOfBounds(b, () -> b.put(b.limit(), tmpa, 0, 1));
|
||||||
catchIndexOutOfBounds(b, () -> b.put(b.limit() - 41, tmpa, 0, 42));
|
catchIndexOutOfBounds(b, () -> b.put(b.limit() - 41, tmpa, 0, 42));
|
||||||
|
|
||||||
|
catchIndexOutOfBounds(b, () -> b.slice(-1, 7));
|
||||||
|
catchIndexOutOfBounds(b, () -> b.slice(b.limit() + 1, 7));
|
||||||
|
catchIndexOutOfBounds(b, () -> b.slice(0, -1));
|
||||||
|
catchIndexOutOfBounds(b, () -> b.slice(7, b.limit() - 7 + 1));
|
||||||
|
|
||||||
// Values
|
// Values
|
||||||
|
|
||||||
b.clear();
|
b.clear();
|
||||||
@ -832,6 +837,20 @@ public class BasicByte
|
|||||||
+ sb.arrayOffset() + " != " + sb2.arrayOffset(), sb, sb2);
|
+ sb.arrayOffset() + " != " + sb2.arrayOffset(), sb, sb2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int bPos = b.position();
|
||||||
|
int bLim = b.limit();
|
||||||
|
|
||||||
|
b.position(7);
|
||||||
|
b.limit(42);
|
||||||
|
ByteBuffer rsb = b.slice();
|
||||||
|
b.position(0);
|
||||||
|
b.limit(b.capacity());
|
||||||
|
ByteBuffer asb = b.slice(7, 35);
|
||||||
|
checkSlice(rsb, asb);
|
||||||
|
|
||||||
|
b.position(bPos);
|
||||||
|
b.limit(bLim);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Views
|
// Views
|
||||||
|
@ -648,7 +648,7 @@ public class BasicChar
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exceptions in absolute bulk operations
|
// Exceptions in absolute bulk and slice operations
|
||||||
|
|
||||||
catchNullArgument(b, () -> b.get(7, null, 0, 42));
|
catchNullArgument(b, () -> b.get(7, null, 0, 42));
|
||||||
catchNullArgument(b, () -> b.put(7, (char[])null, 0, 42));
|
catchNullArgument(b, () -> b.put(7, (char[])null, 0, 42));
|
||||||
@ -668,6 +668,11 @@ public class BasicChar
|
|||||||
catchIndexOutOfBounds(b, () -> b.put(b.limit(), tmpa, 0, 1));
|
catchIndexOutOfBounds(b, () -> b.put(b.limit(), tmpa, 0, 1));
|
||||||
catchIndexOutOfBounds(b, () -> b.put(b.limit() - 41, tmpa, 0, 42));
|
catchIndexOutOfBounds(b, () -> b.put(b.limit() - 41, tmpa, 0, 42));
|
||||||
|
|
||||||
|
catchIndexOutOfBounds(b, () -> b.slice(-1, 7));
|
||||||
|
catchIndexOutOfBounds(b, () -> b.slice(b.limit() + 1, 7));
|
||||||
|
catchIndexOutOfBounds(b, () -> b.slice(0, -1));
|
||||||
|
catchIndexOutOfBounds(b, () -> b.slice(7, b.limit() - 7 + 1));
|
||||||
|
|
||||||
// Values
|
// Values
|
||||||
|
|
||||||
b.clear();
|
b.clear();
|
||||||
@ -832,6 +837,20 @@ public class BasicChar
|
|||||||
+ sb.arrayOffset() + " != " + sb2.arrayOffset(), sb, sb2);
|
+ sb.arrayOffset() + " != " + sb2.arrayOffset(), sb, sb2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int bPos = b.position();
|
||||||
|
int bLim = b.limit();
|
||||||
|
|
||||||
|
b.position(7);
|
||||||
|
b.limit(42);
|
||||||
|
CharBuffer rsb = b.slice();
|
||||||
|
b.position(0);
|
||||||
|
b.limit(b.capacity());
|
||||||
|
CharBuffer asb = b.slice(7, 35);
|
||||||
|
checkSlice(rsb, asb);
|
||||||
|
|
||||||
|
b.position(bPos);
|
||||||
|
b.limit(bLim);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -648,7 +648,7 @@ public class BasicDouble
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exceptions in absolute bulk operations
|
// Exceptions in absolute bulk and slice operations
|
||||||
|
|
||||||
catchNullArgument(b, () -> b.get(7, null, 0, 42));
|
catchNullArgument(b, () -> b.get(7, null, 0, 42));
|
||||||
catchNullArgument(b, () -> b.put(7, (double[])null, 0, 42));
|
catchNullArgument(b, () -> b.put(7, (double[])null, 0, 42));
|
||||||
@ -668,6 +668,11 @@ public class BasicDouble
|
|||||||
catchIndexOutOfBounds(b, () -> b.put(b.limit(), tmpa, 0, 1));
|
catchIndexOutOfBounds(b, () -> b.put(b.limit(), tmpa, 0, 1));
|
||||||
catchIndexOutOfBounds(b, () -> b.put(b.limit() - 41, tmpa, 0, 42));
|
catchIndexOutOfBounds(b, () -> b.put(b.limit() - 41, tmpa, 0, 42));
|
||||||
|
|
||||||
|
catchIndexOutOfBounds(b, () -> b.slice(-1, 7));
|
||||||
|
catchIndexOutOfBounds(b, () -> b.slice(b.limit() + 1, 7));
|
||||||
|
catchIndexOutOfBounds(b, () -> b.slice(0, -1));
|
||||||
|
catchIndexOutOfBounds(b, () -> b.slice(7, b.limit() - 7 + 1));
|
||||||
|
|
||||||
// Values
|
// Values
|
||||||
|
|
||||||
b.clear();
|
b.clear();
|
||||||
@ -832,6 +837,20 @@ public class BasicDouble
|
|||||||
+ sb.arrayOffset() + " != " + sb2.arrayOffset(), sb, sb2);
|
+ sb.arrayOffset() + " != " + sb2.arrayOffset(), sb, sb2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int bPos = b.position();
|
||||||
|
int bLim = b.limit();
|
||||||
|
|
||||||
|
b.position(7);
|
||||||
|
b.limit(42);
|
||||||
|
DoubleBuffer rsb = b.slice();
|
||||||
|
b.position(0);
|
||||||
|
b.limit(b.capacity());
|
||||||
|
DoubleBuffer asb = b.slice(7, 35);
|
||||||
|
checkSlice(rsb, asb);
|
||||||
|
|
||||||
|
b.position(bPos);
|
||||||
|
b.limit(bLim);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -648,7 +648,7 @@ public class BasicFloat
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exceptions in absolute bulk operations
|
// Exceptions in absolute bulk and slice operations
|
||||||
|
|
||||||
catchNullArgument(b, () -> b.get(7, null, 0, 42));
|
catchNullArgument(b, () -> b.get(7, null, 0, 42));
|
||||||
catchNullArgument(b, () -> b.put(7, (float[])null, 0, 42));
|
catchNullArgument(b, () -> b.put(7, (float[])null, 0, 42));
|
||||||
@ -668,6 +668,11 @@ public class BasicFloat
|
|||||||
catchIndexOutOfBounds(b, () -> b.put(b.limit(), tmpa, 0, 1));
|
catchIndexOutOfBounds(b, () -> b.put(b.limit(), tmpa, 0, 1));
|
||||||
catchIndexOutOfBounds(b, () -> b.put(b.limit() - 41, tmpa, 0, 42));
|
catchIndexOutOfBounds(b, () -> b.put(b.limit() - 41, tmpa, 0, 42));
|
||||||
|
|
||||||
|
catchIndexOutOfBounds(b, () -> b.slice(-1, 7));
|
||||||
|
catchIndexOutOfBounds(b, () -> b.slice(b.limit() + 1, 7));
|
||||||
|
catchIndexOutOfBounds(b, () -> b.slice(0, -1));
|
||||||
|
catchIndexOutOfBounds(b, () -> b.slice(7, b.limit() - 7 + 1));
|
||||||
|
|
||||||
// Values
|
// Values
|
||||||
|
|
||||||
b.clear();
|
b.clear();
|
||||||
@ -832,6 +837,20 @@ public class BasicFloat
|
|||||||
+ sb.arrayOffset() + " != " + sb2.arrayOffset(), sb, sb2);
|
+ sb.arrayOffset() + " != " + sb2.arrayOffset(), sb, sb2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int bPos = b.position();
|
||||||
|
int bLim = b.limit();
|
||||||
|
|
||||||
|
b.position(7);
|
||||||
|
b.limit(42);
|
||||||
|
FloatBuffer rsb = b.slice();
|
||||||
|
b.position(0);
|
||||||
|
b.limit(b.capacity());
|
||||||
|
FloatBuffer asb = b.slice(7, 35);
|
||||||
|
checkSlice(rsb, asb);
|
||||||
|
|
||||||
|
b.position(bPos);
|
||||||
|
b.limit(bLim);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -648,7 +648,7 @@ public class BasicInt
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exceptions in absolute bulk operations
|
// Exceptions in absolute bulk and slice operations
|
||||||
|
|
||||||
catchNullArgument(b, () -> b.get(7, null, 0, 42));
|
catchNullArgument(b, () -> b.get(7, null, 0, 42));
|
||||||
catchNullArgument(b, () -> b.put(7, (int[])null, 0, 42));
|
catchNullArgument(b, () -> b.put(7, (int[])null, 0, 42));
|
||||||
@ -668,6 +668,11 @@ public class BasicInt
|
|||||||
catchIndexOutOfBounds(b, () -> b.put(b.limit(), tmpa, 0, 1));
|
catchIndexOutOfBounds(b, () -> b.put(b.limit(), tmpa, 0, 1));
|
||||||
catchIndexOutOfBounds(b, () -> b.put(b.limit() - 41, tmpa, 0, 42));
|
catchIndexOutOfBounds(b, () -> b.put(b.limit() - 41, tmpa, 0, 42));
|
||||||
|
|
||||||
|
catchIndexOutOfBounds(b, () -> b.slice(-1, 7));
|
||||||
|
catchIndexOutOfBounds(b, () -> b.slice(b.limit() + 1, 7));
|
||||||
|
catchIndexOutOfBounds(b, () -> b.slice(0, -1));
|
||||||
|
catchIndexOutOfBounds(b, () -> b.slice(7, b.limit() - 7 + 1));
|
||||||
|
|
||||||
// Values
|
// Values
|
||||||
|
|
||||||
b.clear();
|
b.clear();
|
||||||
@ -832,6 +837,20 @@ public class BasicInt
|
|||||||
+ sb.arrayOffset() + " != " + sb2.arrayOffset(), sb, sb2);
|
+ sb.arrayOffset() + " != " + sb2.arrayOffset(), sb, sb2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int bPos = b.position();
|
||||||
|
int bLim = b.limit();
|
||||||
|
|
||||||
|
b.position(7);
|
||||||
|
b.limit(42);
|
||||||
|
IntBuffer rsb = b.slice();
|
||||||
|
b.position(0);
|
||||||
|
b.limit(b.capacity());
|
||||||
|
IntBuffer asb = b.slice(7, 35);
|
||||||
|
checkSlice(rsb, asb);
|
||||||
|
|
||||||
|
b.position(bPos);
|
||||||
|
b.limit(bLim);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -648,7 +648,7 @@ public class BasicLong
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exceptions in absolute bulk operations
|
// Exceptions in absolute bulk and slice operations
|
||||||
|
|
||||||
catchNullArgument(b, () -> b.get(7, null, 0, 42));
|
catchNullArgument(b, () -> b.get(7, null, 0, 42));
|
||||||
catchNullArgument(b, () -> b.put(7, (long[])null, 0, 42));
|
catchNullArgument(b, () -> b.put(7, (long[])null, 0, 42));
|
||||||
@ -668,6 +668,11 @@ public class BasicLong
|
|||||||
catchIndexOutOfBounds(b, () -> b.put(b.limit(), tmpa, 0, 1));
|
catchIndexOutOfBounds(b, () -> b.put(b.limit(), tmpa, 0, 1));
|
||||||
catchIndexOutOfBounds(b, () -> b.put(b.limit() - 41, tmpa, 0, 42));
|
catchIndexOutOfBounds(b, () -> b.put(b.limit() - 41, tmpa, 0, 42));
|
||||||
|
|
||||||
|
catchIndexOutOfBounds(b, () -> b.slice(-1, 7));
|
||||||
|
catchIndexOutOfBounds(b, () -> b.slice(b.limit() + 1, 7));
|
||||||
|
catchIndexOutOfBounds(b, () -> b.slice(0, -1));
|
||||||
|
catchIndexOutOfBounds(b, () -> b.slice(7, b.limit() - 7 + 1));
|
||||||
|
|
||||||
// Values
|
// Values
|
||||||
|
|
||||||
b.clear();
|
b.clear();
|
||||||
@ -832,6 +837,20 @@ public class BasicLong
|
|||||||
+ sb.arrayOffset() + " != " + sb2.arrayOffset(), sb, sb2);
|
+ sb.arrayOffset() + " != " + sb2.arrayOffset(), sb, sb2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int bPos = b.position();
|
||||||
|
int bLim = b.limit();
|
||||||
|
|
||||||
|
b.position(7);
|
||||||
|
b.limit(42);
|
||||||
|
LongBuffer rsb = b.slice();
|
||||||
|
b.position(0);
|
||||||
|
b.limit(b.capacity());
|
||||||
|
LongBuffer asb = b.slice(7, 35);
|
||||||
|
checkSlice(rsb, asb);
|
||||||
|
|
||||||
|
b.position(bPos);
|
||||||
|
b.limit(bLim);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -648,7 +648,7 @@ public class BasicShort
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exceptions in absolute bulk operations
|
// Exceptions in absolute bulk and slice operations
|
||||||
|
|
||||||
catchNullArgument(b, () -> b.get(7, null, 0, 42));
|
catchNullArgument(b, () -> b.get(7, null, 0, 42));
|
||||||
catchNullArgument(b, () -> b.put(7, (short[])null, 0, 42));
|
catchNullArgument(b, () -> b.put(7, (short[])null, 0, 42));
|
||||||
@ -668,6 +668,11 @@ public class BasicShort
|
|||||||
catchIndexOutOfBounds(b, () -> b.put(b.limit(), tmpa, 0, 1));
|
catchIndexOutOfBounds(b, () -> b.put(b.limit(), tmpa, 0, 1));
|
||||||
catchIndexOutOfBounds(b, () -> b.put(b.limit() - 41, tmpa, 0, 42));
|
catchIndexOutOfBounds(b, () -> b.put(b.limit() - 41, tmpa, 0, 42));
|
||||||
|
|
||||||
|
catchIndexOutOfBounds(b, () -> b.slice(-1, 7));
|
||||||
|
catchIndexOutOfBounds(b, () -> b.slice(b.limit() + 1, 7));
|
||||||
|
catchIndexOutOfBounds(b, () -> b.slice(0, -1));
|
||||||
|
catchIndexOutOfBounds(b, () -> b.slice(7, b.limit() - 7 + 1));
|
||||||
|
|
||||||
// Values
|
// Values
|
||||||
|
|
||||||
b.clear();
|
b.clear();
|
||||||
@ -832,6 +837,20 @@ public class BasicShort
|
|||||||
+ sb.arrayOffset() + " != " + sb2.arrayOffset(), sb, sb2);
|
+ sb.arrayOffset() + " != " + sb2.arrayOffset(), sb, sb2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int bPos = b.position();
|
||||||
|
int bLim = b.limit();
|
||||||
|
|
||||||
|
b.position(7);
|
||||||
|
b.limit(42);
|
||||||
|
ShortBuffer rsb = b.slice();
|
||||||
|
b.position(0);
|
||||||
|
b.limit(b.capacity());
|
||||||
|
ShortBuffer asb = b.slice(7, 35);
|
||||||
|
checkSlice(rsb, asb);
|
||||||
|
|
||||||
|
b.position(bPos);
|
||||||
|
b.limit(bLim);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -64,6 +64,8 @@ public class ByteBufferViews {
|
|||||||
size -> ByteBuffer.allocate(size).position(8).slice()),
|
size -> ByteBuffer.allocate(size).position(8).slice()),
|
||||||
Map.entry("ByteBuffer.allocate(size).position(8).slice().duplicate()",
|
Map.entry("ByteBuffer.allocate(size).position(8).slice().duplicate()",
|
||||||
size -> ByteBuffer.allocate(size).position(8).slice().duplicate()),
|
size -> ByteBuffer.allocate(size).position(8).slice().duplicate()),
|
||||||
|
Map.entry("ByteBuffer.allocate(size).slice(8,size-8)",
|
||||||
|
size -> ByteBuffer.allocate(size).slice(8,size-8)),
|
||||||
// Unaligned
|
// Unaligned
|
||||||
Map.entry("ByteBuffer.allocate(size).position(1)",
|
Map.entry("ByteBuffer.allocate(size).position(1)",
|
||||||
size -> ByteBuffer.allocate(size).position(1)),
|
size -> ByteBuffer.allocate(size).position(1)),
|
||||||
@ -71,6 +73,8 @@ public class ByteBufferViews {
|
|||||||
size -> ByteBuffer.allocate(size).position(1).slice()),
|
size -> ByteBuffer.allocate(size).position(1).slice()),
|
||||||
Map.entry("ByteBuffer.allocate(size).position(1).slice().duplicate()",
|
Map.entry("ByteBuffer.allocate(size).position(1).slice().duplicate()",
|
||||||
size -> ByteBuffer.allocate(size).position(1).slice().duplicate()),
|
size -> ByteBuffer.allocate(size).position(1).slice().duplicate()),
|
||||||
|
Map.entry("ByteBuffer.allocate(size).slice(1,size-1)",
|
||||||
|
size -> ByteBuffer.allocate(size).slice(1,size-1)),
|
||||||
|
|
||||||
// Off-heap
|
// Off-heap
|
||||||
Map.entry("ByteBuffer.allocateDirect(size)",
|
Map.entry("ByteBuffer.allocateDirect(size)",
|
||||||
@ -82,13 +86,17 @@ public class ByteBufferViews {
|
|||||||
size -> ByteBuffer.allocateDirect(size).position(8).slice()),
|
size -> ByteBuffer.allocateDirect(size).position(8).slice()),
|
||||||
Map.entry("ByteBuffer.allocateDirect(size).position(8).slice().duplicate()",
|
Map.entry("ByteBuffer.allocateDirect(size).position(8).slice().duplicate()",
|
||||||
size -> ByteBuffer.allocateDirect(size).position(8).slice().duplicate()),
|
size -> ByteBuffer.allocateDirect(size).position(8).slice().duplicate()),
|
||||||
|
Map.entry("ByteBuffer.allocateDirect(size).slice(8,size-8)",
|
||||||
|
size -> ByteBuffer.allocateDirect(size).slice(8,size-8)),
|
||||||
// Unaligned
|
// Unaligned
|
||||||
Map.entry("ByteBuffer.allocateDirect(size).position(1)",
|
Map.entry("ByteBuffer.allocateDirect(size).position(1)",
|
||||||
size -> ByteBuffer.allocateDirect(size).position(1)),
|
size -> ByteBuffer.allocateDirect(size).position(1)),
|
||||||
Map.entry("ByteBuffer.allocateDirect(size).position(1).slice()",
|
Map.entry("ByteBuffer.allocateDirect(size).position(1).slice()",
|
||||||
size -> ByteBuffer.allocateDirect(size).position(1).slice()),
|
size -> ByteBuffer.allocateDirect(size).position(1).slice()),
|
||||||
Map.entry("ByteBuffer.allocateDirect(size).position(1).slice().duplicate()",
|
Map.entry("ByteBuffer.allocateDirect(size).position(1).slice().duplicate()",
|
||||||
size -> ByteBuffer.allocateDirect(size).position(1).slice().duplicate())
|
size -> ByteBuffer.allocateDirect(size).position(1).slice().duplicate()),
|
||||||
|
Map.entry("ByteBuffer.allocateDirect(size).slice(1,size-1)",
|
||||||
|
size -> ByteBuffer.allocateDirect(size).slice(1,size-1))
|
||||||
);
|
);
|
||||||
|
|
||||||
// List of buffer byte order functions
|
// List of buffer byte order functions
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -22,11 +22,14 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* @test
|
/* @test
|
||||||
* @bug 4997655 7000913
|
* @bug 4997655 5071718 7000913
|
||||||
* @summary (bf) CharBuffer.slice() on wrapped CharSequence results in wrong position
|
* @summary (bf) CharBuffer.slice() on wrapped CharSequence results in wrong position
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.nio.*;
|
import java.nio.CharBuffer;
|
||||||
|
import java.nio.InvalidMarkException;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class StringCharBufferSliceTest {
|
public class StringCharBufferSliceTest {
|
||||||
public static void main( String[] args) throws Exception {
|
public static void main( String[] args) throws Exception {
|
||||||
@ -40,85 +43,114 @@ public class StringCharBufferSliceTest {
|
|||||||
|
|
||||||
CharBuffer buff = CharBuffer.wrap(in);
|
CharBuffer buff = CharBuffer.wrap(in);
|
||||||
test(buff, buff.slice());
|
test(buff, buff.slice());
|
||||||
|
test(buff, buff.slice(0, buff.remaining()));
|
||||||
|
|
||||||
System.out.println(
|
System.out.println(
|
||||||
">>> StringCharBufferSliceTest-main: testing with new position.");
|
">>> StringCharBufferSliceTest-main: testing with new position.");
|
||||||
|
|
||||||
buff.position(2);
|
buff.position(2);
|
||||||
test(buff, buff.slice());
|
test(buff, buff.slice());
|
||||||
|
test(buff, buff.slice(2, buff.remaining()));
|
||||||
|
|
||||||
System.out.println(
|
System.out.println(
|
||||||
">>> StringCharBufferSliceTest-main: testing with non zero initial position.");
|
">>> StringCharBufferSliceTest-main: testing with non zero initial position.");
|
||||||
|
|
||||||
buff = CharBuffer.wrap(in, 3, in.length());
|
buff = CharBuffer.wrap(in, 3, in.length());
|
||||||
test(buff, buff.slice());
|
test(buff, buff.slice());
|
||||||
|
test(buff, buff.slice(0, buff.remaining()));
|
||||||
|
|
||||||
System.out.println(
|
System.out.println(
|
||||||
">>> StringCharBufferSliceTest-main: testing slice result with get()");
|
">>> StringCharBufferSliceTest-main: testing slice result with get()");
|
||||||
buff.position(4);
|
buff.position(4);
|
||||||
buff.limit(7);
|
buff.limit(7);
|
||||||
CharBuffer slice = buff.slice();
|
BiConsumer<CharBuffer,CharBuffer> bitest = (b, s) -> {
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
if (slice.get() != buff.get()) {
|
if (s.get() != b.get()) {
|
||||||
throw new RuntimeException("Wrong characters in slice result.");
|
throw new RuntimeException
|
||||||
|
("Wrong characters in slice result.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
bitest.accept(buff, buff.slice());
|
||||||
|
buff.position(4);
|
||||||
|
bitest.accept(buff, buff.slice(4, 3));
|
||||||
|
|
||||||
System.out.println(
|
System.out.println(
|
||||||
">>> StringCharBufferSliceTest-main: testing slice result with get(int)");
|
">>> StringCharBufferSliceTest-main: testing slice result with get(int)");
|
||||||
buff.position(4);
|
buff.position(4);
|
||||||
buff.limit(7);
|
buff.limit(7);
|
||||||
slice = buff.slice();
|
bitest = (b, s) -> {
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
if (slice.get(i) != buff.get(4 + i)) {
|
if (s.get(i) != b.get(4 + i)) {
|
||||||
throw new RuntimeException("Wrong characters in slice result.");
|
throw new RuntimeException
|
||||||
|
("Wrong characters in slice result.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
bitest.accept(buff, buff.slice());
|
||||||
|
buff.position(4);
|
||||||
|
bitest.accept(buff, buff.slice(4, 3));
|
||||||
|
|
||||||
System.out.println(
|
System.out.println(
|
||||||
">>> StringCharBufferSliceTest-main: testing slice with result of slice");
|
">>> StringCharBufferSliceTest-main: testing slice with result of slice");
|
||||||
buff.position(0);
|
buff.position(0);
|
||||||
buff.limit(buff.capacity());
|
buff.limit(buff.capacity());
|
||||||
slice = buff.slice();
|
Consumer<CharBuffer> test = (s) -> {
|
||||||
for (int i=0; i<4; i++) {
|
for (int i=0; i<4; i++) {
|
||||||
slice.position(i);
|
s.position(i);
|
||||||
CharBuffer nextSlice = slice.slice();
|
CharBuffer nextSlice = s.slice();
|
||||||
if (nextSlice.position() != 0)
|
if (nextSlice.position() != 0)
|
||||||
throw new RuntimeException("New buffer's position should be zero");
|
throw new RuntimeException
|
||||||
if (!nextSlice.equals(slice))
|
("New buffer's position should be zero");
|
||||||
|
if (!nextSlice.equals(s))
|
||||||
throw new RuntimeException("New buffer should be equal");
|
throw new RuntimeException("New buffer should be equal");
|
||||||
slice = nextSlice;
|
s = nextSlice;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
test.accept(buff.slice());
|
||||||
|
test.accept(buff.slice(0, buff.capacity()));
|
||||||
|
|
||||||
System.out.println(
|
System.out.println(
|
||||||
">>> StringCharBufferSliceTest-main: testing toString.");
|
">>> StringCharBufferSliceTest-main: testing toString.");
|
||||||
buff.position(4);
|
buff.position(4);
|
||||||
buff.limit(7);
|
buff.limit(7);
|
||||||
slice = buff.slice();
|
test = (s) -> {
|
||||||
if (!slice.toString().equals("tes")) {
|
if (!s.toString().equals("tes")) {
|
||||||
throw new RuntimeException("bad toString() after slice(): " + slice.toString());
|
throw new RuntimeException
|
||||||
|
("bad toString() after slice(): " + s.toString());
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
test.accept(buff.slice());
|
||||||
|
test.accept(buff.slice(4, 3));
|
||||||
|
|
||||||
System.out.println(
|
System.out.println(
|
||||||
">>> StringCharBufferSliceTest-main: testing subSequence.");
|
">>> StringCharBufferSliceTest-main: testing subSequence.");
|
||||||
buff.position(4);
|
buff.position(4);
|
||||||
buff.limit(8);
|
buff.limit(8);
|
||||||
slice = buff.slice();
|
test = (s) -> {
|
||||||
CharSequence subSeq = slice.subSequence(1, 3);
|
CharSequence subSeq = s.subSequence(1, 3);
|
||||||
if (subSeq.charAt(0) != 'e' || subSeq.charAt(1) != 's') {
|
if (subSeq.charAt(0) != 'e' || subSeq.charAt(1) != 's') {
|
||||||
throw new RuntimeException("bad subSequence() after slice(): '" + subSeq + "'");
|
throw new RuntimeException
|
||||||
|
("bad subSequence() after slice(): '" + subSeq + "'");
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
test.accept(buff.slice());
|
||||||
|
test.accept(buff.slice(4, 4));
|
||||||
|
|
||||||
System.out.println(
|
System.out.println(
|
||||||
">>> StringCharBufferSliceTest-main: testing duplicate.");
|
">>> StringCharBufferSliceTest-main: testing duplicate.");
|
||||||
buff.position(4);
|
buff.position(4);
|
||||||
buff.limit(8);
|
buff.limit(8);
|
||||||
slice = buff.slice();
|
test = (s) -> {
|
||||||
CharBuffer dupe = slice.duplicate();
|
CharBuffer dupe = s.duplicate();
|
||||||
if (dupe.charAt(0) != 't' || dupe.charAt(1) != 'e'
|
if (dupe.charAt(0) != 't' || dupe.charAt(1) != 'e'
|
||||||
|| dupe.charAt(2) != 's' || dupe.charAt(3) != 't') {
|
|| dupe.charAt(2) != 's' || dupe.charAt(3) != 't') {
|
||||||
throw new RuntimeException("bad duplicate() after slice(): '" + dupe + "'");
|
throw new RuntimeException
|
||||||
|
("bad duplicate() after slice(): '" + dupe + "'");
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
test.accept(buff.slice());
|
||||||
|
test.accept(buff.slice(4, 4));
|
||||||
|
|
||||||
System.out.println(">>> StringCharBufferSliceTest-main: done!");
|
System.out.println(">>> StringCharBufferSliceTest-main: done!");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user