org.littleshoot.util.mina
Class MinaUtils

java.lang.Object
  extended by org.littleshoot.util.mina.MinaUtils

public class MinaUtils
extends Object

Apache MINA utility functions.


Constructor Summary
MinaUtils()
           
 
Method Summary
static String getString(org.littleshoot.mina.common.ByteBuffer buf)
          Reads an ASCII string from the buffer.
static boolean isUdp(org.littleshoot.mina.common.IoSession session)
          Determines whether or not the specified session is a UDP session.
static void putUnsignedByte(org.littleshoot.mina.common.ByteBuffer bb, int value)
          Puts an unsigned byte into the buffer.
static void putUnsignedByte(org.littleshoot.mina.common.ByteBuffer bb, int position, int value)
          Puts an unsigned byte into the buffer.
static void putUnsignedInt(org.littleshoot.mina.common.ByteBuffer bb, int position, long value)
          Puts an unsigned byte into the buffer.
static void putUnsignedInt(org.littleshoot.mina.common.ByteBuffer bb, long value)
          Puts an unsigned byte into the buffer.
static void putUnsignedShort(org.littleshoot.mina.common.ByteBuffer bb, int value)
          Puts an unsigned byte into the buffer.
static void putUnsignedShort(org.littleshoot.mina.common.ByteBuffer bb, int position, int value)
          Puts an unsigned byte into the buffer.
static Collection<org.littleshoot.mina.common.ByteBuffer> split(org.littleshoot.mina.common.ByteBuffer buffer, int chunkSize)
          Splits the specified ByteBuffer into smaller ByteBuffers of the specified size.
static Collection<byte[]> splitToByteArrays(org.littleshoot.mina.common.ByteBuffer buffer, int chunkSize)
          Splits the specified ByteBuffer into smaller ByteBuffers of the specified size.
static String toAsciiString(org.littleshoot.mina.common.ByteBuffer buf)
          Useful for debugging.
static org.littleshoot.mina.common.ByteBuffer toBuf(String str)
          Converts the specified String to a ByteBuffer.
static byte[] toByteArray(org.littleshoot.mina.common.ByteBuffer buf)
          Copies the specified buffer to a byte array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MinaUtils

public MinaUtils()
Method Detail

toAsciiString

public static String toAsciiString(org.littleshoot.mina.common.ByteBuffer buf)
Useful for debugging. Turns the given buffer into an ASCII string. This does not affect the position or the limit of the buffer (it resets them to their original values when done).

Parameters:
buf - The buffer to convert to a string.
Returns:
The string.

getString

public static String getString(org.littleshoot.mina.common.ByteBuffer buf)
Reads an ASCII string from the buffer. Reads from the buffer's current position to its limit.

Parameters:
buf - The buffer to read from.
Returns:
The bytes converted to an ASCII string.

toByteArray

public static byte[] toByteArray(org.littleshoot.mina.common.ByteBuffer buf)
Copies the specified buffer to a byte array.

Parameters:
buf - The buffer to copy.
Returns:
The byte array.

split

public static Collection<org.littleshoot.mina.common.ByteBuffer> split(org.littleshoot.mina.common.ByteBuffer buffer,
                                                                       int chunkSize)
Splits the specified ByteBuffer into smaller ByteBuffers of the specified size. The remaining bytes in the buffer must be greater than the chunk size. This method will create smaller buffers of the specified size until there are fewer remaining bytes than the chunk size, when it will simply add a buffer the same size as the number of bytes remaining.

Parameters:
buffer - The ByteBuffer to split.
chunkSize - The size of the smaller buffers to create.
Returns:
A Collection of ByteBuffers of the specified size. The final buffer in the Collection will have a size > 0 and <= the chunk size.

splitToByteArrays

public static Collection<byte[]> splitToByteArrays(org.littleshoot.mina.common.ByteBuffer buffer,
                                                   int chunkSize)
Splits the specified ByteBuffer into smaller ByteBuffers of the specified size. The remaining bytes in the buffer must be greater than the chunk size. This method will create smaller buffers of the specified size until there are fewer remaining bytes than the chunk size, when it will simply add a buffer the same size as the number of bytes remaining.

Parameters:
buffer - The ByteBuffer to split.
chunkSize - The size of the smaller buffers to create.
Returns:
A Collection of ByteBuffers of the specified size. The final buffer in the Collection will have a size > 0 and <= the chunk size.

putUnsignedByte

public static void putUnsignedByte(org.littleshoot.mina.common.ByteBuffer bb,
                                   int value)
Puts an unsigned byte into the buffer.

Parameters:
bb - The buffer.
value - The value to insert.

putUnsignedByte

public static void putUnsignedByte(org.littleshoot.mina.common.ByteBuffer bb,
                                   int position,
                                   int value)
Puts an unsigned byte into the buffer.

Parameters:
bb - The buffer.
position - The index in the buffer to insert the value.
value - The value to insert.

putUnsignedShort

public static void putUnsignedShort(org.littleshoot.mina.common.ByteBuffer bb,
                                    int value)
Puts an unsigned byte into the buffer.

Parameters:
bb - The buffer.
value - The value to insert.

putUnsignedShort

public static void putUnsignedShort(org.littleshoot.mina.common.ByteBuffer bb,
                                    int position,
                                    int value)
Puts an unsigned byte into the buffer.

Parameters:
bb - The buffer.
position - The index in the buffer to insert the value.
value - The value to insert.

putUnsignedInt

public static void putUnsignedInt(org.littleshoot.mina.common.ByteBuffer bb,
                                  long value)
Puts an unsigned byte into the buffer.

Parameters:
bb - The buffer.
value - The value to insert.

putUnsignedInt

public static void putUnsignedInt(org.littleshoot.mina.common.ByteBuffer bb,
                                  int position,
                                  long value)
Puts an unsigned byte into the buffer.

Parameters:
bb - The buffer.
position - The index in the buffer to insert the value.
value - The value to insert.

toBuf

public static org.littleshoot.mina.common.ByteBuffer toBuf(String str)
Converts the specified String to a ByteBuffer. The string encoding is assumed to be ASCII.

Parameters:
str - The string to convert.
Returns:
The new ByteBuffer.

isUdp

public static boolean isUdp(org.littleshoot.mina.common.IoSession session)
Determines whether or not the specified session is a UDP session.

Parameters:
session - The session to check.
Returns:
true if the session is a UDP session, otherwise false.


Copyright © 2013 LittleShoot. All Rights Reserved.