Class ByteBufUtil
- java.lang.Object
-
- net.lax1dude.eaglercraft.v1_8.netty.ByteBufUtil
-
public final class ByteBufUtil extends java.lang.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 int
compare(ByteBuf bufferA, ByteBuf bufferB)
Compares the two specified buffers as described inByteBuf.compareTo(ByteBuf)
.static byte
decodeHexByte(java.lang.CharSequence s, int pos)
Decode a 2-digit hex byte from within a string.static ByteBuf
encodeString(java.nio.CharBuffer src, java.nio.charset.Charset charset)
Encode the givenCharBuffer
using the givenCharset
into a newByteBuf
which is allocated via theByteBufAllocator
.static boolean
equals(ByteBuf bufferA, ByteBuf bufferB)
Returnstrue
if and only if the two specified buffers are identical to each other as described inChannelBuffer#equals(Object)
.static int
hashCode(ByteBuf buffer)
Calculates the hash code of the specified buffer.static int
indexOf(ByteBuf buffer, int fromIndex, int toIndex, byte value)
The default implementation ofByteBuf.indexOf(int, int, byte)
.static boolean
isText(ByteBuf buf, int index, int length, java.nio.charset.Charset charset)
Returnstrue
if the specifiedByteBuf
starting atindex
withlength
is valid text using the givenCharset
, otherwise returnfalse
.static boolean
isText(ByteBuf buf, java.nio.charset.Charset charset)
static ByteBuf
readBytes(ByteBuf buffer, int length)
Read the given amount of bytes into a newByteBuf
that is allocated from theByteBufAllocator
.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
writeUtf8(java.lang.CharSequence seq)
static int
writeUtf8(ByteBuf buf, java.lang.CharSequence seq)
-
-
-
Method Detail
-
decodeHexByte
public static byte decodeHexByte(java.lang.CharSequence s, int pos)
Decode a 2-digit hex byte from within a string.
-
hashCode
public static int hashCode(ByteBuf buffer)
Calculates the hash code of the specified buffer. This method is useful when implementing a new buffer type.
-
equals
public static boolean equals(ByteBuf bufferA, ByteBuf bufferB)
Returnstrue
if and only if the two specified buffers are identical to each other as described inChannelBuffer#equals(Object)
. This method is useful when implementing a new buffer type.
-
compare
public static int compare(ByteBuf bufferA, ByteBuf bufferB)
Compares the two specified buffers as described inByteBuf.compareTo(ByteBuf)
. This method is useful when implementing a new buffer type.
-
indexOf
public static int indexOf(ByteBuf buffer, int fromIndex, int toIndex, byte value)
The default implementation ofByteBuf.indexOf(int, int, byte)
. This method is useful when implementing a new buffer type.
-
swapShort
public static short swapShort(short value)
Toggles the endianness of the specified 16-bit short integer.
-
swapMedium
public static int swapMedium(int value)
Toggles the endianness of the specified 24-bit medium integer.
-
swapInt
public static int swapInt(int value)
Toggles the endianness of the specified 32-bit integer.
-
swapLong
public static long swapLong(long value)
Toggles the endianness of the specified 64-bit long integer.
-
readBytes
public static ByteBuf readBytes(ByteBuf buffer, int length)
Read the given amount of bytes into a newByteBuf
that is allocated from theByteBufAllocator
.
-
writeUtf8
public static ByteBuf writeUtf8(java.lang.CharSequence seq)
-
writeUtf8
public static int writeUtf8(ByteBuf buf, java.lang.CharSequence seq)
-
encodeString
public static ByteBuf encodeString(java.nio.CharBuffer src, java.nio.charset.Charset charset)
Encode the givenCharBuffer
using the givenCharset
into a newByteBuf
which is allocated via theByteBufAllocator
.
-
isText
public static boolean isText(ByteBuf buf, java.nio.charset.Charset charset)
- Parameters:
buf
- The givenByteBuf
.charset
- The specifiedCharset
.
-
isText
public static boolean isText(ByteBuf buf, int index, int length, java.nio.charset.Charset charset)
Returnstrue
if the specifiedByteBuf
starting atindex
withlength
is valid text using the givenCharset
, otherwise returnfalse
.- Parameters:
buf
- The givenByteBuf
.index
- The start index of the specified buffer.length
- The length of the specified buffer.charset
- The specifiedCharset
.- Throws:
java.lang.IndexOutOfBoundsException
- ifindex
+length
is greater thanbuf.readableBytes
-
-