Package org.apache.qpid.protonj2.buffer
Class ProtonByteUtils
- java.lang.Object
-
- org.apache.qpid.protonj2.buffer.ProtonByteUtils
-
public abstract class ProtonByteUtils extends Object
Set of Utility methods useful when dealing with byte arrays and other primitive types.
-
-
Constructor Summary
Constructors Constructor Description ProtonByteUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte
readByte(byte[] array, int offset)
Reads a single byte from the given array from the provided offset.static int
readInt(byte[] array, int offset)
Reads a four byte integer from the given array from the provided offset.static long
readLong(byte[] array, int offset)
Reads an eight byte integer from the given array from the provided offset.static short
readShort(byte[] array, int offset)
Reads a two byte short from the given array from the provided offset.static byte[]
toByteArray(byte value)
Given a byte value returns an array containing the given byte as the only entry.static byte[]
toByteArray(int value)
Given an integer value returns an array containing the given byte as the only entry.static byte[]
toByteArray(long value)
Given a long value returns an array containing the given byte as the only entry.static byte[]
toByteArray(short value)
Given a short value returns an array containing the given byte as the only entry.static byte[]
writeByte(byte value, byte[] destination, int offset)
Writes the value given into the provided array at the specified offset returning to destination once done.static byte[]
writeInt(int value, byte[] destination, int offset)
Writes the value given into the provided array at the specified offset returning to destination once done.static byte[]
writeLong(long value, byte[] destination, int offset)
Writes the value given into the provided array at the specified offset returning to destination once done.static byte[]
writeShort(short value, byte[] destination, int offset)
Writes the value given into the provided array at the specified offset returning to destination once done.
-
-
-
Method Detail
-
toByteArray
public static byte[] toByteArray(byte value)
Given a byte value returns an array containing the given byte as the only entry.- Parameters:
value
- The value to wrap in an array instance.- Returns:
- a new array containing the primitive value as the only array element.
-
toByteArray
public static byte[] toByteArray(short value)
Given a short value returns an array containing the given byte as the only entry.- Parameters:
value
- The value to wrap in an array instance.- Returns:
- a new array containing the primitive value as the only array element.
-
toByteArray
public static byte[] toByteArray(int value)
Given an integer value returns an array containing the given byte as the only entry.- Parameters:
value
- The value to wrap in an array instance.- Returns:
- a new array containing the primitive value as the only array element.
-
toByteArray
public static byte[] toByteArray(long value)
Given a long value returns an array containing the given byte as the only entry.- Parameters:
value
- The value to wrap in an array instance.- Returns:
- a new array containing the primitive value as the only array element.
-
writeByte
public static byte[] writeByte(byte value, byte[] destination, int offset)
Writes the value given into the provided array at the specified offset returning to destination once done.- Parameters:
value
- The value to be encoded into the given arraydestination
- The given array where the provided value should be written.offset
- The offset into the array to start writing.- Returns:
- the provided destination array.
-
writeShort
public static byte[] writeShort(short value, byte[] destination, int offset)
Writes the value given into the provided array at the specified offset returning to destination once done. The provided array must have enough space starting from the given offset for the value to be encoded or an exception will be thrown.- Parameters:
value
- The value to be encoded into the given arraydestination
- The given array where the provided value should be written.offset
- The offset into the array to start writing.- Returns:
- the provided destination array.
-
writeInt
public static byte[] writeInt(int value, byte[] destination, int offset)
Writes the value given into the provided array at the specified offset returning to destination once done. The provided array must have enough space starting from the given offset for the value to be encoded or an exception will be thrown.- Parameters:
value
- The value to be encoded into the given arraydestination
- The given array where the provided value should be written.offset
- The offset into the array to start writing.- Returns:
- the provided destination array.
-
writeLong
public static byte[] writeLong(long value, byte[] destination, int offset)
Writes the value given into the provided array at the specified offset returning to destination once done. The provided array must have enough space starting from the given offset for the value to be encoded or an exception will be thrown.- Parameters:
value
- The value to be encoded into the given arraydestination
- The given array where the provided value should be written.offset
- The offset into the array to start writing.- Returns:
- the provided destination array.
-
readByte
public static byte readByte(byte[] array, int offset)
Reads a single byte from the given array from the provided offset.- Parameters:
array
- The array to be read fromoffset
- The offset into the array to start reading from.- Returns:
- the resulting value read from the array at the provided array offset.
-
readShort
public static short readShort(byte[] array, int offset)
Reads a two byte short from the given array from the provided offset.- Parameters:
array
- The array to be read fromoffset
- The offset into the array to start reading from.- Returns:
- the resulting value read from the array at the provided array offset.
-
readInt
public static int readInt(byte[] array, int offset)
Reads a four byte integer from the given array from the provided offset.- Parameters:
array
- The array to be read fromoffset
- The offset into the array to start reading from.- Returns:
- the resulting value read from the array at the provided array offset.
-
readLong
public static long readLong(byte[] array, int offset)
Reads an eight byte integer from the given array from the provided offset.- Parameters:
array
- The array to be read fromoffset
- The offset into the array to start reading from.- Returns:
- the resulting value read from the array at the provided array offset.
-
-