public final class ByteBufUtil
extends java.lang.Object
ByteBuf
,
such as the generation of hex dump and swapping an integer's byte order.Modifier and Type | Method and Description |
---|---|
static void |
appendPrettyHexDump(java.lang.StringBuilder dump,
ByteBuf buf)
Appends the prettified multi-line hexadecimal dump of the specified
ByteBuf to the specified
StringBuilder that is easy to read by humans. |
static void |
appendPrettyHexDump(java.lang.StringBuilder dump,
ByteBuf buf,
int offset,
int length)
Appends the prettified multi-line hexadecimal dump of the specified
ByteBuf to the specified
StringBuilder that is easy to read by humans, starting at the given offset using
the given length . |
static int |
compare(ByteBuf bufferA,
ByteBuf bufferB)
Compares the two specified buffers as described in
ByteBuf.compareTo(ByteBuf) . |
static byte |
decodeHexByte(java.lang.CharSequence s,
int pos)
Decode a 2-digit hex byte from within a string.
|
static byte[] |
decodeHexDump(java.lang.CharSequence hexDump)
Decodes a string generated by
hexDump(byte[]) |
static byte[] |
decodeHexDump(java.lang.CharSequence hexDump,
int fromIndex,
int length)
Decodes part of a string generated by
hexDump(byte[]) |
static ByteBuf |
encodeString(ByteBufAllocator alloc,
java.nio.CharBuffer src,
java.nio.charset.Charset charset)
Encode the given
CharBuffer using the given Charset into a new ByteBuf which
is allocated via the ByteBufAllocator . |
static boolean |
equals(ByteBuf bufferA,
ByteBuf bufferB)
Returns
true if and only if the two specified buffers are
identical to each other as described in ChannelBuffer#equals(Object) . |
static int |
hashCode(ByteBuf buffer)
Calculates the hash code of the specified buffer.
|
static java.lang.String |
hexDump(byte[] array)
Returns a hex dump
of the specified byte array.
|
static java.lang.String |
hexDump(byte[] array,
int fromIndex,
int length)
Returns a hex dump
of the specified byte array's sub-region.
|
static java.lang.String |
hexDump(ByteBuf buffer)
Returns a hex dump
of the specified buffer's readable bytes.
|
static java.lang.String |
hexDump(ByteBuf buffer,
int fromIndex,
int length)
Returns a hex dump
of the specified buffer's sub-region.
|
static int |
indexOf(ByteBuf buffer,
int fromIndex,
int toIndex,
byte value)
The default implementation of
ByteBuf.indexOf(int, int, byte) . |
static boolean |
isText(ByteBuf buf,
java.nio.charset.Charset charset)
|
static boolean |
isText(ByteBuf buf,
int index,
int length,
java.nio.charset.Charset charset)
Returns
true if the specified ByteBuf starting at index with length is valid
text using the given Charset , otherwise return false . |
static java.lang.String |
prettyHexDump(ByteBuf buffer)
Returns a multi-line hexadecimal dump of the specified
ByteBuf that is easy to read by humans. |
static java.lang.String |
prettyHexDump(ByteBuf buffer,
int offset,
int length)
Returns a multi-line hexadecimal dump of the specified
ByteBuf that is easy to read by humans,
starting at the given offset using the given length . |
static ByteBuf |
readBytes(ByteBufAllocator alloc,
ByteBuf buffer,
int length)
Read the given amount of bytes into a new
ByteBuf that is allocated from the ByteBufAllocator . |
static int |
swapInt(int value)
Toggles the endianness of the specified 32-bit integer.
|
static long |
swapLong(long value)
Toggles the endianness of the specified 64-bit long integer.
|
static int |
swapMedium(int value)
Toggles the endianness of the specified 24-bit medium integer.
|
static short |
swapShort(short value)
Toggles the endianness of the specified 16-bit short integer.
|
static ByteBuf |
threadLocalDirectBuffer()
Returns a cached thread-local direct buffer, if available.
|
static ByteBuf |
writeAscii(ByteBufAllocator alloc,
java.lang.CharSequence seq)
|
static int |
writeAscii(ByteBuf buf,
java.lang.CharSequence seq)
|
static ByteBuf |
writeUtf8(ByteBufAllocator alloc,
java.lang.CharSequence seq)
|
static int |
writeUtf8(ByteBuf buf,
java.lang.CharSequence seq)
|
public static java.lang.String hexDump(ByteBuf buffer)
public static java.lang.String hexDump(ByteBuf buffer, int fromIndex, int length)
public static java.lang.String hexDump(byte[] array)
public static java.lang.String hexDump(byte[] array, int fromIndex, int length)
public static byte decodeHexByte(java.lang.CharSequence s, int pos)
public static byte[] decodeHexDump(java.lang.CharSequence hexDump)
hexDump(byte[])
public static byte[] decodeHexDump(java.lang.CharSequence hexDump, int fromIndex, int length)
hexDump(byte[])
public static int hashCode(ByteBuf buffer)
public static boolean equals(ByteBuf bufferA, ByteBuf bufferB)
true
if and only if the two specified buffers are
identical to each other as described in ChannelBuffer#equals(Object)
.
This method is useful when implementing a new buffer type.public static int compare(ByteBuf bufferA, ByteBuf bufferB)
ByteBuf.compareTo(ByteBuf)
.
This method is useful when implementing a new buffer type.public static int indexOf(ByteBuf buffer, int fromIndex, int toIndex, byte value)
ByteBuf.indexOf(int, int, byte)
.
This method is useful when implementing a new buffer type.public static short swapShort(short value)
public static int swapMedium(int value)
public static int swapInt(int value)
public static long swapLong(long value)
public static ByteBuf readBytes(ByteBufAllocator alloc, ByteBuf buffer, int length)
ByteBuf
that is allocated from the ByteBufAllocator
.public static ByteBuf writeUtf8(ByteBufAllocator alloc, java.lang.CharSequence seq)
public static int writeUtf8(ByteBuf buf, java.lang.CharSequence seq)
public static ByteBuf writeAscii(ByteBufAllocator alloc, java.lang.CharSequence seq)
public static int writeAscii(ByteBuf buf, java.lang.CharSequence seq)
public static ByteBuf encodeString(ByteBufAllocator alloc, java.nio.CharBuffer src, java.nio.charset.Charset charset)
CharBuffer
using the given Charset
into a new ByteBuf
which
is allocated via the ByteBufAllocator
.public static java.lang.String prettyHexDump(ByteBuf buffer)
ByteBuf
that is easy to read by humans.public static java.lang.String prettyHexDump(ByteBuf buffer, int offset, int length)
ByteBuf
that is easy to read by humans,
starting at the given offset
using the given length
.public static void appendPrettyHexDump(java.lang.StringBuilder dump, ByteBuf buf)
ByteBuf
to the specified
StringBuilder
that is easy to read by humans.public static void appendPrettyHexDump(java.lang.StringBuilder dump, ByteBuf buf, int offset, int length)
ByteBuf
to the specified
StringBuilder
that is easy to read by humans, starting at the given offset
using
the given length
.public static ByteBuf threadLocalDirectBuffer()
null
otherwise.public static boolean isText(ByteBuf buf, java.nio.charset.Charset charset)
buf
- The given ByteBuf
.charset
- The specified Charset
.public static boolean isText(ByteBuf buf, int index, int length, java.nio.charset.Charset charset)
true
if the specified ByteBuf
starting at index
with length
is valid
text using the given Charset
, otherwise return false
.buf
- The given ByteBuf
.index
- The start index of the specified buffer.length
- The length of the specified buffer.charset
- The specified Charset
.java.lang.IndexOutOfBoundsException
- if index
+ length
is greater than buf.readableBytes
Copyright © 2008–2018 The Netty Project. All rights reserved.