public final class BufferUtils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.util.function.IntUnaryOperator |
DEFAULT_BUFFER_GROWTH_FACTOR |
static char |
DEFAULT_HEX_SEPARATOR |
static int |
DEFAULT_HEXDUMP_CHUNK_SIZE |
static java.util.logging.Level |
DEFAULT_HEXDUMP_LEVEL |
static char |
EMPTY_HEX_SEPARATOR |
static java.lang.String |
HEX_DIGITS |
static java.lang.String |
HEXDUMP_CHUNK_SIZE |
static long |
MAX_UINT32_VALUE
Maximum value of a
uint32 field |
static int |
MAX_UINT8_VALUE
Maximum value of a
uint8 field |
Modifier | Constructor and Description |
---|---|
private |
BufferUtils()
Private Constructor
|
Modifier and Type | Method and Description |
---|---|
static <A extends java.lang.Appendable> |
appendHex(A sb,
byte[] array,
int offset,
int len,
char sep) |
static <A extends java.lang.Appendable> |
appendHex(A sb,
char sep,
byte... array) |
static <B extends Buffer> |
clear(B buffer)
Invokes
Buffer.clear() |
static byte[] |
decodeHex(char separator,
java.lang.CharSequence csq) |
static byte[] |
decodeHex(char separator,
java.lang.CharSequence csq,
int start,
int end) |
static <S extends java.io.OutputStream> |
decodeHex(S stream,
char separator,
java.lang.CharSequence csq) |
static <S extends java.io.OutputStream> |
decodeHex(S stream,
char separator,
java.lang.CharSequence csq,
int start,
int end) |
static void |
dumpHex(SimplifiedLog logger,
java.util.logging.Level level,
java.lang.String prefix,
char sep,
int chunkSize,
byte... data) |
static void |
dumpHex(SimplifiedLog logger,
java.util.logging.Level level,
java.lang.String prefix,
char sep,
int chunkSize,
byte[] data,
int offset,
int len) |
static void |
dumpHex(SimplifiedLog logger,
java.util.logging.Level level,
java.lang.String prefix,
PropertyResolver resolver,
char sep,
byte... data) |
static void |
dumpHex(SimplifiedLog logger,
java.util.logging.Level level,
java.lang.String prefix,
PropertyResolver resolver,
char sep,
byte[] data,
int offset,
int len) |
static boolean |
equals(byte[] a1,
byte[] a2) |
static boolean |
equals(byte[] a1,
int a1Offset,
byte[] a2,
int a2Offset,
int length) |
static byte |
fromHex(char hi,
char lo) |
static int |
getNextPowerOf2(int value) |
static long |
getUInt(byte... buf) |
static long |
getUInt(byte[] buf,
int off,
int len) |
static boolean |
isValidInt32Value(long value) |
static boolean |
isValidUint32Value(long value) |
static int |
putUInt(long value,
byte[] buf)
Writes a 32-bit value in network order (i.e., MSB 1st)
|
static int |
putUInt(long value,
byte[] buf,
int off,
int len)
Writes a 32-bit value in network order (i.e., MSB 1st)
|
static int |
readInt(java.io.InputStream input,
byte[] buf)
Read a 32-bit value in network order
|
static int |
readInt(java.io.InputStream input,
byte[] buf,
int offset,
int len)
Read a 32-bit value in network order
|
static long |
readUInt(java.io.InputStream input,
byte[] buf)
Read a 32-bit value in network order
|
static long |
readUInt(java.io.InputStream input,
byte[] buf,
int offset,
int len)
Read a 32-bit value in network order
|
static java.lang.String |
toHex(byte... array) |
static java.lang.String |
toHex(byte[] array,
int offset,
int len) |
static java.lang.String |
toHex(byte[] array,
int offset,
int len,
char sep) |
static java.lang.String |
toHex(char sep,
byte... array) |
static int |
updateLengthPlaceholder(Buffer buffer,
int lenPos)
Used for encodings where we don't know the data length before adding it to the buffer.
|
static void |
updateLengthPlaceholder(Buffer buffer,
int lenPos,
int dataLength)
Updates a 32-bit "placeholder" location for data length - moves the write position to the specified
placeholder position, updates the length value and then moves the write position it back to its original value.
|
static long |
validateInt32Value(long value,
java.lang.String message) |
static long |
validateInt32Value(long value,
java.lang.String format,
java.lang.Object... args) |
static long |
validateInt32Value(long value,
java.lang.String format,
java.lang.Object arg) |
static long |
validateUint32Value(long value,
java.lang.String message) |
static long |
validateUint32Value(long value,
java.lang.String format,
java.lang.Object... args) |
static long |
validateUint32Value(long value,
java.lang.String format,
java.lang.Object arg) |
static void |
writeInt(java.io.OutputStream output,
int value,
byte[] buf)
Writes a 32-bit value in network order (i.e., MSB 1st)
|
static void |
writeInt(java.io.OutputStream output,
int value,
byte[] buf,
int off,
int len)
Writes a 32-bit value in network order (i.e., MSB 1st)
|
static void |
writeUInt(java.io.OutputStream output,
long value,
byte[] buf)
Writes a 32-bit value in network order (i.e., MSB 1st)
|
static void |
writeUInt(java.io.OutputStream output,
long value,
byte[] buf,
int off,
int len)
Writes a 32-bit value in network order (i.e., MSB 1st)
|
public static final char DEFAULT_HEX_SEPARATOR
public static final char EMPTY_HEX_SEPARATOR
public static final java.lang.String HEX_DIGITS
public static final java.lang.String HEXDUMP_CHUNK_SIZE
public static final int DEFAULT_HEXDUMP_CHUNK_SIZE
public static final java.util.logging.Level DEFAULT_HEXDUMP_LEVEL
public static final java.util.function.IntUnaryOperator DEFAULT_BUFFER_GROWTH_FACTOR
public static final long MAX_UINT32_VALUE
uint32
fieldpublic static final int MAX_UINT8_VALUE
uint8
fieldpublic static void dumpHex(SimplifiedLog logger, java.util.logging.Level level, java.lang.String prefix, PropertyResolver resolver, char sep, byte... data)
public static void dumpHex(SimplifiedLog logger, java.util.logging.Level level, java.lang.String prefix, PropertyResolver resolver, char sep, byte[] data, int offset, int len)
public static void dumpHex(SimplifiedLog logger, java.util.logging.Level level, java.lang.String prefix, char sep, int chunkSize, byte... data)
public static void dumpHex(SimplifiedLog logger, java.util.logging.Level level, java.lang.String prefix, char sep, int chunkSize, byte[] data, int offset, int len)
public static java.lang.String toHex(byte... array)
public static java.lang.String toHex(char sep, byte... array)
public static java.lang.String toHex(byte[] array, int offset, int len)
public static java.lang.String toHex(byte[] array, int offset, int len, char sep)
public static <A extends java.lang.Appendable> A appendHex(A sb, char sep, byte... array) throws java.io.IOException
java.io.IOException
public static <A extends java.lang.Appendable> A appendHex(A sb, byte[] array, int offset, int len, char sep) throws java.io.IOException
java.io.IOException
public static byte[] decodeHex(char separator, java.lang.CharSequence csq)
separator
- The separator between the HEX values - may be EMPTY_HEX_SEPARATOR
csq
- The CharSequence
containing the HEX encoded bytesjava.lang.IllegalArgumentException
- If invalid HEX sequence lengthjava.lang.NumberFormatException
- If invalid HEX characters founddecodeHex(char, CharSequence, int, int)
public static byte[] decodeHex(char separator, java.lang.CharSequence csq, int start, int end)
separator
- The separator between the HEX values - may be EMPTY_HEX_SEPARATOR
csq
- The CharSequence
containing the HEX encoded bytesstart
- Start offset of the HEX sequence (inclusive)end
- End offset of the HEX sequence (exclusive)java.lang.IllegalArgumentException
- If invalid HEX sequence lengthjava.lang.NumberFormatException
- If invalid HEX characters foundpublic static <S extends java.io.OutputStream> int decodeHex(S stream, char separator, java.lang.CharSequence csq) throws java.io.IOException
S
- The OutputStream
generic typestream
- The target OutputStream
separator
- The separator between the HEX values - may be EMPTY_HEX_SEPARATOR
csq
- The CharSequence
containing the HEX encoded bytesjava.io.IOException
- If failed to writejava.lang.IllegalArgumentException
- If invalid HEX sequence lengthjava.lang.NumberFormatException
- If invalid HEX characters founddecodeHex(OutputStream, char, CharSequence, int, int)
public static <S extends java.io.OutputStream> int decodeHex(S stream, char separator, java.lang.CharSequence csq, int start, int end) throws java.io.IOException
S
- The OutputStream
generic typestream
- The target OutputStream
separator
- The separator between the HEX values - may be EMPTY_HEX_SEPARATOR
csq
- The CharSequence
containing the HEX encoded bytesstart
- Start offset of the HEX sequence (inclusive)end
- End offset of the HEX sequence (exclusive)java.io.IOException
- If failed to writejava.lang.IllegalArgumentException
- If invalid HEX sequence lengthjava.lang.NumberFormatException
- If invalid HEX characters foundpublic static byte fromHex(char hi, char lo) throws java.lang.NumberFormatException
java.lang.NumberFormatException
public static int readInt(java.io.InputStream input, byte[] buf) throws java.io.IOException
input
- The InputStream
buf
- Work buffer to usejava.io.IOException
- If failed to read 4 bytes or not enough room in work bufferreadInt(InputStream, byte[], int, int)
public static int readInt(java.io.InputStream input, byte[] buf, int offset, int len) throws java.io.IOException
input
- The InputStream
buf
- Work buffer to useoffset
- Offset in buffer to uslen
- Available length - must have at least 4 bytes availablejava.io.IOException
- If failed to read 4 bytes or not enough room in work bufferreadUInt(InputStream, byte[], int, int)
public static long readUInt(java.io.InputStream input, byte[] buf) throws java.io.IOException
input
- The InputStream
buf
- Work buffer to usejava.io.IOException
- If failed to read 4 bytes or not enough room in work bufferreadUInt(InputStream, byte[], int, int)
public static long readUInt(java.io.InputStream input, byte[] buf, int offset, int len) throws java.io.IOException
input
- The InputStream
buf
- Work buffer to useoffset
- Offset in buffer to uslen
- Available length - must have at least 4 bytes availablejava.io.IOException
- If failed to read 4 bytes or not enough room in work buffergetUInt(byte[], int, int)
public static long getUInt(byte... buf)
buf
- A buffer holding a 32-bit unsigned integer in big endian format. Note: if more than 4
bytes are available, then only the first 4 bytes in the buffer will be usedlong
whose 32 high-order bits are zerogetUInt(byte[], int, int)
public static long getUInt(byte[] buf, int off, int len)
buf
- A buffer holding a 32-bit unsigned integer in big endian format.off
- The offset of the data in the bufferlen
- The available data length. Note: if more than 4 bytes are available, then only the
first 4 bytes in the buffer will be used (starting at the specified offset)long
whose 32 high-order bits are zeropublic static void writeInt(java.io.OutputStream output, int value, byte[] buf) throws java.io.IOException
output
- The OutputStream
to write the valuevalue
- The 32-bit valuebuf
- A work buffer to use - must have enough space to contain 4 bytesjava.io.IOException
- If failed to write the value or work buffer too smallwriteInt(OutputStream, int, byte[], int, int)
public static void writeInt(java.io.OutputStream output, int value, byte[] buf, int off, int len) throws java.io.IOException
output
- The OutputStream
to write the valuevalue
- The 32-bit valuebuf
- A work buffer to use - must have enough space to contain 4 bytesoff
- The offset to write the valuelen
- The available spacejava.io.IOException
- If failed to write the value or work buffer too smallwriteUInt(OutputStream, long, byte[], int, int)
public static void writeUInt(java.io.OutputStream output, long value, byte[] buf) throws java.io.IOException
output
- The OutputStream
to write the valuevalue
- The 32-bit valuebuf
- A work buffer to use - must have enough space to contain 4 bytesjava.io.IOException
- If failed to write the value or work buffer too smallwriteUInt(OutputStream, long, byte[], int, int)
public static void writeUInt(java.io.OutputStream output, long value, byte[] buf, int off, int len) throws java.io.IOException
output
- The OutputStream
to write the valuevalue
- The 32-bit valuebuf
- A work buffer to use - must have enough space to contain 4 bytesoff
- The offset to write the valuelen
- The available spacejava.io.IOException
- If failed to write the value or work buffer to smallputUInt(long, byte[], int, int)
public static int putUInt(long value, byte[] buf)
value
- The 32-bit valuebuf
- The bufferjava.lang.IllegalArgumentException
- if not enough space availableputUInt(long, byte[], int, int)
public static int putUInt(long value, byte[] buf, int off, int len)
value
- The 32-bit valuebuf
- The bufferoff
- The offset to write the valuelen
- The available spacejava.lang.IllegalArgumentException
- if not enough space availablepublic static boolean equals(byte[] a1, byte[] a2)
public static boolean equals(byte[] a1, int a1Offset, byte[] a2, int a2Offset, int length)
public static int getNextPowerOf2(int value)
public static int updateLengthPlaceholder(Buffer buffer, int lenPos)
buffer
- The Buffer
lenPos
- The offset in the buffer where the length placeholder is to be update - Note: assumption is
that the encoded data starts immediately after the placeholderpublic static void updateLengthPlaceholder(Buffer buffer, int lenPos, int dataLength)
buffer
- The Buffer
lenPos
- The offset in the buffer where the length placeholder is to be update - Note: assumption
is that the encoded data starts immediately after the placeholderdataLength
- The length to updatepublic static <B extends Buffer> B clear(B buffer)
Buffer.clear()
B
- The generic buffer typebuffer
- A Buffer
instance - ignored if null
public static long validateInt32Value(long value, java.lang.String message)
public static long validateInt32Value(long value, java.lang.String format, java.lang.Object arg)
public static long validateInt32Value(long value, java.lang.String format, java.lang.Object... args)
public static boolean isValidInt32Value(long value)
public static long validateUint32Value(long value, java.lang.String message)
public static long validateUint32Value(long value, java.lang.String format, java.lang.Object arg)
public static long validateUint32Value(long value, java.lang.String format, java.lang.Object... args)
public static boolean isValidUint32Value(long value)