Modifier and Type | Method and Description |
---|---|
static void |
appendPrettyHexDump(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(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 void |
copy(io.netty.util.AsciiString src,
ByteBuf dst)
|
static void |
copy(io.netty.util.AsciiString src,
int srcIdx,
ByteBuf dst,
int length)
|
static void |
copy(io.netty.util.AsciiString src,
int srcIdx,
ByteBuf dst,
int dstIdx,
int length)
|
static byte |
decodeHexByte(CharSequence s,
int pos)
Decode a 2-digit hex byte from within a string.
|
static byte[] |
decodeHexDump(CharSequence hexDump)
Decodes a string generated by
hexDump(byte[]) |
static byte[] |
decodeHexDump(CharSequence hexDump,
int fromIndex,
int length)
Decodes part of a string generated by
hexDump(byte[]) |
static ByteBuf |
encodeString(ByteBufAllocator alloc,
CharBuffer src,
Charset charset)
Encode the given
CharBuffer using the given Charset into a new ByteBuf which
is allocated via the ByteBufAllocator . |
static ByteBuf |
encodeString(ByteBufAllocator alloc,
CharBuffer src,
Charset charset,
int extraCapacity)
Encode the given
CharBuffer using the given Charset into a new ByteBuf which
is allocated via the ByteBufAllocator . |
static boolean |
ensureWritableSuccess(int ensureWritableResult)
Used to determine if the return value of
ByteBuf.ensureWritable(int, boolean) means that there is
adequate space and a write operation will succeed. |
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 ByteBuf.equals(Object) . |
static boolean |
equals(ByteBuf a,
int aStartIndex,
ByteBuf b,
int bStartIndex,
int length)
Returns
true if and only if the two specified buffers are
identical to each other for length bytes starting at aStartIndex
index for the a buffer and bStartIndex index for the b buffer. |
static byte[] |
getBytes(ByteBuf buf)
Create a copy of the underlying storage from
buf into a byte array. |
static byte[] |
getBytes(ByteBuf buf,
int start,
int length)
Create a copy of the underlying storage from
buf into a byte array. |
static byte[] |
getBytes(ByteBuf buf,
int start,
int length,
boolean copy)
Return an array of the underlying storage from
buf into a byte array. |
static int |
hashCode(ByteBuf buffer)
Calculates the hash code of the specified buffer.
|
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(ByteBuf buffer)
Returns a hex dump
of the specified buffer's readable bytes.
|
static String |
hexDump(ByteBuf buffer,
int fromIndex,
int length)
Returns a hex dump
of the specified buffer's sub-region.
|
static int |
indexOf(ByteBuf needle,
ByteBuf haystack)
Returns the reader index of needle in haystack, or -1 if needle is not in haystack.
|
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,
Charset charset)
|
static boolean |
isText(ByteBuf buf,
int index,
int length,
Charset charset)
|
static String |
prettyHexDump(ByteBuf buffer)
Returns a multi-line hexadecimal dump of the specified
ByteBuf that is easy to read by humans. |
static 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 |
reserveAndWriteUtf8(ByteBuf buf,
CharSequence seq,
int reserveBytes)
|
static ByteBuf |
setShortBE(ByteBuf buf,
int index,
int shortValue)
Sets a big-endian 16-bit short integer to the buffer.
|
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 int |
utf8Bytes(CharSequence seq)
Returns the exact bytes length of UTF8 character sequence.
|
static int |
utf8MaxBytes(CharSequence seq)
Returns max bytes length of UTF8 character sequence.
|
static int |
utf8MaxBytes(int seqLength)
Returns max bytes length of UTF8 character sequence of the given length.
|
static ByteBuf |
writeAscii(ByteBufAllocator alloc,
CharSequence seq)
|
static int |
writeAscii(ByteBuf buf,
CharSequence seq)
|
static ByteBuf |
writeMediumBE(ByteBuf buf,
int mediumValue)
Writes a big-endian 24-bit medium integer to the buffer.
|
static ByteBuf |
writeShortBE(ByteBuf buf,
int shortValue)
Writes a big-endian 16-bit short integer to the buffer.
|
static ByteBuf |
writeUtf8(ByteBufAllocator alloc,
CharSequence seq)
|
static int |
writeUtf8(ByteBuf buf,
CharSequence seq)
|
public static String hexDump(ByteBuf buffer)
public static String hexDump(ByteBuf buffer, int fromIndex, int length)
public static String hexDump(byte[] array, int fromIndex, int length)
public static byte decodeHexByte(CharSequence s, int pos)
public static byte[] decodeHexDump(CharSequence hexDump)
hexDump(byte[])
public static byte[] decodeHexDump(CharSequence hexDump, int fromIndex, int length)
hexDump(byte[])
public static boolean ensureWritableSuccess(int ensureWritableResult)
ByteBuf.ensureWritable(int, boolean)
means that there is
adequate space and a write operation will succeed.ensureWritableResult
- The return value from ByteBuf.ensureWritable(int, boolean)
.true
if ensureWritableResult
means that there is adequate space and a write operation
will succeed.public static int hashCode(ByteBuf buffer)
public static int indexOf(ByteBuf needle, ByteBuf haystack)
public static boolean equals(ByteBuf a, int aStartIndex, ByteBuf b, int bStartIndex, int length)
true
if and only if the two specified buffers are
identical to each other for length
bytes starting at aStartIndex
index for the a
buffer and bStartIndex
index for the b
buffer.
A more compact way to express this is:
a[aStartIndex : aStartIndex + length] == b[bStartIndex : bStartIndex + length]
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 ByteBuf.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 writeShortBE(ByteBuf buf, int shortValue)
public static ByteBuf setShortBE(ByteBuf buf, int index, int shortValue)
public static ByteBuf writeMediumBE(ByteBuf buf, int mediumValue)
public static ByteBuf readBytes(ByteBufAllocator alloc, ByteBuf buffer, int length)
ByteBuf
that is allocated from the ByteBufAllocator
.public static ByteBuf writeUtf8(ByteBufAllocator alloc, CharSequence seq)
public static int writeUtf8(ByteBuf buf, CharSequence seq)
CharSequence
in UTF-8 and write
it to a ByteBuf
.
It behaves like reserveAndWriteUtf8(ByteBuf, CharSequence, int)
with reserveBytes
computed by utf8MaxBytes(CharSequence)
.
This method returns the actual number of bytes written.
public static int reserveAndWriteUtf8(ByteBuf buf, CharSequence seq, int reserveBytes)
CharSequence
in UTF-8 and write
it into reserveBytes
of a ByteBuf
.
The reserveBytes
must be computed (ie eagerly using utf8MaxBytes(CharSequence)
or exactly with utf8Bytes(CharSequence)
) to ensure this method to not fail: for performance reasons
the index checks will be performed using just reserveBytes
.
This method returns the actual number of bytes written.
public static int utf8MaxBytes(int seqLength)
public static int utf8MaxBytes(CharSequence seq)
It behaves like utf8MaxBytes(int)
applied to seq
CharSequence.length()
.
public static int utf8Bytes(CharSequence seq)
This method is producing the exact length according to writeUtf8(ByteBuf, CharSequence)
.
public static ByteBuf writeAscii(ByteBufAllocator alloc, CharSequence seq)
public static int writeAscii(ByteBuf buf, CharSequence seq)
CharSequence
in ASCII and write it
to a ByteBuf
.
This method returns the actual number of bytes written.public static ByteBuf encodeString(ByteBufAllocator alloc, CharBuffer src, Charset charset)
CharBuffer
using the given Charset
into a new ByteBuf
which
is allocated via the ByteBufAllocator
.public static ByteBuf encodeString(ByteBufAllocator alloc, CharBuffer src, Charset charset, int extraCapacity)
CharBuffer
using the given Charset
into a new ByteBuf
which
is allocated via the ByteBufAllocator
.alloc
- The ByteBufAllocator
to allocate ByteBuf
.src
- The CharBuffer
to encode.charset
- The specified Charset
.extraCapacity
- the extra capacity to alloc except the space for decoding.public static ByteBuf threadLocalDirectBuffer()
null
otherwise.public static byte[] getBytes(ByteBuf buf)
buf
into a byte array.
The copy will start at ByteBuf.readerIndex()
and copy ByteBuf.readableBytes()
bytes.public static byte[] getBytes(ByteBuf buf, int start, int length)
buf
into a byte array.
The copy will start at start
and copy length
bytes.public static byte[] getBytes(ByteBuf buf, int start, int length, boolean copy)
buf
into a byte array.
The copy will start at start
and copy length
bytes.
If copy
is true a copy will be made of the memory.
If copy
is false the underlying storage will be shared, if possible.public static void copy(io.netty.util.AsciiString src, ByteBuf dst)
src
- the source string to copydst
- the destination bufferpublic static void copy(io.netty.util.AsciiString src, int srcIdx, ByteBuf dst, int dstIdx, int length)
src
to a ByteBuf
using ByteBuf.setBytes(int, byte[], int, int)
.
Unlike the copy(AsciiString, ByteBuf)
and copy(AsciiString, int, ByteBuf, int)
methods,
this method do not increase a writerIndex
of dst
buffer.src
- the source string to copysrcIdx
- the starting offset of characters to copydst
- the destination bufferdstIdx
- the starting offset in the destination bufferlength
- the number of characters to copypublic static void copy(io.netty.util.AsciiString src, int srcIdx, ByteBuf dst, int length)
src
- the source string to copysrcIdx
- the starting offset of characters to copydst
- the destination bufferlength
- the number of characters to copypublic static String prettyHexDump(ByteBuf buffer)
ByteBuf
that is easy to read by humans.public static 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(StringBuilder dump, ByteBuf buf)
ByteBuf
to the specified
StringBuilder
that is easy to read by humans.public static void appendPrettyHexDump(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 boolean isText(ByteBuf buf, int index, int length, 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
.IndexOutOfBoundsException
- if index
+ length
is greater than buf.readableBytes
Copyright © 2008–2019 The Netty Project. All rights reserved.