Class ByteArraySupport
littleEndian()
or bigEndian()
respectively to access byte arrays in
little-endian or big-endian order.
Thread safety
The methods of this class are not safe for use by multiple concurrent threads, unless otherwise stated. If a byte array is to be used by more than one thread then access to the byte array should be controlled by appropriate synchronization.
Alignment
Unaligned accesses are allowed, but will not constant-fold during partial evaluation. If constant
folding is desired, consider using the unaligned methods (e.g., getIntUnaligned(byte[], int)
) to read
immutable data from unaligned offsets.
- Since:
- 20.3
-
Method Summary
Modifier and TypeMethodDescriptionstatic ByteArraySupport
Enables accessing multibyte Java primitives from byte arrays in big-endian order.abstract byte
compareAndExchangeByte
(byte[] buffer, long byteOffset, byte expected, byte x) Atomically exchanges the given byte with the current byte at the given byte offset from the start of the buffer, if and only if the current byte equals the expected byte.abstract int
compareAndExchangeInt
(byte[] buffer, long byteOffset, int expected, int x) Atomically exchanges the given int with the current int at the given byte offset from the start of the buffer, if and only if the current int equals the expected int.abstract long
compareAndExchangeLong
(byte[] buffer, long byteOffset, long expected, long x) Atomically exchanges the given long with the current long at the given byte offset from the start of the buffer, if and only if the current long equals the expected long.abstract short
compareAndExchangeShort
(byte[] buffer, long byteOffset, short expected, short x) Atomically exchanges the given short with the current short at the given byte offset from the start of the buffer, if and only if the current short equals the expected short.abstract byte
getAndAddByte
(byte[] buffer, long byteOffset, byte delta) Atomically adds the given byte to the current byte at the given byte offset from the start of the buffer.abstract int
getAndAddInt
(byte[] buffer, long byteOffset, int delta) Atomically adds the given int to the current int at the given byte offset from the start of the buffer.abstract long
getAndAddLong
(byte[] buffer, long byteOffset, long delta) Atomically adds the given long to the current long at the given byte offset from the start of the buffer.abstract short
getAndAddShort
(byte[] buffer, long byteOffset, short delta) Atomically adds the given short to the current short at the given byte offset from the start of the buffer.abstract byte
getAndBitwiseAndByte
(byte[] buffer, long byteOffset, byte mask) Atomically bitwise-ANDs the given byte to the current byte at the given byte offset from the start of the buffer.abstract int
getAndBitwiseAndInt
(byte[] buffer, long byteOffset, int mask) Atomically bitwise-ANDs the given int to the current int at the given byte offset from the start of the buffer.abstract long
getAndBitwiseAndLong
(byte[] buffer, long byteOffset, long mask) Atomically bitwise-ANDs the given long to the current long at the given byte offset from the start of the buffer.abstract short
getAndBitwiseAndShort
(byte[] buffer, long byteOffset, short mask) Atomically bitwise-ANDs the given short to the current short at the given byte offset from the start of the buffer.abstract byte
getAndBitwiseOrByte
(byte[] buffer, long byteOffset, byte mask) Atomically bitwise-ORs the given byte to the current byte at the given byte offset from the start of the buffer.abstract int
getAndBitwiseOrInt
(byte[] buffer, long byteOffset, int mask) Atomically bitwise-ORs the given int to the current int at the given byte offset from the start of the buffer.abstract long
getAndBitwiseOrLong
(byte[] buffer, long byteOffset, long mask) Atomically bitwise-ORs the given long to the current long at the given byte offset from the start of the buffer.abstract short
getAndBitwiseOrShort
(byte[] buffer, long byteOffset, short mask) Atomically bitwise-ORs the given short to the current short at the given byte offset from the start of the buffer.abstract byte
getAndBitwiseXorByte
(byte[] buffer, long byteOffset, byte mask) Atomically bitwise-XORs the given byte to the current byte at the given byte offset from the start of the buffer.abstract int
getAndBitwiseXorInt
(byte[] buffer, long byteOffset, int mask) Atomically bitwise-XORs the given int to the current int at the given byte offset from the start of the buffer.abstract long
getAndBitwiseXorLong
(byte[] buffer, long byteOffset, long mask) Atomically bitwise-XORs the given long to the current long at the given byte offset from the start of the buffer.abstract short
getAndBitwiseXorShort
(byte[] buffer, long byteOffset, short mask) Atomically bitwise-XORs the given short to the current short at the given byte offset from the start of the buffer.abstract byte
getAndSetByte
(byte[] buffer, long byteOffset, byte newValue) Atomically exchanges the given byte with the current byte at the given byte offset from the start of the buffer.abstract int
getAndSetInt
(byte[] buffer, long byteOffset, int newValue) Atomically exchanges the given int with the current int at the given byte offset from the start of the buffer.abstract long
getAndSetLong
(byte[] buffer, long byteOffset, long newValue) Atomically exchanges the given long with the current long at the given byte offset from the start of the buffer.abstract short
getAndSetShort
(byte[] buffer, long byteOffset, short newValue) Atomically exchanges the given short with the current short at the given byte offset from the start of the buffer.abstract byte
getByte
(byte[] buffer, int byteOffset) Reads the byte at the given byte offset from the start of the buffer.abstract byte
getByte
(byte[] buffer, long byteOffset) Reads the byte at the given byte offset from the start of the buffer.abstract byte
getByteVolatile
(byte[] buffer, long byteOffset) Volatile version ofgetByte(byte[], long)
.abstract double
getDouble
(byte[] buffer, int byteOffset) Reads the double at the given byte offset from the start of the buffer.abstract double
getDouble
(byte[] buffer, long byteOffset) Reads the double at the given byte offset from the start of the buffer.abstract float
getFloat
(byte[] buffer, int byteOffset) Reads the float at the given byte offset from the start of the buffer.abstract float
getFloat
(byte[] buffer, long byteOffset) Reads the float at the given byte offset from the start of the buffer.abstract int
getInt
(byte[] buffer, int byteOffset) Reads the int at the given byte offset from the start of the buffer.abstract int
getInt
(byte[] buffer, long byteOffset) Reads the int at the given byte offset from the start of the buffer.abstract int
getIntUnaligned
(byte[] buffer, int byteOffset) Reads the int at the given byte offset from the start of the buffer.abstract int
getIntUnaligned
(byte[] buffer, long byteOffset) Reads the int at the given byte offset from the start of the buffer.abstract int
getIntVolatile
(byte[] buffer, long byteOffset) Volatile version ofgetInt(byte[], long)
.abstract long
getLong
(byte[] buffer, int byteOffset) Reads the long at the given byte offset from the start of the buffer.abstract long
getLong
(byte[] buffer, long byteOffset) Reads the long at the given byte offset from the start of the buffer.abstract long
getLongUnaligned
(byte[] buffer, int byteOffset) Reads the long at the given byte offset from the start of the buffer.abstract long
getLongUnaligned
(byte[] buffer, long byteOffset) Reads the long at the given byte offset from the start of the buffer.abstract long
getLongVolatile
(byte[] buffer, long byteOffset) Volatile version ofgetLong(byte[], long)
.abstract short
getShort
(byte[] buffer, int byteOffset) Reads the short at the given byte offset from the start of the buffer.abstract short
getShort
(byte[] buffer, long byteOffset) Reads the short at the given byte offset from the start of the buffer.abstract short
getShortUnaligned
(byte[] buffer, int byteOffset) Reads the short at the given byte offset from the start of the buffer.abstract short
getShortUnaligned
(byte[] buffer, long byteOffset) Reads the short at the given byte offset from the start of the buffer.abstract short
getShortVolatile
(byte[] buffer, long byteOffset) Volatile version ofgetShort(byte[], long)
.final boolean
inBounds
(byte[] buffer, int startByteOffset, int length) Checks if an access is in bounds of the given buffer.final boolean
inBounds
(byte[] buffer, long startByteOffset, long length) Checks if an access is in bounds of the given buffer.static ByteArraySupport
Enables accessing multibyte Java primitives from byte arrays in little-endian order.abstract void
putByte
(byte[] buffer, int byteOffset, byte value) Writes the given byte at the given byte offset from the start of the buffer.abstract void
putByte
(byte[] buffer, long byteOffset, byte value) Writes the given byte at the given byte offset from the start of the buffer.abstract void
putByteVolatile
(byte[] buffer, long byteOffset, byte value) Volatile version ofputByte(byte[], long, byte)
.abstract void
putDouble
(byte[] buffer, int byteOffset, double value) Writes the given double at the given byte offset from the start of the buffer.abstract void
putDouble
(byte[] buffer, long byteOffset, double value) Writes the given double at the given byte offset from the start of the buffer.abstract void
putFloat
(byte[] buffer, int byteOffset, float value) Writes the given float at the given byte offset from the start of the buffer.abstract void
putFloat
(byte[] buffer, long byteOffset, float value) Writes the given float at the given byte offset from the start of the buffer.abstract void
putInt
(byte[] buffer, int byteOffset, int value) Writes the given int at the given byte offset from the start of the buffer.abstract void
putInt
(byte[] buffer, long byteOffset, int value) Writes the given int at the given byte offset from the start of the buffer.abstract void
putIntVolatile
(byte[] buffer, long byteOffset, int value) Volatile version ofputInt(byte[], long, int)
.abstract void
putLong
(byte[] buffer, int byteOffset, long value) Writes the given long at the given byte offset from the start of the buffer.abstract void
putLong
(byte[] buffer, long byteOffset, long value) Writes the given long at the given byte offset from the start of the buffer.abstract void
putLongVolatile
(byte[] buffer, long byteOffset, long value) Volatile version ofputLong(byte[], long, long)
.abstract void
putShort
(byte[] buffer, int byteOffset, short value) Writes the given short at the given byte offset from the start of the buffer.abstract void
putShort
(byte[] buffer, long byteOffset, short value) Writes the given short at the given byte offset from the start of the buffer.abstract void
putShortVolatile
(byte[] buffer, long byteOffset, short value) Volatile version ofputShort(byte[], long, short)
.
-
Method Details
-
littleEndian
Enables accessing multibyte Java primitives from byte arrays in little-endian order.Example usage:
byte[] buffer = new byte[]{0, 0, 0, 0}; ByteArraySupport.littleEndian().putShort(buffer, 2, (short) 1); // buffer[2] == (byte) 1 // buffer[3] == (byte) 0 ByteArraySupport.littleEndian().putShort(buffer, 3, (short) 1); // throws IndexOutOfBoundsException exception
- Since:
- 20.3
-
bigEndian
Enables accessing multibyte Java primitives from byte arrays in big-endian order.Example usage:
byte[] buffer = new byte[]{0, 0, 0, 0}; ByteArraySupport.bigEndian().putShort(buffer, 0, (short) 1); // buffer[0] == (byte) 0 // buffer[1] == (byte) 1
- Since:
- 20.3
-
inBounds
public final boolean inBounds(byte[] buffer, int startByteOffset, int length) Checks if an access is in bounds of the given buffer.If out-of-bounds accesses are expected to happen frequently, it is faster (~1.2x in interpreter mode) to use this method to check for them than catching
IndexOutOfBoundsException
s.- Parameters:
buffer
- the byte arraystartByteOffset
- the start byte offset of the accesslength
- the number of bytes accessed- Returns:
- True if the access is in bounds, false otherwise
- Since:
- 20.3
-
inBounds
public final boolean inBounds(byte[] buffer, long startByteOffset, long length) Checks if an access is in bounds of the given buffer.If out-of-bounds accesses are expected to happen frequently, it is faster (~1.2x in interpreter mode) to use this method to check for them than catching
IndexOutOfBoundsException
s.- Parameters:
buffer
- the byte arraystartByteOffset
- the start byte offset of the accesslength
- the number of bytes accessed- Returns:
- True if the access is in bounds, false otherwise
- Since:
- 22.2
-
getByte
Reads the byte at the given byte offset from the start of the buffer.- Parameters:
buffer
- the byte array to read frombyteOffset
- the byte offset at which the byte will be read- Returns:
- the byte at the given byte offset from the start of the buffer
- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length
- Since:
- 20.3
-
getByte
Reads the byte at the given byte offset from the start of the buffer.- Parameters:
buffer
- the byte array to read frombyteOffset
- the byte offset at which the byte will be read- Returns:
- the byte at the given byte offset from the start of the buffer
- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length
- Since:
- 22.2
-
putByte
public abstract void putByte(byte[] buffer, int byteOffset, byte value) throws IndexOutOfBoundsException Writes the given byte at the given byte offset from the start of the buffer.- Parameters:
buffer
- the byte array to write inbyteOffset
- the byte offset at which the byte will be writtenvalue
- the byte value to be written- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length
- Since:
- 20.3
-
putByte
public abstract void putByte(byte[] buffer, long byteOffset, byte value) throws IndexOutOfBoundsException Writes the given byte at the given byte offset from the start of the buffer.- Parameters:
buffer
- the byte array to write inbyteOffset
- the byte offset at which the byte will be writtenvalue
- the byte value to be written- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length
- Since:
- 22.2
-
getShort
Reads the short at the given byte offset from the start of the buffer.- Parameters:
buffer
- the byte array to read frombyteOffset
- the byte offset from which the short will be read- Returns:
- the short at the given byte offset from the start of the buffer
- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length - 1
- Since:
- 20.3
-
getShort
Reads the short at the given byte offset from the start of the buffer.- Parameters:
buffer
- the byte array to read frombyteOffset
- the byte offset from which the short will be read- Returns:
- the short at the given byte offset from the start of the buffer
- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length - 1
- Since:
- 22.2
-
putShort
public abstract void putShort(byte[] buffer, int byteOffset, short value) throws IndexOutOfBoundsException Writes the given short at the given byte offset from the start of the buffer.- Parameters:
buffer
- the byte array to write inbyteOffset
- the byte offset from which the short will be writtenvalue
- the short value to be written- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length - 1
- Since:
- 20.3
-
putShort
public abstract void putShort(byte[] buffer, long byteOffset, short value) throws IndexOutOfBoundsException Writes the given short at the given byte offset from the start of the buffer.- Parameters:
buffer
- the byte array to write inbyteOffset
- the byte offset from which the short will be writtenvalue
- the short value to be written- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length - 1
- Since:
- 22.2
-
getInt
Reads the int at the given byte offset from the start of the buffer.- Parameters:
buffer
- the byte array to read frombyteOffset
- the byte offset from which the int will be read- Returns:
- the int at the given byte offset from the start of the buffer
- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length - 3
- Since:
- 20.3
-
getInt
Reads the int at the given byte offset from the start of the buffer.- Parameters:
buffer
- the byte array to read frombyteOffset
- the byte offset from which the int will be read- Returns:
- the int at the given byte offset from the start of the buffer
- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length - 3
- Since:
- 20.3
-
putInt
public abstract void putInt(byte[] buffer, int byteOffset, int value) throws IndexOutOfBoundsException Writes the given int at the given byte offset from the start of the buffer.- Parameters:
buffer
- the byte array to write inbyteOffset
- the byte offset from which the int will be writtenvalue
- the int value to be written- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length - 3
- Since:
- 20.3
-
putInt
public abstract void putInt(byte[] buffer, long byteOffset, int value) throws IndexOutOfBoundsException Writes the given int at the given byte offset from the start of the buffer.- Parameters:
buffer
- the byte array to write inbyteOffset
- the byte offset from which the int will be writtenvalue
- the int value to be written- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length - 3
- Since:
- 22.2
-
getLong
Reads the long at the given byte offset from the start of the buffer.- Parameters:
buffer
- the byte array to read frombyteOffset
- the byte offset from which the int will be read- Returns:
- the int at the given byte offset from the start of the buffer
- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length - 7
- Since:
- 20.3
-
getLong
Reads the long at the given byte offset from the start of the buffer.- Parameters:
buffer
- the byte array to read frombyteOffset
- the byte offset from which the int will be read- Returns:
- the int at the given byte offset from the start of the buffer
- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length - 7
- Since:
- 22.2
-
putLong
public abstract void putLong(byte[] buffer, int byteOffset, long value) throws IndexOutOfBoundsException Writes the given long at the given byte offset from the start of the buffer.- Parameters:
buffer
- the byte array to write inbyteOffset
- the byte offset from which the int will be writtenvalue
- the int value to be written- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length - 7
- Since:
- 20.3
-
putLong
public abstract void putLong(byte[] buffer, long byteOffset, long value) throws IndexOutOfBoundsException Writes the given long at the given byte offset from the start of the buffer.- Parameters:
buffer
- the byte array to write inbyteOffset
- the byte offset from which the int will be writtenvalue
- the int value to be written- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length - 7
- Since:
- 22.2
-
getFloat
Reads the float at the given byte offset from the start of the buffer.- Parameters:
buffer
- the byte array to read frombyteOffset
- the byte offset from which the float will be read- Returns:
- the float at the given byte offset from the start of the buffer
- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length - 3
- Since:
- 20.3
-
getFloat
Reads the float at the given byte offset from the start of the buffer.- Parameters:
buffer
- the byte array to read frombyteOffset
- the byte offset from which the float will be read- Returns:
- the float at the given byte offset from the start of the buffer
- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length - 3
- Since:
- 22.2
-
putFloat
public abstract void putFloat(byte[] buffer, int byteOffset, float value) throws IndexOutOfBoundsException Writes the given float at the given byte offset from the start of the buffer.- Parameters:
buffer
- the byte array to write inbyteOffset
- the byte offset from which the float will be writtenvalue
- the float value to be written- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length - 3
- Since:
- 20.3
-
putFloat
public abstract void putFloat(byte[] buffer, long byteOffset, float value) throws IndexOutOfBoundsException Writes the given float at the given byte offset from the start of the buffer.- Parameters:
buffer
- the byte array to write inbyteOffset
- the byte offset from which the float will be writtenvalue
- the float value to be written- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length - 3
- Since:
- 22.2
-
getDouble
Reads the double at the given byte offset from the start of the buffer.- Parameters:
buffer
- the byte array to read frombyteOffset
- the byte offset from which the double will be read- Returns:
- the double at the given byte offset from the start of the buffer
- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length - 7
- Since:
- 20.3
-
getDouble
Reads the double at the given byte offset from the start of the buffer.- Parameters:
buffer
- the byte array to read frombyteOffset
- the byte offset from which the double will be read- Returns:
- the double at the given byte offset from the start of the buffer
- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length - 7
- Since:
- 22.2
-
putDouble
public abstract void putDouble(byte[] buffer, int byteOffset, double value) throws IndexOutOfBoundsException Writes the given double at the given byte offset from the start of the buffer.- Parameters:
buffer
- the byte array to write inbyteOffset
- the byte offset from which the double will be writtenvalue
- the double value to be written- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length - 7
- Since:
- 20.3
-
putDouble
public abstract void putDouble(byte[] buffer, long byteOffset, double value) throws IndexOutOfBoundsException Writes the given double at the given byte offset from the start of the buffer.- Parameters:
buffer
- the byte array to write inbyteOffset
- the byte offset from which the double will be writtenvalue
- the double value to be written- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length - 7
- Since:
- 22.2
-
getShortUnaligned
public abstract short getShortUnaligned(byte[] buffer, int byteOffset) throws IndexOutOfBoundsException Reads the short at the given byte offset from the start of the buffer. UnlikegetShort(byte[], int)
, the byte offset does not need to be short-aligned. The platform may not support atomic unaligned reads, so this method should not be used with shared mutable data.- Parameters:
buffer
- the byte array to read frombyteOffset
- the byte offset from which the short will be read- Returns:
- the short at the given byte offset from the start of the buffer
- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length - 1
- Since:
- 24.2
-
getShortUnaligned
public abstract short getShortUnaligned(byte[] buffer, long byteOffset) throws IndexOutOfBoundsException Reads the short at the given byte offset from the start of the buffer. UnlikegetShort(byte[], long)
, the byte offset does not need to be short-aligned. The platform may not support atomic unaligned reads, so this method should not be used with shared mutable data.- Parameters:
buffer
- the byte array to read frombyteOffset
- the byte offset from which the short will be read- Returns:
- the short at the given byte offset from the start of the buffer
- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length - 1
- Since:
- 24.2
-
getIntUnaligned
Reads the int at the given byte offset from the start of the buffer. UnlikegetInt(byte[], int)
, the byte offset does not need to be int-aligned. The platform may not support atomic unaligned reads, so this method should not be used with shared mutable data.- Parameters:
buffer
- the byte array to read frombyteOffset
- the byte offset from which the int will be read- Returns:
- the int at the given byte offset from the start of the buffer
- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length - 3
- Since:
- 24.2
-
getIntUnaligned
public abstract int getIntUnaligned(byte[] buffer, long byteOffset) throws IndexOutOfBoundsException Reads the int at the given byte offset from the start of the buffer. UnlikegetInt(byte[], long)
, the byte offset does not need to be int-aligned. The platform may not support atomic unaligned reads, so this method should not be used with shared mutable data.- Parameters:
buffer
- the byte array to read frombyteOffset
- the byte offset from which the int will be read- Returns:
- the int at the given byte offset from the start of the buffer
- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length - 3
- Since:
- 24.2
-
getLongUnaligned
public abstract long getLongUnaligned(byte[] buffer, int byteOffset) throws IndexOutOfBoundsException Reads the long at the given byte offset from the start of the buffer. UnlikegetLong(byte[], int)
, the byte offset does not need to be long-aligned. The platform may not support atomic unaligned reads, so this method should not be used with shared mutable data.- Parameters:
buffer
- the byte array to read frombyteOffset
- the byte offset from which the long will be read- Returns:
- the long at the given byte offset from the start of the buffer
- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length - 7
- Since:
- 24.2
-
getLongUnaligned
public abstract long getLongUnaligned(byte[] buffer, long byteOffset) throws IndexOutOfBoundsException Reads the long at the given byte offset from the start of the buffer. UnlikegetLong(byte[], long)
, the byte offset does not need to be long-aligned. The platform may not support atomic unaligned reads, so this method should not be used with shared mutable data.- Parameters:
buffer
- the byte array to read frombyteOffset
- the byte offset from which the long will be read- Returns:
- the long at the given byte offset from the start of the buffer
- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length - 7
- Since:
- 24.2
-
getByteVolatile
public abstract byte getByteVolatile(byte[] buffer, long byteOffset) throws IndexOutOfBoundsException Volatile version ofgetByte(byte[], long)
.- Throws:
IndexOutOfBoundsException
- Since:
- 23.1
-
putByteVolatile
public abstract void putByteVolatile(byte[] buffer, long byteOffset, byte value) throws IndexOutOfBoundsException Volatile version ofputByte(byte[], long, byte)
.- Throws:
IndexOutOfBoundsException
- Since:
- 23.1
-
getShortVolatile
public abstract short getShortVolatile(byte[] buffer, long byteOffset) throws IndexOutOfBoundsException Volatile version ofgetShort(byte[], long)
.- Throws:
IndexOutOfBoundsException
- Since:
- 23.1
-
putShortVolatile
public abstract void putShortVolatile(byte[] buffer, long byteOffset, short value) throws IndexOutOfBoundsException Volatile version ofputShort(byte[], long, short)
.- Throws:
IndexOutOfBoundsException
- Since:
- 23.1
-
getIntVolatile
Volatile version ofgetInt(byte[], long)
.- Throws:
IndexOutOfBoundsException
- Since:
- 23.1
-
putIntVolatile
public abstract void putIntVolatile(byte[] buffer, long byteOffset, int value) throws IndexOutOfBoundsException Volatile version ofputInt(byte[], long, int)
.- Throws:
IndexOutOfBoundsException
- Since:
- 23.1
-
getLongVolatile
public abstract long getLongVolatile(byte[] buffer, long byteOffset) throws IndexOutOfBoundsException Volatile version ofgetLong(byte[], long)
.- Throws:
IndexOutOfBoundsException
- Since:
- 23.1
-
putLongVolatile
public abstract void putLongVolatile(byte[] buffer, long byteOffset, long value) throws IndexOutOfBoundsException Volatile version ofputLong(byte[], long, long)
.- Throws:
IndexOutOfBoundsException
- Since:
- 23.1
-
getAndAddByte
public abstract byte getAndAddByte(byte[] buffer, long byteOffset, byte delta) throws IndexOutOfBoundsException Atomically adds the given byte to the current byte at the given byte offset from the start of the buffer.- Parameters:
buffer
- the byte array to read frombyteOffset
- the byte offset at which the byte will be read and written todelta
- the byte value to add- Returns:
- the previous byte at the given byte offset from the start of the buffer
- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length
- Since:
- 23.1
-
getAndAddShort
public abstract short getAndAddShort(byte[] buffer, long byteOffset, short delta) throws IndexOutOfBoundsException Atomically adds the given short to the current short at the given byte offset from the start of the buffer.- Parameters:
buffer
- the byte array to read frombyteOffset
- the byte offset at which the short will be read and written todelta
- the short value to add- Returns:
- the previous short at the given byte offset from the start of the buffer
- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length - 1
- Since:
- 23.1
-
getAndAddInt
public abstract int getAndAddInt(byte[] buffer, long byteOffset, int delta) throws IndexOutOfBoundsException Atomically adds the given int to the current int at the given byte offset from the start of the buffer.- Parameters:
buffer
- the byte array to read frombyteOffset
- the byte offset at which the int will be read and written todelta
- the int value to add- Returns:
- the previous int at the given byte offset from the start of the buffer
- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length - 3
- Since:
- 23.1
-
getAndAddLong
public abstract long getAndAddLong(byte[] buffer, long byteOffset, long delta) throws IndexOutOfBoundsException Atomically adds the given long to the current long at the given byte offset from the start of the buffer.- Parameters:
buffer
- the byte array to read frombyteOffset
- the byte offset at which the long will be read and written todelta
- the long value to add- Returns:
- the previous long at the given byte offset from the start of the buffer
- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length - 7
- Since:
- 23.1
-
getAndBitwiseAndByte
public abstract byte getAndBitwiseAndByte(byte[] buffer, long byteOffset, byte mask) throws IndexOutOfBoundsException Atomically bitwise-ANDs the given byte to the current byte at the given byte offset from the start of the buffer.- Parameters:
buffer
- the byte array to read frombyteOffset
- the byte offset at which the byte will be read and written tomask
- the byte value to bitwise-AND- Returns:
- the previous byte at the given byte offset from the start of the buffer
- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length
- Since:
- 23.1
-
getAndBitwiseAndShort
public abstract short getAndBitwiseAndShort(byte[] buffer, long byteOffset, short mask) throws IndexOutOfBoundsException Atomically bitwise-ANDs the given short to the current short at the given byte offset from the start of the buffer.- Parameters:
buffer
- the byte array to read frombyteOffset
- the byte offset at which the short will be read and written tomask
- the short value to bitwise-AND- Returns:
- the previous short at the given byte offset from the start of the buffer
- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length - 1
- Since:
- 23.1
-
getAndBitwiseAndInt
public abstract int getAndBitwiseAndInt(byte[] buffer, long byteOffset, int mask) throws IndexOutOfBoundsException Atomically bitwise-ANDs the given int to the current int at the given byte offset from the start of the buffer.- Parameters:
buffer
- the byte array to read frombyteOffset
- the byte offset at which the int will be read and written tomask
- the int value to bitwise-AND- Returns:
- the previous int at the given byte offset from the start of the buffer
- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length - 3
- Since:
- 23.1
-
getAndBitwiseAndLong
public abstract long getAndBitwiseAndLong(byte[] buffer, long byteOffset, long mask) throws IndexOutOfBoundsException Atomically bitwise-ANDs the given long to the current long at the given byte offset from the start of the buffer.- Parameters:
buffer
- the byte array to read frombyteOffset
- the byte offset at which the long will be read and written tomask
- the long value to bitwise-AND- Returns:
- the previous long at the given byte offset from the start of the buffer
- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length - 7
- Since:
- 23.1
-
getAndBitwiseOrByte
public abstract byte getAndBitwiseOrByte(byte[] buffer, long byteOffset, byte mask) throws IndexOutOfBoundsException Atomically bitwise-ORs the given byte to the current byte at the given byte offset from the start of the buffer.- Parameters:
buffer
- the byte array to read frombyteOffset
- the byte offset at which the byte will be read and written tomask
- the byte value to bitwise-OR- Returns:
- the previous byte at the given byte offset from the start of the buffer
- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length
- Since:
- 23.1
-
getAndBitwiseOrShort
public abstract short getAndBitwiseOrShort(byte[] buffer, long byteOffset, short mask) throws IndexOutOfBoundsException Atomically bitwise-ORs the given short to the current short at the given byte offset from the start of the buffer.- Parameters:
buffer
- the byte array to read frombyteOffset
- the byte offset at which the short will be read and written tomask
- the short value to bitwise-OR- Returns:
- the previous short at the given byte offset from the start of the buffer
- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length - 1
- Since:
- 23.1
-
getAndBitwiseOrInt
public abstract int getAndBitwiseOrInt(byte[] buffer, long byteOffset, int mask) throws IndexOutOfBoundsException Atomically bitwise-ORs the given int to the current int at the given byte offset from the start of the buffer.- Parameters:
buffer
- the byte array to read frombyteOffset
- the byte offset at which the int will be read and written tomask
- the int value to bitwise-OR- Returns:
- the previous int at the given byte offset from the start of the buffer
- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length - 3
- Since:
- 23.1
-
getAndBitwiseOrLong
public abstract long getAndBitwiseOrLong(byte[] buffer, long byteOffset, long mask) throws IndexOutOfBoundsException Atomically bitwise-ORs the given long to the current long at the given byte offset from the start of the buffer.- Parameters:
buffer
- the byte array to read frombyteOffset
- the byte offset at which the long will be read and written tomask
- the long value to bitwise-OR- Returns:
- the previous long at the given byte offset from the start of the buffer
- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length - 7
- Since:
- 23.1
-
getAndBitwiseXorByte
public abstract byte getAndBitwiseXorByte(byte[] buffer, long byteOffset, byte mask) throws IndexOutOfBoundsException Atomically bitwise-XORs the given byte to the current byte at the given byte offset from the start of the buffer.- Parameters:
buffer
- the byte array to read frombyteOffset
- the byte offset at which the byte will be read and written tomask
- the byte value to bitwise-XOR- Returns:
- the previous byte at the given byte offset from the start of the buffer
- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length
- Since:
- 23.1
-
getAndBitwiseXorShort
public abstract short getAndBitwiseXorShort(byte[] buffer, long byteOffset, short mask) throws IndexOutOfBoundsException Atomically bitwise-XORs the given short to the current short at the given byte offset from the start of the buffer.- Parameters:
buffer
- the byte array to read frombyteOffset
- the byte offset at which the short will be read and written tomask
- the short value to bitwise-XOR- Returns:
- the previous short at the given byte offset from the start of the buffer
- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length - 1
- Since:
- 23.1
-
getAndBitwiseXorInt
public abstract int getAndBitwiseXorInt(byte[] buffer, long byteOffset, int mask) throws IndexOutOfBoundsException Atomically bitwise-XORs the given int to the current int at the given byte offset from the start of the buffer.- Parameters:
buffer
- the byte array to read frombyteOffset
- the byte offset at which the int will be read and written tomask
- the int value to bitwise-XOR- Returns:
- the previous int at the given byte offset from the start of the buffer
- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length - 3
- Since:
- 23.1
-
getAndBitwiseXorLong
public abstract long getAndBitwiseXorLong(byte[] buffer, long byteOffset, long mask) throws IndexOutOfBoundsException Atomically bitwise-XORs the given long to the current long at the given byte offset from the start of the buffer.- Parameters:
buffer
- the byte array to read frombyteOffset
- the byte offset at which the long will be read and written tomask
- the long value to bitwise-XOR- Returns:
- the previous long at the given byte offset from the start of the buffer
- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length - 7
- Since:
- 23.1
-
getAndSetByte
public abstract byte getAndSetByte(byte[] buffer, long byteOffset, byte newValue) throws IndexOutOfBoundsException Atomically exchanges the given byte with the current byte at the given byte offset from the start of the buffer.- Parameters:
buffer
- the byte array to read frombyteOffset
- the byte offset at which the byte will be read and written tonewValue
- the new byte value- Returns:
- the previous byte at the given byte offset from the start of the buffer
- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length
- Since:
- 23.1
-
getAndSetShort
public abstract short getAndSetShort(byte[] buffer, long byteOffset, short newValue) throws IndexOutOfBoundsException Atomically exchanges the given short with the current short at the given byte offset from the start of the buffer.- Parameters:
buffer
- the byte array to read frombyteOffset
- the byte offset at which the short will be read and written tonewValue
- the new short value- Returns:
- the previous short at the given byte offset from the start of the buffer
- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length - 1
- Since:
- 23.1
-
getAndSetInt
public abstract int getAndSetInt(byte[] buffer, long byteOffset, int newValue) throws IndexOutOfBoundsException Atomically exchanges the given int with the current int at the given byte offset from the start of the buffer.- Parameters:
buffer
- the byte array to read frombyteOffset
- the byte offset at which the int will be read and written tonewValue
- the new int value- Returns:
- the previous int at the given byte offset from the start of the buffer
- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length - 3
- Since:
- 23.1
-
getAndSetLong
public abstract long getAndSetLong(byte[] buffer, long byteOffset, long newValue) throws IndexOutOfBoundsException Atomically exchanges the given long with the current long at the given byte offset from the start of the buffer.- Parameters:
buffer
- the byte array to read frombyteOffset
- the byte offset at which the long will be read and written tonewValue
- the new long value- Returns:
- the previous long at the given byte offset from the start of the buffer
- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length - 7
- Since:
- 23.1
-
compareAndExchangeByte
public abstract byte compareAndExchangeByte(byte[] buffer, long byteOffset, byte expected, byte x) throws IndexOutOfBoundsException Atomically exchanges the given byte with the current byte at the given byte offset from the start of the buffer, if and only if the current byte equals the expected byte.- Parameters:
buffer
- the byte array to read frombyteOffset
- the byte offset at which the byte will be read and written toexpected
- the expected byte valuex
- the replacement byte value- Returns:
- the previous byte at the given byte offset from the start of the buffer
- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length
- Since:
- 23.1
-
compareAndExchangeShort
public abstract short compareAndExchangeShort(byte[] buffer, long byteOffset, short expected, short x) throws IndexOutOfBoundsException Atomically exchanges the given short with the current short at the given byte offset from the start of the buffer, if and only if the current short equals the expected short.- Parameters:
buffer
- the byte array to read frombyteOffset
- the byte offset at which the short will be read and written toexpected
- the expected short valuex
- the replacement short value- Returns:
- the previous short at the given byte offset from the start of the buffer
- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length - 1
- Since:
- 23.1
-
compareAndExchangeInt
public abstract int compareAndExchangeInt(byte[] buffer, long byteOffset, int expected, int x) throws IndexOutOfBoundsException Atomically exchanges the given int with the current int at the given byte offset from the start of the buffer, if and only if the current int equals the expected int.- Parameters:
buffer
- the byte array to read frombyteOffset
- the byte offset at which the int will be read and written toexpected
- the expected int valuex
- the replacement int value- Returns:
- the previous int at the given byte offset from the start of the buffer
- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length - 3
- Since:
- 23.1
-
compareAndExchangeLong
public abstract long compareAndExchangeLong(byte[] buffer, long byteOffset, long expected, long x) throws IndexOutOfBoundsException Atomically exchanges the given long with the current long at the given byte offset from the start of the buffer, if and only if the current long equals the expected long.- Parameters:
buffer
- the byte array to read frombyteOffset
- the byte offset at which the long will be read and written toexpected
- the expected long valuex
- the replacement long value- Returns:
- the previous long at the given byte offset from the start of the buffer
- Throws:
IndexOutOfBoundsException
- if and only ifbyteOffset < 0 || byteOffset >= buffer.length - 7
- Since:
- 23.1
-