Cross Reference: BasicByte.java
xref
: /
openjdk7
/
jdk
/
test
/
java
/
nio
/
Buffer
/
BasicByte.java
Home
History
Annotate
Line#
Navigate
Download
Search
only in
./
0
N/A
/*
2362
N/A
* Copyright (c) 2000, 2008, Oracle
and
/
or
its affiliates. All rights reserved.
0
N/A
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0
N/A
*
0
N/A
* This code is free software; you can redistribute it
and
/
or
modify it
0
N/A
* under the terms of the GNU General Public License version 2 only, as
0
N/A
* published by the Free Software Foundation.
0
N/A
*
0
N/A
* This code is distributed in the hope that it will be useful, but WITHOUT
0
N/A
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0
N/A
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0
N/A
* version 2 for more details (a copy is included in the LICENSE file that
0
N/A
* accompanied this code).
0
N/A
*
0
N/A
* You should have received a copy of the GNU General Public License version
0
N/A
* 2 along with this work; if not, write to the Free Software Foundation,
0
N/A
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0
N/A
*
2362
N/A
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362
N/A
* or visit www.oracle.com if you need additional information or have any
2362
N/A
* questions.
0
N/A
*/
0
N/A
0
N/A
/* Type-specific source code for unit test
0
N/A
*
0
N/A
* Regenerate the BasicX classes via genBasic.sh whenever this file changes.
0
N/A
* We check in the generated source files so that the test tree can be used
0
N/A
* independently of the rest of the source tree.
0
N/A
*/
0
N/A
0
N/A
// -- This file was mechanically generated: Do not edit! -- //
0
N/A
0
N/A
import
java
.
nio
.*;
721
N/A
import
java
.
lang
.
reflect
.
Method
;
0
N/A
0
N/A
0
N/A
public
class
BasicByte
0
N/A
extends
Basic
0
N/A
{
0
N/A
2005
N/A
private
static
final
byte
[]
VALUES
= {
2005
N/A
Byte
.
MIN_VALUE
,
2005
N/A
(
byte
) -
1
,
2005
N/A
(
byte
)
0
,
2005
N/A
(
byte
)
1
,
2005
N/A
Byte
.
MAX_VALUE
,
2005
N/A
2005
N/A
2005
N/A
2005
N/A
2005
N/A
2005
N/A
2005
N/A
2005
N/A
2005
N/A
2005
N/A
2005
N/A
2005
N/A
2005
N/A
};
2005
N/A
0
N/A
private
static
void
relGet
(
ByteBuffer
b) {
0
N/A
int
n = b.
capacity
();
0
N/A
byte
v;
0
N/A
for
(
int
i =
0
; i < n; i++)
0
N/A
ck
(b, (
long
)b.
get
(), (
long
)((
byte
)
ic
(i)));
0
N/A
b.
rewind
();
0
N/A
}
0
N/A
0
N/A
private
static
void
relGet
(
ByteBuffer
b,
int
start
) {
0
N/A
int
n = b.
remaining
();
0
N/A
byte
v;
0
N/A
for
(
int
i =
start
; i < n; i++)
0
N/A
ck
(b, (
long
)b.
get
(), (
long
)((
byte
)
ic
(i)));
0
N/A
b.
rewind
();
0
N/A
}
0
N/A
0
N/A
private
static
void
absGet
(
ByteBuffer
b) {
0
N/A
int
n = b.
capacity
();
0
N/A
byte
v;
0
N/A
for
(
int
i =
0
; i < n; i++)
0
N/A
ck
(b, (
long
)b.
get
(), (
long
)((
byte
)
ic
(i)));
0
N/A
b.
rewind
();
0
N/A
}
0
N/A
0
N/A
private
static
void
bulkGet
(
ByteBuffer
b) {
0
N/A
int
n = b.
capacity
();
0
N/A
byte
[] a =
new
byte
[n +
7
];
0
N/A
b.
get
(a,
7
, n);
0
N/A
for
(
int
i =
0
; i < n; i++)
0
N/A
ck
(b, (
long
)a[i +
7
], (
long
)((
byte
)
ic
(i)));
0
N/A
}
0
N/A
0
N/A
private
static
void
relPut
(
ByteBuffer
b) {
0
N/A
int
n = b.
capacity
();
0
N/A
b.
clear
();
0
N/A
for
(
int
i =
0
; i < n; i++)
0
N/A
b.
put
((
byte
)
ic
(i));
0
N/A
b.
flip
();
0
N/A
}
0
N/A
0
N/A
private
static
void
absPut
(
ByteBuffer
b) {
0
N/A
int
n = b.
capacity
();
0
N/A
b.
clear
();
0
N/A
for
(
int
i =
0
; i < n; i++)
0
N/A
b.
put
(i, (
byte
)
ic
(i));
0
N/A
b.
limit
(n);
0
N/A
b.
position
(
0
);
0
N/A
}
0
N/A
0
N/A
private
static
void
bulkPutArray
(
ByteBuffer
b) {
0
N/A
int
n = b.
capacity
();
0
N/A
b.
clear
();
0
N/A
byte
[] a =
new
byte
[n +
7
];
0
N/A
for
(
int
i =
0
; i < n; i++)
0
N/A
a[i +
7
] = (
byte
)
ic
(i);
0
N/A
b.
put
(a,
7
, n);
0
N/A
b.
flip
();
0
N/A
}
0
N/A
0
N/A
private
static
void
bulkPutBuffer
(
ByteBuffer
b) {
0
N/A
int
n = b.
capacity
();
0
N/A
b.
clear
();
0
N/A
ByteBuffer
c =
ByteBuffer
.
allocate
(n +
7
);
0
N/A
c.
position
(
7
);
0
N/A
for
(
int
i =
0
; i < n; i++)
0
N/A
c.
put
((
byte
)
ic
(i));
0
N/A
c.
flip
();
0
N/A
c.
position
(
7
);
0
N/A
b.
put
(c);
0
N/A
b.
flip
();
0
N/A
}
0
N/A
0
N/A
//6231529
0
N/A
private
static
void
callReset
(
ByteBuffer
b) {
0
N/A
b.
position
(
0
);
0
N/A
b.
mark
();
0
N/A
0
N/A
b.
duplicate
().
reset
();
0
N/A
b.
asReadOnlyBuffer
().
reset
();
0
N/A
}
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
private
static
void
checkSlice
(
ByteBuffer
b,
ByteBuffer
slice
) {
0
N/A
ck
(
slice
,
0
,
slice
.
position
());
0
N/A
ck
(
slice
, b.
remaining
(),
slice
.
limit
());
0
N/A
ck
(
slice
, b.
remaining
(),
slice
.
capacity
());
0
N/A
if
(b.
isDirect
() !=
slice
.
isDirect
())
0
N/A
fail
(
"Lost direction"
,
slice
);
0
N/A
if
(b.
isReadOnly
() !=
slice
.
isReadOnly
())
0
N/A
fail
(
"Lost read-only"
,
slice
);
0
N/A
}
0
N/A
0
N/A
0
N/A
0
N/A
private
static
void
checkBytes
(
ByteBuffer
b,
byte
[]
bs
) {
0
N/A
int
n =
bs
.
length
;
0
N/A
int
p = b.
position
();
0
N/A
byte
v;
0
N/A
if
(b.
order
() ==
ByteOrder
.
BIG_ENDIAN
) {
0
N/A
for
(
int
i =
0
; i < n; i++)
0
N/A
ck
(b, b.
get
(),
bs
[i]);
0
N/A
}
else
{
0
N/A
for
(
int
i = n -
1
; i >=
0
; i--)
0
N/A
ck
(b, b.
get
(),
bs
[i]);
0
N/A
}
0
N/A
b.
position
(p);
0
N/A
}
0
N/A
721
N/A
private
static
void
compact
(
Buffer
b) {
721
N/A
try
{
721
N/A
Class
<?>
cl
= b.
getClass
();
721
N/A
Method
m =
cl
.
getDeclaredMethod
(
"compact"
);
721
N/A
m.
setAccessible
(
true
);
721
N/A
m.
invoke
(b);
721
N/A
}
catch
(
Exception
e) {
721
N/A
fail
(e.
getMessage
(), b);
721
N/A
}
721
N/A
}
721
N/A
721
N/A
private
static
void
checkInvalidMarkException
(
final
Buffer
b) {
721
N/A
tryCatch
(b,
InvalidMarkException
.
class
,
new
Runnable
() {
721
N/A
public
void
run
() {
721
N/A
b.
mark
();
721
N/A
compact
(b);
721
N/A
b.
reset
();
721
N/A
}});
721
N/A
}
721
N/A
0
N/A
private
static
void
testViews
(
int
level
,
ByteBuffer
b,
boolean
direct
) {
0
N/A
0
N/A
ShortBuffer
sb
= b.
asShortBuffer
();
0
N/A
BasicShort
.
test
(
level
,
sb
,
direct
);
0
N/A
checkBytes
(b,
new
byte
[] {
0
, (
byte
)
ic
(
0
) });
721
N/A
checkInvalidMarkException
(
sb
);
0
N/A
0
N/A
CharBuffer
cb
= b.
asCharBuffer
();
0
N/A
BasicChar
.
test
(
level
,
cb
,
direct
);
0
N/A
checkBytes
(b,
new
byte
[] {
0
, (
byte
)
ic
(
0
) });
721
N/A
checkInvalidMarkException
(
cb
);
0
N/A
0
N/A
IntBuffer
ib
= b.
asIntBuffer
();
0
N/A
BasicInt
.
test
(
level
,
ib
,
direct
);
0
N/A
checkBytes
(b,
new
byte
[] {
0
,
0
,
0
, (
byte
)
ic
(
0
) });
721
N/A
checkInvalidMarkException
(
ib
);
0
N/A
0
N/A
LongBuffer
lb
= b.
asLongBuffer
();
0
N/A
BasicLong
.
test
(
level
,
lb
,
direct
);
0
N/A
checkBytes
(b,
new
byte
[] {
0
,
0
,
0
,
0
,
0
,
0
,
0
, (
byte
)
ic
(
0
) });
721
N/A
checkInvalidMarkException
(
lb
);
0
N/A
0
N/A
FloatBuffer
fb
= b.
asFloatBuffer
();
0
N/A
BasicFloat
.
test
(
level
,
fb
,
direct
);
0
N/A
checkBytes
(b,
new
byte
[] {
0x42
, (
byte
)
0xc2
,
0
,
0
});
721
N/A
checkInvalidMarkException
(
fb
);
0
N/A
0
N/A
DoubleBuffer
db
= b.
asDoubleBuffer
();
0
N/A
BasicDouble
.
test
(
level
,
db
,
direct
);
0
N/A
checkBytes
(b,
new
byte
[] {
0x40
,
0x58
,
0x40
,
0
,
0
,
0
,
0
,
0
});
721
N/A
checkInvalidMarkException
(
db
);
0
N/A
}
0
N/A
0
N/A
private
static
void
testHet
(
int
level
,
ByteBuffer
b) {
0
N/A
0
N/A
int
p = b.
position
();
0
N/A
b.
limit
(b.
capacity
());
0
N/A
show
(
level
, b);
0
N/A
out
.
print
(
" put:"
);
0
N/A
0
N/A
b.
putChar
((
char
)
1
);
0
N/A
b.
putChar
((
char
)
Character
.
MAX_VALUE
);
0
N/A
out
.
print
(
" char"
);
0
N/A
0
N/A
b.
putShort
((
short
)
1
);
0
N/A
b.
putShort
((
short
)
Short
.
MAX_VALUE
);
0
N/A
out
.
print
(
" short"
);
0
N/A
0
N/A
b.
putInt
(
1
);
0
N/A
b.
putInt
(
Integer
.
MAX_VALUE
);
0
N/A
out
.
print
(
" int"
);
0
N/A
0
N/A
b.
putLong
((
long
)
1
);
0
N/A
b.
putLong
((
long
)
Long
.
MAX_VALUE
);
0
N/A
out
.
print
(
" long"
);
0
N/A
0
N/A
b.
putFloat
((
float
)
1
);
0
N/A
b.
putFloat
((
float
)
Float
.
MIN_VALUE
);
0
N/A
b.
putFloat
((
float
)
Float
.
MAX_VALUE
);
0
N/A
out
.
print
(
" float"
);
0
N/A
0
N/A
b.
putDouble
((
double
)
1
);
0
N/A
b.
putDouble
((
double
)
Double
.
MIN_VALUE
);
0
N/A
b.
putDouble
((
double
)
Double
.
MAX_VALUE
);
0
N/A
out
.
print
(
" double"
);
0
N/A
0
N/A
out
.
println
();
0
N/A
b.
limit
(b.
position
());
0
N/A
b.
position
(p);
0
N/A
show
(
level
, b);
0
N/A
out
.
print
(
" get:"
);
0
N/A
0
N/A
ck
(b, b.
getChar
(),
1
);
0
N/A
ck
(b, b.
getChar
(),
Character
.
MAX_VALUE
);
0
N/A
out
.
print
(
" char"
);
0
N/A
0
N/A
ck
(b, b.
getShort
(),
1
);
0
N/A
ck
(b, b.
getShort
(),
Short
.
MAX_VALUE
);
0
N/A
out
.
print
(
" short"
);
0
N/A
0
N/A
ck
(b, b.
getInt
(),
1
);
0
N/A
ck
(b, b.
getInt
(),
Integer
.
MAX_VALUE
);
0
N/A
out
.
print
(
" int"
);
0
N/A
0
N/A
ck
(b, b.
getLong
(),
1
);
0
N/A
ck
(b, b.
getLong
(),
Long
.
MAX_VALUE
);
0
N/A
out
.
print
(
" long"
);
0
N/A
0
N/A
ck
(b, (
long
)b.
getFloat
(),
1
);
0
N/A
ck
(b, (
long
)b.
getFloat
(), (
long
)
Float
.
MIN_VALUE
);
0
N/A
ck
(b, (
long
)b.
getFloat
(), (
long
)
Float
.
MAX_VALUE
);
0
N/A
out
.
print
(
" float"
);
0
N/A
0
N/A
ck
(b, (
long
)b.
getDouble
(),
1
);
0
N/A
ck
(b, (
long
)b.
getDouble
(), (
long
)
Double
.
MIN_VALUE
);
0
N/A
ck
(b, (
long
)b.
getDouble
(), (
long
)
Double
.
MAX_VALUE
);
0
N/A
out
.
print
(
" double"
);
0
N/A
0
N/A
out
.
println
();
0
N/A
0
N/A
}
0
N/A
0
N/A
0
N/A
2005
N/A
private
static
void
fail
(
String
problem
,
2005
N/A
ByteBuffer
xb
,
ByteBuffer
yb
,
2005
N/A
byte
x,
byte
y) {
2005
N/A
fail
(
problem
+
String
.
format
(
": x=%s y=%s"
, x, y),
xb
,
yb
);
2005
N/A
}
2005
N/A
0
N/A
private
static
void
tryCatch
(
Buffer
b,
Class
ex
,
Runnable
thunk
) {
0
N/A
boolean
caught
=
false
;
0
N/A
try
{
0
N/A
thunk
.
run
();
0
N/A
}
catch
(
Throwable
x) {
721
N/A
if
(
ex
.
isAssignableFrom
(x.
getClass
())) {
0
N/A
caught
=
true
;
721
N/A
}
else
{
721
N/A
fail
(x.
getMessage
() +
" not expected"
);
721
N/A
}
0
N/A
}
0
N/A
if
(!
caught
)
0
N/A
fail
(
ex
.
getName
() +
" not thrown"
, b);
0
N/A
}
0
N/A
0
N/A
private
static
void
tryCatch
(
byte
[] t,
Class
ex
,
Runnable
thunk
) {
0
N/A
tryCatch
(
ByteBuffer
.
wrap
(t),
ex
,
thunk
);
0
N/A
}
0
N/A
0
N/A
public
static
void
test
(
int
level
,
final
ByteBuffer
b,
boolean
direct
) {
0
N/A
0
N/A
show
(
level
, b);
0
N/A
0
N/A
if
(
direct
!= b.
isDirect
())
0
N/A
fail
(
"Wrong direction"
, b);
0
N/A
0
N/A
// Gets and puts
0
N/A
0
N/A
relPut
(b);
0
N/A
relGet
(b);
0
N/A
absGet
(b);
0
N/A
bulkGet
(b);
0
N/A
0
N/A
absPut
(b);
0
N/A
relGet
(b);
0
N/A
absGet
(b);
0
N/A
bulkGet
(b);
0
N/A
0
N/A
bulkPutArray
(b);
0
N/A
relGet
(b);
0
N/A
0
N/A
bulkPutBuffer
(b);
0
N/A
relGet
(b);
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
1108
N/A
1108
N/A
1108
N/A
0
N/A
// Compact
0
N/A
0
N/A
relPut
(b);
0
N/A
b.
position
(
13
);
0
N/A
b.
compact
();
0
N/A
b.
flip
();
0
N/A
relGet
(b,
13
);
0
N/A
0
N/A
// Exceptions
0
N/A
0
N/A
relPut
(b);
0
N/A
b.
limit
(b.
capacity
() /
2
);
0
N/A
b.
position
(b.
limit
());
0
N/A
0
N/A
tryCatch
(b,
BufferUnderflowException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
b.
get
();
0
N/A
}});
0
N/A
0
N/A
tryCatch
(b,
BufferOverflowException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
b.
put
((
byte
)
42
);
0
N/A
}});
0
N/A
0
N/A
// The index must be non-negative and lesss than the buffer's limit.
0
N/A
tryCatch
(b,
IndexOutOfBoundsException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
b.
get
(b.
limit
());
0
N/A
}});
0
N/A
tryCatch
(b,
IndexOutOfBoundsException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
b.
get
(-
1
);
0
N/A
}});
0
N/A
0
N/A
tryCatch
(b,
IndexOutOfBoundsException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
b.
put
(b.
limit
(), (
byte
)
42
);
0
N/A
}});
0
N/A
721
N/A
tryCatch
(b,
InvalidMarkException
.
class
,
new
Runnable
() {
721
N/A
public
void
run
() {
721
N/A
b.
position
(
0
);
721
N/A
b.
mark
();
721
N/A
b.
compact
();
721
N/A
b.
reset
();
721
N/A
}});
721
N/A
0
N/A
// Values
0
N/A
0
N/A
b.
clear
();
0
N/A
b.
put
((
byte
)
0
);
0
N/A
b.
put
((
byte
)-
1
);
0
N/A
b.
put
((
byte
)
1
);
0
N/A
b.
put
(
Byte
.
MAX_VALUE
);
0
N/A
b.
put
(
Byte
.
MIN_VALUE
);
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
byte
v;
0
N/A
b.
flip
();
0
N/A
ck
(b, b.
get
(),
0
);
0
N/A
ck
(b, b.
get
(), (
byte
)-
1
);
0
N/A
ck
(b, b.
get
(),
1
);
0
N/A
ck
(b, b.
get
(),
Byte
.
MAX_VALUE
);
0
N/A
ck
(b, b.
get
(),
Byte
.
MIN_VALUE
);
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
// Comparison
0
N/A
b.
rewind
();
0
N/A
ByteBuffer
b2
=
ByteBuffer
.
allocate
(b.
capacity
());
0
N/A
b2
.
put
(b);
0
N/A
b2
.
flip
();
0
N/A
b.
position
(
2
);
0
N/A
b2
.
position
(
2
);
0
N/A
if
(!b.
equals
(
b2
)) {
0
N/A
for
(
int
i =
2
; i < b.
limit
(); i++) {
0
N/A
byte
x = b.
get
(i);
0
N/A
byte
y =
b2
.
get
(i);
0
N/A
if
(x != y
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
)
0
N/A
out
.
println
(
"["
+ i +
"] "
+ x +
" != "
+ y);
0
N/A
}
0
N/A
fail
(
"Identical buffers not equal"
, b,
b2
);
0
N/A
}
0
N/A
if
(b.
compareTo
(
b2
) !=
0
)
0
N/A
fail
(
"Comparison to identical buffer != 0"
, b,
b2
);
0
N/A
0
N/A
b.
limit
(b.
limit
() +
1
);
0
N/A
b.
position
(b.
limit
() -
1
);
0
N/A
b.
put
((
byte
)
99
);
0
N/A
b.
rewind
();
0
N/A
b2
.
rewind
();
0
N/A
if
(b.
equals
(
b2
))
0
N/A
fail
(
"Non-identical buffers equal"
, b,
b2
);
0
N/A
if
(b.
compareTo
(
b2
) <=
0
)
0
N/A
fail
(
"Comparison to shorter buffer <= 0"
, b,
b2
);
0
N/A
b.
limit
(b.
limit
() -
1
);
0
N/A
0
N/A
b.
put
(
2
, (
byte
)
42
);
0
N/A
if
(b.
equals
(
b2
))
0
N/A
fail
(
"Non-identical buffers equal"
, b,
b2
);
0
N/A
if
(b.
compareTo
(
b2
) <=
0
)
0
N/A
fail
(
"Comparison to lesser buffer <= 0"
, b,
b2
);
0
N/A
2005
N/A
// Check equals and compareTo with interesting values
2005
N/A
for
(
byte
x :
VALUES
) {
2005
N/A
ByteBuffer
xb
=
ByteBuffer
.
wrap
(
new
byte
[] { x });
2005
N/A
if
(
xb
.
compareTo
(
xb
) !=
0
) {
2005
N/A
fail
(
"compareTo not reflexive"
,
xb
,
xb
, x, x);
2005
N/A
}
2005
N/A
if
(!
xb
.
equals
(
xb
)) {
2005
N/A
fail
(
"equals not reflexive"
,
xb
,
xb
, x, x);
2005
N/A
}
2005
N/A
for
(
byte
y :
VALUES
) {
2005
N/A
ByteBuffer
yb
=
ByteBuffer
.
wrap
(
new
byte
[] { y });
2005
N/A
if
(
xb
.
compareTo
(
yb
) != -
yb
.
compareTo
(
xb
)) {
2005
N/A
fail
(
"compareTo not anti-symmetric"
,
2005
N/A
xb
,
yb
, x, y);
2005
N/A
}
2005
N/A
if
((
xb
.
compareTo
(
yb
) ==
0
) !=
xb
.
equals
(
yb
)) {
2005
N/A
fail
(
"compareTo inconsistent with equals"
,
2005
N/A
xb
,
yb
, x, y);
2005
N/A
}
2005
N/A
if
(
xb
.
compareTo
(
yb
) !=
Byte
.
compare
(x, y)) {
2005
N/A
2005
N/A
2005
N/A
2005
N/A
2005
N/A
2005
N/A
2005
N/A
fail
(
"Incorrect results for ByteBuffer.compareTo"
,
2005
N/A
xb
,
yb
, x, y);
2005
N/A
}
2005
N/A
if
(
xb
.
equals
(
yb
) != ((x == y) || ((x != x) && (y != y)))) {
2005
N/A
fail
(
"Incorrect results for ByteBuffer.equals"
,
2005
N/A
xb
,
yb
, x, y);
2005
N/A
}
2005
N/A
}
2005
N/A
}
2005
N/A
0
N/A
// Sub, dup
0
N/A
0
N/A
relPut
(b);
0
N/A
relGet
(b.
duplicate
());
0
N/A
b.
position
(
13
);
0
N/A
relGet
(b.
duplicate
(),
13
);
0
N/A
relGet
(b.
duplicate
().
slice
(),
13
);
0
N/A
relGet
(b.
slice
(),
13
);
0
N/A
relGet
(b.
slice
().
duplicate
(),
13
);
0
N/A
0
N/A
// Slice
0
N/A
0
N/A
b.
position
(
5
);
0
N/A
ByteBuffer
sb
= b.
slice
();
0
N/A
checkSlice
(b,
sb
);
0
N/A
b.
position
(
0
);
0
N/A
ByteBuffer
sb2
=
sb
.
slice
();
0
N/A
checkSlice
(
sb
,
sb2
);
0
N/A
0
N/A
if
(!
sb
.
equals
(
sb2
))
0
N/A
fail
(
"Sliced slices do not match"
,
sb
,
sb2
);
0
N/A
if
((
sb
.
hasArray
()) && (
sb
.
arrayOffset
() !=
sb2
.
arrayOffset
()))
0
N/A
fail
(
"Array offsets do not match: "
0
N/A
+
sb
.
arrayOffset
() +
" != "
+
sb2
.
arrayOffset
(),
sb
,
sb2
);
0
N/A
0
N/A
0
N/A
0
N/A
// Views
0
N/A
0
N/A
b.
clear
();
0
N/A
b.
order
(
ByteOrder
.
BIG_ENDIAN
);
0
N/A
testViews
(
level
+
1
, b,
direct
);
0
N/A
0
N/A
for
(
int
i =
1
; i <=
9
; i++) {
0
N/A
b.
position
(i);
0
N/A
show
(
level
+
1
, b);
0
N/A
testViews
(
level
+
2
, b,
direct
);
0
N/A
}
0
N/A
0
N/A
b.
position
(
0
);
0
N/A
b.
order
(
ByteOrder
.
LITTLE_ENDIAN
);
0
N/A
testViews
(
level
+
1
, b,
direct
);
0
N/A
0
N/A
// Heterogeneous accessors
0
N/A
0
N/A
b.
order
(
ByteOrder
.
BIG_ENDIAN
);
0
N/A
for
(
int
i =
0
; i <=
9
; i++) {
0
N/A
b.
position
(i);
0
N/A
testHet
(
level
+
1
, b);
0
N/A
}
0
N/A
b.
order
(
ByteOrder
.
LITTLE_ENDIAN
);
0
N/A
b.
position
(
3
);
0
N/A
testHet
(
level
+
1
, b);
0
N/A
0
N/A
0
N/A
0
N/A
// Read-only views
0
N/A
0
N/A
b.
rewind
();
0
N/A
final
ByteBuffer
rb
= b.
asReadOnlyBuffer
();
0
N/A
if
(!b.
equals
(
rb
))
0
N/A
fail
(
"Buffer not equal to read-only view"
, b,
rb
);
0
N/A
show
(
level
+
1
,
rb
);
0
N/A
0
N/A
tryCatch
(b,
ReadOnlyBufferException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
relPut
(
rb
);
0
N/A
}});
0
N/A
0
N/A
tryCatch
(b,
ReadOnlyBufferException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
absPut
(
rb
);
0
N/A
}});
0
N/A
0
N/A
tryCatch
(b,
ReadOnlyBufferException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
bulkPutArray
(
rb
);
0
N/A
}});
0
N/A
0
N/A
tryCatch
(b,
ReadOnlyBufferException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
bulkPutBuffer
(
rb
);
0
N/A
}});
0
N/A
0
N/A
tryCatch
(b,
ReadOnlyBufferException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
rb
.
compact
();
0
N/A
}});
0
N/A
0
N/A
0
N/A
0
N/A
tryCatch
(b,
ReadOnlyBufferException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
rb
.
putChar
((
char
)
1
);
0
N/A
}});
0
N/A
tryCatch
(b,
ReadOnlyBufferException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
rb
.
putChar
(
0
, (
char
)
1
);
0
N/A
}});
0
N/A
0
N/A
tryCatch
(b,
ReadOnlyBufferException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
rb
.
putShort
((
short
)
1
);
0
N/A
}});
0
N/A
tryCatch
(b,
ReadOnlyBufferException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
rb
.
putShort
(
0
, (
short
)
1
);
0
N/A
}});
0
N/A
0
N/A
tryCatch
(b,
ReadOnlyBufferException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
rb
.
putInt
(
1
);
0
N/A
}});
0
N/A
tryCatch
(b,
ReadOnlyBufferException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
rb
.
putInt
(
0
,
1
);
0
N/A
}});
0
N/A
0
N/A
tryCatch
(b,
ReadOnlyBufferException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
rb
.
putLong
((
long
)
1
);
0
N/A
}});
0
N/A
tryCatch
(b,
ReadOnlyBufferException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
rb
.
putLong
(
0
, (
long
)
1
);
0
N/A
}});
0
N/A
0
N/A
tryCatch
(b,
ReadOnlyBufferException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
rb
.
putFloat
((
float
)
1
);
0
N/A
}});
0
N/A
tryCatch
(b,
ReadOnlyBufferException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
rb
.
putFloat
(
0
, (
float
)
1
);
0
N/A
}});
0
N/A
0
N/A
tryCatch
(b,
ReadOnlyBufferException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
rb
.
putDouble
((
double
)
1
);
0
N/A
}});
0
N/A
tryCatch
(b,
ReadOnlyBufferException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
rb
.
putDouble
(
0
, (
double
)
1
);
0
N/A
}});
0
N/A
0
N/A
0
N/A
0
N/A
if
(
rb
.
getClass
().
getName
().
startsWith
(
"java.nio.Heap"
)) {
0
N/A
0
N/A
tryCatch
(b,
ReadOnlyBufferException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
rb
.
array
();
0
N/A
}});
0
N/A
0
N/A
tryCatch
(b,
ReadOnlyBufferException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
rb
.
arrayOffset
();
0
N/A
}});
0
N/A
0
N/A
if
(
rb
.
hasArray
())
0
N/A
fail
(
"Read-only heap buffer's backing array is accessible"
,
0
N/A
rb
);
0
N/A
0
N/A
}
0
N/A
0
N/A
// Bulk puts from read-only buffers
0
N/A
0
N/A
b.
clear
();
0
N/A
rb
.
rewind
();
0
N/A
b.
put
(
rb
);
0
N/A
0
N/A
0
N/A
// For byte buffers, test both the direct and non-direct cases
0
N/A
ByteBuffer
ob
0
N/A
= (b.
isDirect
()
0
N/A
?
ByteBuffer
.
allocate
(
rb
.
capacity
())
0
N/A
:
ByteBuffer
.
allocateDirect
(
rb
.
capacity
()));
0
N/A
rb
.
rewind
();
0
N/A
ob
.
put
(
rb
);
0
N/A
0
N/A
0
N/A
relPut
(b);
// Required by testViews
0
N/A
0
N/A
}
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
1108
N/A
1108
N/A
0
N/A
public
static
void
test
(
final
byte
[]
ba
) {
0
N/A
int
offset
=
47
;
0
N/A
int
length
=
900
;
0
N/A
final
ByteBuffer
b =
ByteBuffer
.
wrap
(
ba
,
offset
,
length
);
0
N/A
show
(
0
, b);
0
N/A
ck
(b, b.
capacity
(),
ba
.
length
);
0
N/A
ck
(b, b.
position
(),
offset
);
0
N/A
ck
(b, b.
limit
(),
offset
+
length
);
0
N/A
0
N/A
// The offset must be non-negative and no larger than <array.length>.
0
N/A
tryCatch
(
ba
,
IndexOutOfBoundsException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
ByteBuffer
.
wrap
(
ba
, -
1
,
ba
.
length
);
0
N/A
}});
0
N/A
tryCatch
(
ba
,
IndexOutOfBoundsException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
ByteBuffer
.
wrap
(
ba
,
ba
.
length
+
1
,
ba
.
length
);
0
N/A
}});
0
N/A
tryCatch
(
ba
,
IndexOutOfBoundsException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
ByteBuffer
.
wrap
(
ba
,
0
, -
1
);
0
N/A
}});
0
N/A
tryCatch
(
ba
,
IndexOutOfBoundsException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
ByteBuffer
.
wrap
(
ba
,
0
,
ba
.
length
+
1
);
0
N/A
}});
0
N/A
0
N/A
// A NullPointerException will be thrown if the array is null.
0
N/A
tryCatch
(
ba
,
NullPointerException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
ByteBuffer
.
wrap
((
byte
[])
null
,
0
,
5
);
0
N/A
}});
0
N/A
tryCatch
(
ba
,
NullPointerException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
ByteBuffer
.
wrap
((
byte
[])
null
);
0
N/A
}});
0
N/A
}
0
N/A
0
N/A
private
static
void
testAllocate
() {
0
N/A
// An IllegalArgumentException will be thrown for negative capacities.
0
N/A
tryCatch
((
Buffer
)
null
,
IllegalArgumentException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
ByteBuffer
.
allocate
(-
1
);
0
N/A
}});
0
N/A
0
N/A
tryCatch
((
Buffer
)
null
,
IllegalArgumentException
.
class
,
new
Runnable
() {
0
N/A
public
void
run
() {
0
N/A
ByteBuffer
.
allocateDirect
(-
1
);
0
N/A
}});
0
N/A
0
N/A
}
0
N/A
0
N/A
public
static
void
test
() {
0
N/A
testAllocate
();
0
N/A
test
(
0
,
ByteBuffer
.
allocate
(
7
*
1024
),
false
);
0
N/A
test
(
0
,
ByteBuffer
.
wrap
(
new
byte
[
7
*
1024
],
0
,
7
*
1024
),
false
);
0
N/A
test
(
new
byte
[
1024
]);
0
N/A
0
N/A
ByteBuffer
b =
ByteBuffer
.
allocateDirect
(
7
*
1024
);
0
N/A
for
(b.
position
(
0
); b.
position
() < b.
limit
(); )
0
N/A
ck
(b, b.
get
(),
0
);
0
N/A
test
(
0
, b,
true
);
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
callReset
(
ByteBuffer
.
allocate
(
10
));
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
0
N/A
}
0
N/A
0
N/A
}