Top Description Inners Fields Constructors Methods
io.netty5.buffer

public final Class BufferUtil

extends Object
Class Inheritance
Imports
io.netty5.buffer.internal.InternalBufferUtils, io.netty5.util.concurrent.FastThreadLocal, io.netty5.util.internal.PlatformDependent, .StringUtil, .SystemPropertyUtil, io.netty5.util.internal.logging.InternalLogger, .InternalLoggerFactory, java.nio.charset.StandardCharsets

A collection of utility methods that is related with handling ByteBuf, such as the generation of hex dump and swapping an integer's byte order.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class

Field Summary

Modifier and TypeField and Description
private static final InternalLogger
private static final int
private static final int

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static void
appendPrettyHexDump(StringBuilder dump, Buffer buf)

Appends the prettified multi-line hexadecimal dump of the specified Buffer to the specified StringBuilder that is easy to read by humans.

public static void
appendPrettyHexDump(StringBuilder dump, Buffer buf, int offset, int length)

Appends the prettified multi-line hexadecimal dump of the specified Buffer to the specified StringBuilder that is easy to read by humans, starting at the given offset using the given length.

public static boolean
equals(Buffer first, int firstReaderOffset, Buffer second, int secondReaderOffset, int length)

Returns true if and only if the two specified buffers are identical to each other for length bytes starting at firstReaderOffset index for the first buffer and secondReaderOffset index for the second buffer.

public static byte[]
getBytes(Buffer buf)

Create a copy of the underlying storage from buf into a byte array.

public static byte[]
getBytes(Buffer buf, int start, int length)

Create a copy of the underlying storage from buf into a byte array.

public static String
hexDump(Buffer buffer)

Returns a hex dump of the specified buffer's readable bytes.

public static String
hexDump(Buffer buffer, int fromIndex, int length)

Returns a hex dump of the specified buffer's sub-region.

public static String
hexDump(byte[] array)

Returns a hex dump of the specified byte array.

public static String
hexDump(byte[] array, int fromIndex, int length)

Returns a hex dump of the specified byte array's sub-region.

public static int

Returns:

the number with reversed byte order
reverseMedium
(int
the number with original byte order
value
)

Reverses the byte order (endianness) of a medium

public static long

Returns:

the number with reversed byte order
reverseUnsignedInt
(long
the number with original byte order
value
)

Reverses the byte order (endianness) of an unsigned integer

public static int

Returns:

the number with reversed byte order
reverseUnsignedMedium
(int
the number with original byte order
value
)

Reverses the byte order (endianness) of an unsigned medium

public static int

Returns:

the number with reversed byte order
reverseUnsignedShort
(int
the number with original byte order
value
)

Reverses the byte order (endianness) of an unsigned short

public static Buffer

Returns:

a cached thread-local direct buffer, if available. null otherwise.
threadLocalDirectBuffer
()

Returns a cached thread-local direct buffer, if available.

public static Buffer

Returns:

The Buffer which contains the ASCII encoded result.
writeAscii
(BufferAllocator
The allocator used to allocate a new Buffer.
alloc
,
CharSequence
The characters to write into a buffer.
seq
)

Encode a CharSequence in ASCII and write it to a Buffer allocated with alloc.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

loggerback to summary
private static final InternalLogger logger
MAX_CHAR_BUFFER_SIZEback to summary
private static final int MAX_CHAR_BUFFER_SIZE
THREAD_LOCAL_BUFFER_SIZEback to summary
private static final int THREAD_LOCAL_BUFFER_SIZE

Constructor Detail

BufferUtilback to summary
private BufferUtil()

Method Detail

appendPrettyHexDumpback to summary
public static void appendPrettyHexDump(StringBuilder dump, Buffer buf)

Appends the prettified multi-line hexadecimal dump of the specified Buffer to the specified StringBuilder that is easy to read by humans.

appendPrettyHexDumpback to summary
public static void appendPrettyHexDump(StringBuilder dump, Buffer buf, int offset, int length)

Appends the prettified multi-line hexadecimal dump of the specified Buffer to the specified StringBuilder that is easy to read by humans, starting at the given offset using the given length.

equalsback to summary
public static boolean equals(Buffer first, int firstReaderOffset, Buffer second, int secondReaderOffset, int length)

Returns true if and only if the two specified buffers are identical to each other for length bytes starting at firstReaderOffset index for the first buffer and secondReaderOffset index for the second buffer. A more compact way to express this is:

first[firstRoff : firstRoff + length] == second[secondRoff : secondRoff + length]

getBytesback to summary
public static byte[] getBytes(Buffer buf)

Create a copy of the underlying storage from buf into a byte array. The copy will start at Buffer#readerOffset() and copy Buffer#readableBytes() bytes.

getBytesback to summary
public static byte[] getBytes(Buffer buf, int start, int length)

Create a copy of the underlying storage from buf into a byte array. The copy will start at start and copy length bytes.

hexDumpback to summary
public static String hexDump(Buffer buffer)

Returns a hex dump of the specified buffer's readable bytes.

hexDumpback to summary
public static String hexDump(Buffer buffer, int fromIndex, int length)

Returns a hex dump of the specified buffer's sub-region.

hexDumpback to summary
public static String hexDump(byte[] array)

Returns a hex dump of the specified byte array.

hexDumpback to summary
public static String hexDump(byte[] array, int fromIndex, int length)

Returns a hex dump of the specified byte array's sub-region.

reverseMediumback to summary
public static int reverseMedium(int value)

Reverses the byte order (endianness) of a medium

Parameters
value:int

the number with original byte order

Returns:int

the number with reversed byte order

reverseUnsignedIntback to summary
public static long reverseUnsignedInt(long value)

Reverses the byte order (endianness) of an unsigned integer

Parameters
value:long

the number with original byte order

Returns:long

the number with reversed byte order

reverseUnsignedMediumback to summary
public static int reverseUnsignedMedium(int value)

Reverses the byte order (endianness) of an unsigned medium

Parameters
value:int

the number with original byte order

Returns:int

the number with reversed byte order

reverseUnsignedShortback to summary
public static int reverseUnsignedShort(int value)

Reverses the byte order (endianness) of an unsigned short

Parameters
value:int

the number with original byte order

Returns:int

the number with reversed byte order

threadLocalDirectBufferback to summary
public static Buffer threadLocalDirectBuffer()

Returns a cached thread-local direct buffer, if available.

Returns:Buffer

a cached thread-local direct buffer, if available. null otherwise.

writeAsciiback to summary
public static Buffer writeAscii(BufferAllocator alloc, CharSequence seq)

Encode a CharSequence in ASCII and write it to a Buffer allocated with alloc.

Parameters
alloc:BufferAllocator

The allocator used to allocate a new Buffer.

seq:CharSequence

The characters to write into a buffer.

Returns:Buffer

The Buffer which contains the ASCII encoded result.

io.netty5.buffer back to summary

private final Class BufferUtil.HexUtil

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private static final char[]
private static final String[]
private static final String[]
private static final String[]
private static final char[]
private static final String[]

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static void
appendHexDumpRowPrefix(StringBuilder dump, int row, int rowStartIndex)

private static void
appendPrettyHexDump(StringBuilder dump, Buffer buf, int offset, int length)

private static String
hexDump(Buffer buffer, int fromIndex, int length)

private static String
hexDump(byte[] array, int fromIndex, int length)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BYTE2CHARback to summary
private static final char[] BYTE2CHAR
BYTE2HEXback to summary
private static final String[] BYTE2HEX
BYTEPADDINGback to summary
private static final String[] BYTEPADDING
HEXDUMP_ROWPREFIXESback to summary
private static final String[] HEXDUMP_ROWPREFIXES
HEXDUMP_TABLEback to summary
private static final char[] HEXDUMP_TABLE
HEXPADDINGback to summary
private static final String[] HEXPADDING

Constructor Detail

HexUtilback to summary
private HexUtil()

Method Detail

appendHexDumpRowPrefixback to summary
private static void appendHexDumpRowPrefix(StringBuilder dump, int row, int rowStartIndex)
appendPrettyHexDumpback to summary
private static void appendPrettyHexDump(StringBuilder dump, Buffer buf, int offset, int length)
hexDumpback to summary
private static String hexDump(Buffer buffer, int fromIndex, int length)
hexDumpback to summary
private static String hexDump(byte[] array, int fromIndex, int length)
io.netty5.buffer back to summary

private final Class BufferUtil.ThreadLocalDirectBufferHolder

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv static final FastThreadLocal<Buffer>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BUFFERback to summary
pack-priv static final FastThreadLocal<Buffer> BUFFER

Constructor Detail

ThreadLocalDirectBufferHolderback to summary
private ThreadLocalDirectBufferHolder()