public class NettyUtils extends Object
Modifier and Type | Class and Description |
---|---|
static class |
NettyUtils.ObjectDecoderWrapper |
static class |
NettyUtils.ObjectEncoderWrapper |
static class |
NettyUtils.StringDecoderWrapper |
static class |
NettyUtils.StringEncoderWrapper |
Modifier and Type | Field and Description |
---|---|
static String |
NETTY_CHANNEL |
private static NettyUtils.ObjectDecoderWrapper |
OBJECT_DECODER |
private static NettyUtils.StringDecoderWrapper |
STRING_DECODER |
private static NettyUtils.StringEncoderWrapper |
STRING_ENCODER |
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 Object |
readObject(org.jboss.netty.buffer.ChannelBuffer buffer)
This method will first read an unsigned short to find the length of the
object and then read the actual object based on the length.
|
static Object |
readObject(org.jboss.netty.buffer.ChannelBuffer buffer,
int length)
Read an object from a channel buffer with the specified length.
|
static <T,V> V |
readObject(org.jboss.netty.buffer.ChannelBuffer buffer,
Transform<org.jboss.netty.buffer.ChannelBuffer,V> decoder) |
static Object[] |
readObjects(org.jboss.netty.buffer.ChannelBuffer buffer,
int numOfObjects)
This method will read multiple objects of the buffer and return them as
an object array.
|
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 NettyUtils.StringDecoderWrapper STRING_DECODER
private static final NettyUtils.StringEncoderWrapper STRING_ENCODER
private static final NettyUtils.ObjectDecoderWrapper OBJECT_DECODER
public static final String NETTY_CHANNEL
public static void clearPipeline(org.jboss.netty.channel.ChannelPipeline pipeline) throws NoSuchElementException
pipeline
- NoSuchElementException
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.public static Object[] readObjects(org.jboss.netty.buffer.ChannelBuffer buffer, int numOfObjects)
buffer
- The buffer containing the objects, with each object being a
objlength-objbytes combination.numOfObjects
- The number of objects to be read. Should not be negative or 0public static Object readObject(org.jboss.netty.buffer.ChannelBuffer buffer)
buffer
- The Netty buffer containing at least one unsigned short
followed by an Object of that length.IndexOutOfBoundsException
if
the length is greater than expected.public static Object readObject(org.jboss.netty.buffer.ChannelBuffer buffer, int length)
buffer
- The Netty buffer containing the Object.length
- The number of bytes in the Object.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) throws Exception
buffer
- The buffer containing the host and port as string.Exception
public static org.jboss.netty.buffer.ChannelBuffer writeSocketAddress(InetSocketAddress socketAddress)
Copyright © 2012. All Rights Reserved.