public class ByteUtilities extends Object
Note: unless explicitly specified otherwise, the methods in this class assume big-endian (network) byte order (most significant bit first).
Modifier and Type | Method and Description |
---|---|
static long |
bytesToLong(byte[] buffer,
int offset,
int length)
Returns the long value of a sequence of bytes in a byte array.
|
static int |
getPackedLength(byte[][] array)
Returns the length of the array that would result if the given source
two-dimensional array was packed into a one-dimensional byte array.
|
static void |
main(String[] args)
Tests this class.
|
static void |
mergeByteArrays(byte[][] src,
byte[] dst,
int offset)
Merges a two-dimensional byte array into a destination array.
|
static byte[] |
readFromStream(InputStream in)
Creates a new byte array by reading from an InputStream.
|
static byte[] |
readFromStream(InputStream in,
int length)
Creates a new byte array of a given length by reading from an InputStream.
|
static void |
setBytes(long value,
byte[] buffer,
int offset,
int length)
Sets the value of a sequence of bytes in a byte array.
|
public static void main(String[] args)
public static long bytesToLong(byte[] buffer, int offset, int length)
buffer
- the byte array to convert to a long value.offset
- the offset of the value in the byte array.length
- the length (in bytes) of the value.public static void setBytes(long value, byte[] buffer, int offset, int length)
value
- the value to set.buffer
- the byte array to modify.offset
- the offset in the byte array (the first byte to modify).length
- the length (in bytes) of the value.public static void mergeByteArrays(byte[][] src, byte[] dst, int offset)
src
- the source two-dimensional byte array.dst
- the destination byte array.offset
- the offset into the destination array where the new array
will be copied.public static int getPackedLength(byte[][] array)
SUM(array[i].legnth), i = 0..array.length
public static byte[] readFromStream(InputStream in, int length) throws IOException
length
bytes have been read,
until the end of stream is reached, or an error occurs.length
, or null if the
end of stream was reached before the length
bytes
were able to be read.IOException
- if an error occurs while reading from the stream.public static byte[] readFromStream(InputStream in) throws IOException
in
- the InputStreamIOException
- if an error occurs while reading from the stream.Copyright © 2023. All rights reserved.