com.sun.grizzly.util
Class Utils

java.lang.Object
  extended by com.sun.grizzly.util.Utils

public class Utils
extends Object

Class contains set of useful operations commonly used in the framework

Author:
Alexey Stashok, Jean-Francois Arcand

Nested Class Summary
static class Utils.Result
           
 
Field Summary
static boolean VERBOSE_TESTS
           
 
Constructor Summary
Utils()
           
 
Method Summary
static byte[] copy(byte[] src)
           
static void dumpErr(Object text)
           
static void dumpOut(Object text)
           
static byte[] extractBytes(ByteBuffer byteBuffer, byte startByte, byte endByte)
          Return the bytes contained between the startByte and the endByte.
static int findBytes(ByteBuffer byteBuffer, byte[] b)
          Specialized utility method: find a sequence of lower case bytes inside a ByteBuffer.
static int findBytes(ByteBuffer bb, Pattern pattern)
           
static boolean isDebugVM()
           
static Charset lookupCharset(String charsetName)
          Lookup a Charset by name.
static Selector openSelector()
           
static Utils.Result readWithTemporarySelector(SelectableChannel channel, ByteBuffer byteBuffer, long readTimeout)
          Method reads data from SelectableChannel to ByteBuffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERBOSE_TESTS

public static boolean VERBOSE_TESTS
Constructor Detail

Utils

public Utils()
Method Detail

lookupCharset

public static Charset lookupCharset(String charsetName)
Lookup a Charset by name. Fixes Charset concurrency issue (http://paul.vox.com/library/post/the-mysteries-of-java-character-set-performance.html)

Parameters:
charsetName -
Returns:
Charset

openSelector

public static Selector openSelector()
                             throws IOException
Throws:
IOException

readWithTemporarySelector

public static Utils.Result readWithTemporarySelector(SelectableChannel channel,
                                                     ByteBuffer byteBuffer,
                                                     long readTimeout)
                                              throws IOException
Method reads data from SelectableChannel to ByteBuffer. If data is not immediately available - channel will be reregistered on temporary Selector and wait maximum readTimeout milliseconds for data.

Parameters:
channel - SelectableChannel to read data from
byteBuffer - ByteBuffer to store read data to
readTimeout - maximum time in millis operation will wait for incoming data
Returns:
number of bytes were read
Throws:
IOException - if any error was occured during read
IOException

extractBytes

public static byte[] extractBytes(ByteBuffer byteBuffer,
                                  byte startByte,
                                  byte endByte)
Return the bytes contained between the startByte and the endByte. The ByteBuffer will be left in the state it was before invoking that method, meaning its position and limit will be the same.

Parameters:
byteBuffer - The bytes.
startByte - the first byte to look for
endByte - the second byte to look for
Returns:
The byte[] contained between startByte and endByte

findBytes

public static int findBytes(ByteBuffer byteBuffer,
                            byte[] b)
Specialized utility method: find a sequence of lower case bytes inside a ByteBuffer.


findBytes

public static int findBytes(ByteBuffer bb,
                            Pattern pattern)

isDebugVM

public static boolean isDebugVM()

dumpOut

public static void dumpOut(Object text)

dumpErr

public static void dumpErr(Object text)

copy

public static byte[] copy(byte[] src)


Copyright © 2012 Oracle Corporation. All Rights Reserved.