- 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 voidappendPrettyHexDump(StringBuilder dump, Buffer buf)Appends the prettified multi-line hexadecimal dump of the specifiedBufferto the specifiedStringBuilderthat is easy to read by humans.static voidappendPrettyHexDump(StringBuilder dump, Buffer buf, int offset, int length)Appends the prettified multi-line hexadecimal dump of the specifiedBufferto the specifiedStringBuilderthat is easy to read by humans, starting at the givenoffsetusing the givenlength.static booleanequals(Buffer first, int firstReaderOffset, Buffer second, int secondReaderOffset, int length)Returnstrueif and only if the two specified buffers are identical to each other forlengthbytes starting atfirstReaderOffsetindex for thefirstbuffer andsecondReaderOffsetindex for thesecondbuffer.static byte[]getBytes(Buffer buf)Create a copy of the underlying storage frombufinto a byte array.static byte[]getBytes(Buffer buf, int start, int length)Create a copy of the underlying storage frombufinto a byte array.static StringhexDump(byte[] array)Returns a hex dump of the specified byte array.static StringhexDump(byte[] array, int fromIndex, int length)Returns a hex dump of the specified byte array's sub-region.static StringhexDump(Buffer buffer)Returns a hex dump of the specified buffer's readable bytes.static StringhexDump(Buffer buffer, int fromIndex, int length)Returns a hex dump of the specified buffer's sub-region.static intreverseMedium(int value)Reverses the byte order (endianness) of a mediumstatic longreverseUnsignedInt(long value)Reverses the byte order (endianness) of an unsigned integerstatic intreverseUnsignedMedium(int value)Reverses the byte order (endianness) of an unsigned mediumstatic intreverseUnsignedShort(int value)Reverses the byte order (endianness) of an unsigned shortstatic BufferthreadLocalDirectBuffer()Returns a cached thread-local direct buffer, if available.static BufferwriteAscii(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 frombufinto 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 frombufinto a byte array. The copy will start atstartand copylengthbytes.
-
equals
public static boolean equals(Buffer first, int firstReaderOffset, Buffer second, int secondReaderOffset, int length)
Returnstrueif and only if the two specified buffers are identical to each other forlengthbytes starting atfirstReaderOffsetindex for thefirstbuffer andsecondReaderOffsetindex for thesecondbuffer. 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 specifiedBufferto the specifiedStringBuilderthat 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 specifiedBufferto the specifiedStringBuilderthat is easy to read by humans, starting at the givenoffsetusing 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.
nullotherwise.
-
-