- java.lang.Object
-
- io.netty5.buffer.BufferUtil
-
public final class BufferUtil extends Object
A collection of utility methods that is related with handlingByteBuf
, such as the generation of hex dump and swapping an integer's byte order.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
appendPrettyHexDump(StringBuilder dump, Buffer buf)
Appends the prettified multi-line hexadecimal dump of the specifiedBuffer
to the specifiedStringBuilder
that is easy to read by humans.static void
appendPrettyHexDump(StringBuilder dump, Buffer buf, int offset, int length)
Appends the prettified multi-line hexadecimal dump of the specifiedBuffer
to the specifiedStringBuilder
that is easy to read by humans, starting at the givenoffset
using the givenlength
.static boolean
equals(Buffer first, int firstReaderOffset, Buffer second, int secondReaderOffset, int length)
Returnstrue
if and only if the two specified buffers are identical to each other forlength
bytes starting atfirstReaderOffset
index for thefirst
buffer andsecondReaderOffset
index for thesecond
buffer.static byte[]
getBytes(Buffer buf)
Create a copy of the underlying storage frombuf
into a byte array.static byte[]
getBytes(Buffer buf, int start, int length)
Create a copy of the underlying storage frombuf
into a byte array.static String
hexDump(byte[] array)
Returns a hex dump of the specified byte array.static String
hexDump(byte[] array, int fromIndex, int length)
Returns a hex dump of the specified byte array's sub-region.static String
hexDump(Buffer buffer)
Returns a hex dump of the specified buffer's readable bytes.static String
hexDump(Buffer buffer, int fromIndex, int length)
Returns a hex dump of the specified buffer's sub-region.static int
reverseMedium(int value)
Reverses the byte order (endianness) of a mediumstatic long
reverseUnsignedInt(long value)
Reverses the byte order (endianness) of an unsigned integerstatic int
reverseUnsignedMedium(int value)
Reverses the byte order (endianness) of an unsigned mediumstatic int
reverseUnsignedShort(int value)
Reverses the byte order (endianness) of an unsigned shortstatic Buffer
threadLocalDirectBuffer()
Returns a cached thread-local direct buffer, if available.static Buffer
writeAscii(BufferAllocator alloc, CharSequence seq)
-
-
-
Method Detail
-
reverseUnsignedShort
public static int reverseUnsignedShort(int value)
Reverses the byte order (endianness) of an unsigned short- Parameters:
value
- the number with original byte order- Returns:
- the number with reversed byte order
-
reverseMedium
public static int reverseMedium(int value)
Reverses the byte order (endianness) of a medium- Parameters:
value
- the number with original byte order- Returns:
- the number with reversed byte order
-
reverseUnsignedMedium
public static int reverseUnsignedMedium(int value)
Reverses the byte order (endianness) of an unsigned medium- Parameters:
value
- the number with original byte order- Returns:
- the number with reversed byte order
-
reverseUnsignedInt
public static long reverseUnsignedInt(long value)
Reverses the byte order (endianness) of an unsigned integer- Parameters:
value
- the number with original byte order- Returns:
- the number with reversed byte order
-
hexDump
public static String hexDump(Buffer buffer)
Returns a hex dump of the specified buffer's readable bytes.
-
hexDump
public static String hexDump(Buffer buffer, int fromIndex, int length)
Returns a hex dump of the specified buffer's sub-region.
-
hexDump
public static String hexDump(byte[] array, int fromIndex, int length)
Returns a hex dump of the specified byte array's sub-region.
-
writeAscii
public static Buffer writeAscii(BufferAllocator alloc, CharSequence seq)
-
getBytes
public static byte[] getBytes(Buffer buf)
Create a copy of the underlying storage frombuf
into a byte array. The copy will start atBuffer.readerOffset()
and copyBuffer.readableBytes()
bytes.
-
getBytes
public static byte[] getBytes(Buffer buf, int start, int length)
Create a copy of the underlying storage frombuf
into a byte array. The copy will start atstart
and copylength
bytes.
-
equals
public static boolean equals(Buffer first, int firstReaderOffset, Buffer second, int secondReaderOffset, int length)
Returnstrue
if and only if the two specified buffers are identical to each other forlength
bytes starting atfirstReaderOffset
index for thefirst
buffer andsecondReaderOffset
index for thesecond
buffer. A more compact way to express this is:first[firstRoff : firstRoff + length] == second[secondRoff : secondRoff + length]
-
appendPrettyHexDump
public static void appendPrettyHexDump(StringBuilder dump, Buffer buf)
Appends the prettified multi-line hexadecimal dump of the specifiedBuffer
to the specifiedStringBuilder
that is easy to read by humans.
-
appendPrettyHexDump
public static void appendPrettyHexDump(StringBuilder dump, Buffer buf, int offset, int length)
Appends the prettified multi-line hexadecimal dump of the specifiedBuffer
to the specifiedStringBuilder
that is easy to read by humans, starting at the givenoffset
using the givenlength
.
-
threadLocalDirectBuffer
public static Buffer threadLocalDirectBuffer()
Returns a cached thread-local direct buffer, if available.- Returns:
- a cached thread-local direct buffer, if available.
null
otherwise.
-
-