public class NettyUtils extends Object
| Modifier and Type | Field and Description |
|---|---|
private static org.slf4j.Logger |
LOG |
static String |
NETTY_CHANNEL |
| Constructor and Description |
|---|
NettyUtils() |
| Modifier and Type | Method and Description |
|---|---|
static void |
clearPipeline(io.netty.channel.ChannelPipeline pipeline)
A utility method to clear the netty pipeline of all handlers.
|
static io.netty.buffer.ByteBuf |
createBufferForOpcode(int opcode) |
static io.netty.channel.ChannelPipeline |
getPipeLineOfConnection(NettyTCPMessageSender messageSender) |
static io.netty.channel.ChannelPipeline |
getPipeLineOfConnection(PlayerSession playerSession) |
static <T,V> V |
readObject(io.netty.buffer.ByteBuf buffer,
Transform<io.netty.buffer.ByteBuf,V> decoder) |
static InetSocketAddress |
readSocketAddress(io.netty.buffer.ByteBuf buffer)
Read a socket address from a buffer.
|
static String |
readString(io.netty.buffer.ByteBuf buffer)
This method will first read an unsigned short to find the length of the
string and then read the actual string based on the length.
|
static String |
readString(io.netty.buffer.ByteBuf buffer,
Charset charset)
This method will first read an unsigned short to find the length of the
string and then read the actual string based on the length.
|
static String |
readString(io.netty.buffer.ByteBuf buffer,
int length)
Read a string from a channel buffer with the specified length.
|
static String |
readString(io.netty.buffer.ByteBuf buffer,
int length,
Charset charset)
Read a string from a channel buffer with the specified length.
|
static String[] |
readStrings(io.netty.buffer.ByteBuf buffer,
int numOfStrings)
This method will read multiple strings of the buffer and return them as a
string array.
|
static String[] |
readStrings(io.netty.buffer.ByteBuf buffer,
int numOfStrings,
Charset charset)
This method will read multiple strings of the buffer and return them as a
string array.
|
static <V> io.netty.buffer.ByteBuf |
writeObject(Transform<V,io.netty.buffer.ByteBuf> converter,
V object) |
static io.netty.buffer.ByteBuf |
writeSocketAddress(InetSocketAddress socketAddress) |
static io.netty.buffer.ByteBuf |
writeString(String msg)
Creates a channel buffer of which the first 2 bytes contain the length of
the string in bytes and the remaining is the actual string in binary
UTF-8 format.
|
static io.netty.buffer.ByteBuf |
writeString(String msg,
Charset charset)
Creates a channel buffer of which the first 2 bytes contain the length of
the string in bytes and the remaining is the actual string in binary with
specified format.
|
static io.netty.buffer.ByteBuf |
writeStrings(Charset charset,
String... msgs)
Writes multiple strings to a ByteBuf with the length of the string
preceding its content.
|
static io.netty.buffer.ByteBuf |
writeStrings(String... msgs)
Writes multiple strings to a ByteBuf with the length of the string
preceding its content.
|
private static final org.slf4j.Logger LOG
public static final String NETTY_CHANNEL
public static io.netty.channel.ChannelPipeline getPipeLineOfConnection(NettyTCPMessageSender messageSender)
public static io.netty.channel.ChannelPipeline getPipeLineOfConnection(PlayerSession playerSession)
public static void clearPipeline(io.netty.channel.ChannelPipeline pipeline)
pipeline - public static io.netty.buffer.ByteBuf createBufferForOpcode(int opcode)
public static String[] readStrings(io.netty.buffer.ByteBuf buffer, int numOfStrings)
buffer - The buffer containing the strings, with each string being a
strlength-strbytes combination.numOfStrings - The number of strings to be read. Should not be negative or 0public static String[] readStrings(io.netty.buffer.ByteBuf buffer, int numOfStrings, Charset charset)
buffer - The buffer containing the strings, with each string being a
strlength-strbytes combination.numOfStrings - The number of strings to be read. Should not be negative or 0charset - The Charset say 'UTF-8' in which the decoding needs to be
done.public static String readString(io.netty.buffer.ByteBuf buffer)
buffer - The Netty buffer containing at least one unsigned short
followed by a string of similar length.IndexOutOfBoundsException if
the length is greater than expected.public static String readString(io.netty.buffer.ByteBuf buffer, Charset charset)
buffer - The Netty buffer containing at least one unsigned short
followed by a string of similar length.charset - The Charset say 'UTF-8' in which the decoding needs to be
done.IndexOutOfBoundsException if
the length is greater than expected.public static String readString(io.netty.buffer.ByteBuf buffer, int length)
buffer - The Netty buffer containing the String.length - The number of bytes in the String.public static String readString(io.netty.buffer.ByteBuf buffer, int length, Charset charset)
buffer - The Netty buffer containing the String.length - The number of bytes in the String.charset - The Charset say 'UTF-8' in which the decoding needs to be
done.public static io.netty.buffer.ByteBuf writeStrings(String... msgs)
Hello and
World then the channel buffer returned would contain msgs - The messages to be written.ByteBuf with format
length-stringbinary-length-stringbinarypublic static io.netty.buffer.ByteBuf writeStrings(Charset charset, String... msgs)
Hello and
World then the channel buffer returned would contain charset - The Charset say 'UTF-8' in which the encoding needs to be
done.msgs - The messages to be written.ByteBuf with format
length-stringbinary-length-stringbinarypublic static io.netty.buffer.ByteBuf writeString(String msg)
msg - The string to be written.public static io.netty.buffer.ByteBuf writeString(String msg, Charset charset)
msg - The string to be written.charset - The Charset say 'UTF-8' in which the encoding needs to be
done.null if the
string parameter is null.public static <T,V> V readObject(io.netty.buffer.ByteBuf buffer,
Transform<io.netty.buffer.ByteBuf,V> decoder)
public static <V> io.netty.buffer.ByteBuf writeObject(Transform<V,io.netty.buffer.ByteBuf> converter, V object)
public static InetSocketAddress readSocketAddress(io.netty.buffer.ByteBuf buffer)
buffer - The buffer containing the host and port as string.public static io.netty.buffer.ByteBuf writeSocketAddress(InetSocketAddress socketAddress)
Copyright © 2013. All Rights Reserved.