org.jlab.coda.cMsg
Class cMsgUtilities

java.lang.Object
  extended by org.jlab.coda.cMsg.cMsgUtilities

public class cMsgUtilities
extends java.lang.Object

This class stores methods which are neatly self-contained and may be used in more that one place.

Version:
1.0
Author:
Carl Timmer

Constructor Summary
cMsgUtilities()
           
 
Method Summary
static java.lang.String printError(int error, int debug)
          Method that returns and/or prints an error explanation.
static int readSocketBytes(java.nio.ByteBuffer buffer, java.nio.channels.SocketChannel channel, int bytes, int debug)
          This methods reads a minimum of number of bytes from a channel into a buffer.
static int readSocketBytesPlain(java.nio.ByteBuffer buffer, java.nio.channels.SocketChannel channel, int bytes)
          This methods reads a minimum of number of bytes from a channel into a buffer.
static void registerChannel(java.nio.channels.Selector selector, java.nio.channels.SocketChannel channel, int ops)
          Registers an nio channel with a selector and sets socket parameters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

cMsgUtilities

public cMsgUtilities()
Method Detail

readSocketBytesPlain

public static int readSocketBytesPlain(java.nio.ByteBuffer buffer,
                                       java.nio.channels.SocketChannel channel,
                                       int bytes)
                                throws java.io.IOException
This methods reads a minimum of number of bytes from a channel into a buffer.

Parameters:
buffer - a byte buffer which channel data is read into
channel - nio socket communication channel
bytes - minimum number of bytes to read from channel
Returns:
number of bytes read
Throws:
java.io.IOException - If channel is closed or cannot be read from

readSocketBytes

public static int readSocketBytes(java.nio.ByteBuffer buffer,
                                  java.nio.channels.SocketChannel channel,
                                  int bytes,
                                  int debug)
                           throws java.io.IOException
This methods reads a minimum of number of bytes from a channel into a buffer.

Parameters:
buffer - a byte buffer which channel data is read into
channel - nio socket communication channel
bytes - minimum number of bytes to read from channel
debug - level of debug output
Returns:
number of bytes read
Throws:
java.io.IOException - If channel is closed or cannot be read from

registerChannel

public static void registerChannel(java.nio.channels.Selector selector,
                                   java.nio.channels.SocketChannel channel,
                                   int ops)
                            throws java.io.IOException
Registers an nio channel with a selector and sets socket parameters.

Parameters:
selector - object which handles channel readiness states
channel - nio socket communication channel
ops - selector's operation
Throws:
java.io.IOException - If socket parameters cannot be set or channel is closed

printError

public static java.lang.String printError(int error,
                                          int debug)
Method that returns and/or prints an error explanation.

Parameters:
error - error number
debug - level of debug output
Returns:
error explanation