Top Description Fields Constructors Methods
jdk.internal.util

public final Class ByteArray

extends Object
Class Inheritance
Imports
java.lang.invoke.MethodHandles, .VarHandle, java.nio.ByteOrder

Utility methods for packing/unpacking primitive values in/out of byte arrays using big endian order (aka. "network order").

All methods in this class will throw an NullPointerException if null is passed in as a method parameter for a byte array.

Field Summary

Modifier and TypeField and Description
private static final VarHandle
private static final VarHandle
private static final VarHandle
private static final VarHandle
private static final VarHandle
private static final VarHandle

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static VarHandle
create(Class<?> viewArrayClass)

public static boolean

Returns:

a boolean from the provided array at the given offset
getBoolean
(byte[]
to read a value from.
array
,
int
where extraction in the array should begin
offset
)

Returns a boolean from the provided array at the given offset.

public static char

Returns:

a char from the provided array at the given offset using big endian order
getChar
(byte[]
to get a value from.
array
,
int
where extraction in the array should begin
offset
)

Returns a char from the provided array at the given offset using big endian order.

public static double

Returns:

a double from the provided array at the given offset using big endian order
getDouble
(byte[]
to get a value from.
array
,
int
where extraction in the array should begin
offset
)

Returns a double from the provided array at the given offset using big endian order.

public static double

Returns:

a double from the provided array at the given offset using big endian order
getDoubleRaw
(byte[]
to get a value from.
array
,
int
where extraction in the array should begin
offset
)

Returns a double from the provided array at the given offset using big endian order.

public static float

Returns:

a float from the provided array at the given offset using big endian order
getFloat
(byte[]
to get a value from.
array
,
int
where extraction in the array should begin
offset
)

Returns a float from the provided array at the given offset using big endian order.

public static float

Returns:

a float from the provided array at the given offset using big endian order
getFloatRaw
(byte[]
to get a value from.
array
,
int
where extraction in the array should begin
offset
)

Returns a float from the provided array at the given offset using big endian order.

public static int

Returns:

an int from the provided array at the given offset using big endian order
getInt
(byte[]
to get a value from.
array
,
int
where extraction in the array should begin
offset
)

Returns an int from the provided array at the given offset using big endian order.

public static long

Returns:

a long from the provided array at the given offset using big endian order
getLong
(byte[]
to get a value from.
array
,
int
where extraction in the array should begin
offset
)

Returns a long from the provided array at the given offset using big endian order.

public static short

Returns:

a short from the array
getShort
(byte[]
to get a value from.
array
,
int
where extraction in the array should begin
offset
)

Returns a short from the provided array at the given offset using big endian order.

public static int

Returns:

an int representing an unsigned short from the array
getUnsignedShort
(byte[]
to get a value from.
array
,
int
where extraction in the array should begin
offset
)

Returns an unsigned short from the provided array at the given offset using big endian order.

public static void
setBoolean(byte[]
to set (write) a value into
array
,
int
where setting (writing) in the array should begin
offset
,
boolean
value to set in the array
value
)

Sets (writes) the provided value into the provided array beginning at the given offset.

public static void
setChar(byte[]
to set (write) a value into
array
,
int
where setting (writing) in the array should begin
offset
,
char
value to set in the array
value
)

Sets (writes) the provided value using big endian order into the provided array beginning at the given offset.

public static void
setDouble(byte[]
to set (write) a value into
array
,
int
where setting (writing) in the array should begin
offset
,
double
value to set in the array
value
)

Sets (writes) the provided value using big endian order into the provided array beginning at the given offset.

public static void
setDoubleRaw(byte[]
to set (write) a value into
array
,
int
where setting (writing) in the array should begin
offset
,
double
value to set in the array
value
)

Sets (writes) the provided value using big endian order into the provided array beginning at the given offset.

public static void
setFloat(byte[]
to set (write) a value into
array
,
int
where setting (writing) in the array should begin
offset
,
float
value to set in the array
value
)

Sets (writes) the provided value using big endian order into the provided array beginning at the given offset.

public static void
setFloatRaw(byte[]
to set (write) a value into
array
,
int
where setting (writing) in the array should begin
offset
,
float
value to set in the array
value
)

Sets (writes) the provided value using big endian order into the provided array beginning at the given offset.

public static void
setInt(byte[]
to set (write) a value into
array
,
int
where setting (writing) in the array should begin
offset
,
int
value to set in the array
value
)

Sets (writes) the provided value using big endian order into the provided array beginning at the given offset.

public static void
setLong(byte[]
to set (write) a value into
array
,
int
where setting (writing) in the array should begin
offset
,
long
value to set in the array
value
)

Sets (writes) the provided value using big endian order into the provided array beginning at the given offset.

public static void
setShort(byte[]
to set (write) a value into
array
,
int
where setting (writing) in the array should begin
offset
,
short
value to set in the array
value
)

Sets (writes) the provided value using big endian order into the provided array beginning at the given offset.

public static void
setUnsignedShort(byte[]
to set (write) a value into
array
,
int
where setting (writing) in the array should begin
offset
,
int
value to set in the array
value
)

Sets (writes) the provided value using big endian order into the provided array beginning at the given offset.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CHARback to summary
private static final VarHandle CHAR
DOUBLEback to summary
private static final VarHandle DOUBLE
FLOATback to summary
private static final VarHandle FLOAT
INTback to summary
private static final VarHandle INT
LONGback to summary
private static final VarHandle LONG
SHORTback to summary
private static final VarHandle SHORT

Constructor Detail

ByteArrayback to summary
private ByteArray()

Method Detail

createback to summary
private static VarHandle create(Class<?> viewArrayClass)
getBooleanback to summary
public static boolean getBoolean(byte[] array, int offset)

Returns a boolean from the provided array at the given offset. .

Parameters
array:byte[]

to read a value from.

offset:int

where extraction in the array should begin

Returns:boolean

a boolean from the provided array at the given offset

Exceptions
IndexOutOfBoundsException:
if the provided offset is outside the range [0, array.length - 1]
See Also
setBoolean(byte[], int, boolean)
getCharback to summary
public static char getChar(byte[] array, int offset)

Returns a char from the provided array at the given offset using big endian order. .

There are no access alignment requirements.

Parameters
array:byte[]

to get a value from.

offset:int

where extraction in the array should begin

Returns:char

a char from the provided array at the given offset using big endian order

Exceptions
IndexOutOfBoundsException:
if the provided offset is outside the range [0, array.length - 2]
See Also
setChar(byte[], int, char)
getDoubleback to summary
public static double getDouble(byte[] array, int offset)

Returns a double from the provided array at the given offset using big endian order. .

Variants of Double#NaN values are canonized to a single NaN value.

There are no access alignment requirements.

Parameters
array:byte[]

to get a value from.

offset:int

where extraction in the array should begin

Returns:double

a double from the provided array at the given offset using big endian order

Exceptions
IndexOutOfBoundsException:
if the provided offset is outside the range [0, array.length - 8]
See Also
setDouble(byte[], int, double)
getDoubleRawback to summary
public static double getDoubleRaw(byte[] array, int offset)

Returns a double from the provided array at the given offset using big endian order. .

Variants of Double#NaN values are silently read according to their bit patterns.

There are no access alignment requirements.

Parameters
array:byte[]

to get a value from.

offset:int

where extraction in the array should begin

Returns:double

a double from the provided array at the given offset using big endian order

Exceptions
IndexOutOfBoundsException:
if the provided offset is outside the range [0, array.length - 8]
See Also
setDoubleRaw(byte[], int, double)
getFloatback to summary
public static float getFloat(byte[] array, int offset)

Returns a float from the provided array at the given offset using big endian order. .

Variants of Float#NaN values are canonized to a single NaN value.

There are no access alignment requirements.

Parameters
array:byte[]

to get a value from.

offset:int

where extraction in the array should begin

Returns:float

a float from the provided array at the given offset using big endian order

Exceptions
IndexOutOfBoundsException:
if the provided offset is outside the range [0, array.length - 4]
See Also
setFloat(byte[], int, float)
getFloatRawback to summary
public static float getFloatRaw(byte[] array, int offset)

Returns a float from the provided array at the given offset using big endian order. .

Variants of Float#NaN values are silently read according to their bit patterns.

There are no access alignment requirements.

Parameters
array:byte[]

to get a value from.

offset:int

where extraction in the array should begin

Returns:float

a float from the provided array at the given offset using big endian order

Exceptions
IndexOutOfBoundsException:
if the provided offset is outside the range [0, array.length - 4]
See Also
setFloatRaw(byte[], int, float)
getIntback to summary
public static int getInt(byte[] array, int offset)

Returns an int from the provided array at the given offset using big endian order. .

There are no access alignment requirements.

Parameters
array:byte[]

to get a value from.

offset:int

where extraction in the array should begin

Returns:int

an int from the provided array at the given offset using big endian order

Exceptions
IndexOutOfBoundsException:
if the provided offset is outside the range [0, array.length - 4]
See Also
setInt(byte[], int, int)
getLongback to summary
public static long getLong(byte[] array, int offset)

Returns a long from the provided array at the given offset using big endian order. .

There are no access alignment requirements.

Parameters
array:byte[]

to get a value from.

offset:int

where extraction in the array should begin

Returns:long

a long from the provided array at the given offset using big endian order

Exceptions
IndexOutOfBoundsException:
if the provided offset is outside the range [0, array.length - 8]
See Also
setLong(byte[], int, long)
getShortback to summary
public static short getShort(byte[] array, int offset)

Returns a short from the provided array at the given offset using big endian order. .

There are no access alignment requirements.

Parameters
array:byte[]

to get a value from.

offset:int

where extraction in the array should begin

Returns:short

a short from the array

Exceptions
IndexOutOfBoundsException:
if the provided offset is outside the range [0, array.length - 2]
See Also
setShort(byte[], int, short)
getUnsignedShortback to summary
public static int getUnsignedShort(byte[] array, int offset)

Returns an unsigned short from the provided array at the given offset using big endian order. .

There are no access alignment requirements.

Parameters
array:byte[]

to get a value from.

offset:int

where extraction in the array should begin

Returns:int

an int representing an unsigned short from the array

Exceptions
IndexOutOfBoundsException:
if the provided offset is outside the range [0, array.length - 2]
See Also
setUnsignedShort(byte[], int, int)
setBooleanback to summary
public static void setBoolean(byte[] array, int offset, boolean value)

Sets (writes) the provided value into the provided array beginning at the given offset.

Parameters
array:byte[]

to set (write) a value into

offset:int

where setting (writing) in the array should begin

value:boolean

value to set in the array

Exceptions
IndexOutOfBoundsException:
if the provided offset is outside the range [0, array.length]
See Also
getBoolean(byte[], int)
setCharback to summary
public static void setChar(byte[] array, int offset, char value)

Sets (writes) the provided value using big endian order into the provided array beginning at the given offset.

There are no access alignment requirements.

Parameters
array:byte[]

to set (write) a value into

offset:int

where setting (writing) in the array should begin

value:char

value to set in the array

Exceptions
IndexOutOfBoundsException:
if the provided offset is outside the range [0, array.length - 2]
See Also
getChar(byte[], int)
setDoubleback to summary
public static void setDouble(byte[] array, int offset, double value)

Sets (writes) the provided value using big endian order into the provided array beginning at the given offset.

Variants of Double#NaN values are canonized to a single NaN value.

There are no access alignment requirements.

Parameters
array:byte[]

to set (write) a value into

offset:int

where setting (writing) in the array should begin

value:double

value to set in the array

Exceptions
IndexOutOfBoundsException:
if the provided offset is outside the range [0, array.length - 2]
See Also
getDouble(byte[], int)
setDoubleRawback to summary
public static void setDoubleRaw(byte[] array, int offset, double value)

Sets (writes) the provided value using big endian order into the provided array beginning at the given offset.

Variants of Double#NaN values are silently written according to their bit patterns.

There are no access alignment requirements.

Parameters
array:byte[]

to set (write) a value into

offset:int

where setting (writing) in the array should begin

value:double

value to set in the array

Exceptions
IndexOutOfBoundsException:
if the provided offset is outside the range [0, array.length - 2]
See Also
getDoubleRaw(byte[], int)
setFloatback to summary
public static void setFloat(byte[] array, int offset, float value)

Sets (writes) the provided value using big endian order into the provided array beginning at the given offset.

Variants of Float#NaN values are canonized to a single NaN value.

There are no access alignment requirements.

Parameters
array:byte[]

to set (write) a value into

offset:int

where setting (writing) in the array should begin

value:float

value to set in the array

Exceptions
IndexOutOfBoundsException:
if the provided offset is outside the range [0, array.length - 2]
See Also
getFloat(byte[], int)
setFloatRawback to summary
public static void setFloatRaw(byte[] array, int offset, float value)

Sets (writes) the provided value using big endian order into the provided array beginning at the given offset.

Variants of Float#NaN values are silently written according to their bit patterns.

There are no access alignment requirements.

Parameters
array:byte[]

to set (write) a value into

offset:int

where setting (writing) in the array should begin

value:float

value to set in the array

Exceptions
IndexOutOfBoundsException:
if the provided offset is outside the range [0, array.length - 2]
See Also
getFloatRaw(byte[], int)
setIntback to summary
public static void setInt(byte[] array, int offset, int value)

Sets (writes) the provided value using big endian order into the provided array beginning at the given offset.

There are no access alignment requirements.

Parameters
array:byte[]

to set (write) a value into

offset:int

where setting (writing) in the array should begin

value:int

value to set in the array

Exceptions
IndexOutOfBoundsException:
if the provided offset is outside the range [0, array.length - 4]
See Also
getInt(byte[], int)
setLongback to summary
public static void setLong(byte[] array, int offset, long value)

Sets (writes) the provided value using big endian order into the provided array beginning at the given offset.

There are no access alignment requirements.

Parameters
array:byte[]

to set (write) a value into

offset:int

where setting (writing) in the array should begin

value:long

value to set in the array

Exceptions
IndexOutOfBoundsException:
if the provided offset is outside the range [0, array.length - 4]
See Also
getLong(byte[], int)
setShortback to summary
public static void setShort(byte[] array, int offset, short value)

Sets (writes) the provided value using big endian order into the provided array beginning at the given offset.

There are no access alignment requirements.

Parameters
array:byte[]

to set (write) a value into

offset:int

where setting (writing) in the array should begin

value:short

value to set in the array

Exceptions
IndexOutOfBoundsException:
if the provided offset is outside the range [0, array.length - 2]
See Also
getShort(byte[], int)
setUnsignedShortback to summary
public static void setUnsignedShort(byte[] array, int offset, int value)

Sets (writes) the provided value using big endian order into the provided array beginning at the given offset.

There are no access alignment requirements.

Parameters
array:byte[]

to set (write) a value into

offset:int

where setting (writing) in the array should begin

value:int

value to set in the array

Exceptions
IndexOutOfBoundsException:
if the provided offset is outside the range [0, array.length - 2]
See Also
getUnsignedShort(byte[], int)