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(org.jboss.netty.channel.ChannelPipeline pipeline)
A utility method to clear the netty pipeline of all handlers.
|
static org.jboss.netty.buffer.ChannelBuffer |
createBufferForOpcode(int opcode) |
static org.jboss.netty.channel.ChannelPipeline |
getPipeLineOfConnection(NettyTCPMessageSender messageSender) |
static org.jboss.netty.channel.ChannelPipeline |
getPipeLineOfConnection(PlayerSession playerSession) |
static <T,V> V |
readObject(org.jboss.netty.buffer.ChannelBuffer buffer,
Transform<org.jboss.netty.buffer.ChannelBuffer,V> decoder) |
static InetSocketAddress |
readSocketAddress(org.jboss.netty.buffer.ChannelBuffer buffer)
Read a socket address from a buffer.
|
static String |
readString(org.jboss.netty.buffer.ChannelBuffer 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(org.jboss.netty.buffer.ChannelBuffer 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(org.jboss.netty.buffer.ChannelBuffer buffer,
int length)
Read a string from a channel buffer with the specified length.
|
static String |
readString(org.jboss.netty.buffer.ChannelBuffer buffer,
int length,
Charset charset)
Read a string from a channel buffer with the specified length.
|
static String[] |
readStrings(org.jboss.netty.buffer.ChannelBuffer buffer,
int numOfStrings)
This method will read multiple strings of the buffer and return them as a
string array.
|
static String[] |
readStrings(org.jboss.netty.buffer.ChannelBuffer buffer,
int numOfStrings,
Charset charset)
This method will read multiple strings of the buffer and return them as a
string array.
|
static <V> org.jboss.netty.buffer.ChannelBuffer |
writeObject(Transform<V,org.jboss.netty.buffer.ChannelBuffer> converter,
V object) |
static org.jboss.netty.buffer.ChannelBuffer |
writeSocketAddress(InetSocketAddress socketAddress) |
static org.jboss.netty.buffer.ChannelBuffer |
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 org.jboss.netty.buffer.ChannelBuffer |
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 org.jboss.netty.buffer.ChannelBuffer |
writeStrings(Charset charset,
String... msgs)
Writes multiple strings to a channelBuffer with the length of the string
preceding its content.
|
static org.jboss.netty.buffer.ChannelBuffer |
writeStrings(String... msgs)
Writes multiple strings to a channelBuffer with the length of the string
preceding its content.
|
private static final org.slf4j.Logger LOG
public static final String NETTY_CHANNEL
public static org.jboss.netty.channel.ChannelPipeline getPipeLineOfConnection(NettyTCPMessageSender messageSender)
public static org.jboss.netty.channel.ChannelPipeline getPipeLineOfConnection(PlayerSession playerSession)
public static void clearPipeline(org.jboss.netty.channel.ChannelPipeline pipeline)
pipeline
- public static org.jboss.netty.buffer.ChannelBuffer createBufferForOpcode(int opcode)
public static String[] readStrings(org.jboss.netty.buffer.ChannelBuffer 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(org.jboss.netty.buffer.ChannelBuffer 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(org.jboss.netty.buffer.ChannelBuffer 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(org.jboss.netty.buffer.ChannelBuffer 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(org.jboss.netty.buffer.ChannelBuffer buffer, int length)
buffer
- The Netty buffer containing the String.length
- The number of bytes in the String.public static String readString(org.jboss.netty.buffer.ChannelBuffer 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 org.jboss.netty.buffer.ChannelBuffer writeStrings(String... msgs)
Hello
and
World
then the channel buffer returned would contain msgs
- The messages to be written.ChannelBuffer
with format
length-stringbinary-length-stringbinarypublic static org.jboss.netty.buffer.ChannelBuffer 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.ChannelBuffer
with format
length-stringbinary-length-stringbinarypublic static org.jboss.netty.buffer.ChannelBuffer writeString(String msg)
msg
- The string to be written.public static org.jboss.netty.buffer.ChannelBuffer 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(org.jboss.netty.buffer.ChannelBuffer buffer, Transform<org.jboss.netty.buffer.ChannelBuffer,V> decoder)
public static <V> org.jboss.netty.buffer.ChannelBuffer writeObject(Transform<V,org.jboss.netty.buffer.ChannelBuffer> converter, V object)
public static InetSocketAddress readSocketAddress(org.jboss.netty.buffer.ChannelBuffer buffer)
buffer
- The buffer containing the host and port as string.public static org.jboss.netty.buffer.ChannelBuffer writeSocketAddress(InetSocketAddress socketAddress)
Copyright © 2013. All Rights Reserved.