org.apache.mina.proxy.utils
Class ByteUtilities

java.lang.Object
  extended by org.apache.mina.proxy.utils.ByteUtilities

public class ByteUtilities
extends Object

ByteUtilities.java - Byte manipulation functions.

Since:
MINA 2.0.0-M3
Version:
$Rev: 685703 $, $Date: 2008-08-14 00:14:47 +0200 (Do, 14 Aug 2008) $
Author:
The Apache MINA Project (dev@mina.apache.org)

Constructor Summary
ByteUtilities()
           
 
Method Summary
static byte[] asByteArray(String hex)
           
static String asHex(byte[] bytes)
           
static String asHex(byte[] bytes, String separator)
           
static void changeByteEndianess(byte[] b, int offset, int length)
           
static void changeWordEndianess(byte[] b, int offset, int length)
           
static byte[] encodeString(String s, boolean useUnicode)
           
static byte[] getOEMStringAsByteArray(String s)
           
static byte[] getUTFStringAsByteArray(String s)
           
static byte[] intToNetworkByteOrder(int num, byte[] buf, int start, int count)
          Encodes an integer into 4 bytes in network byte order in the buffer supplied.
static boolean isFlagSet(int flagSet, int testFlag)
          Return true if the flag testFlag is set in the flags flagset.
static int makeIntFromByte2(byte[] b)
           
static int makeIntFromByte2(byte[] b, int offset)
           
static int makeIntFromByte4(byte[] b)
           
static int makeIntFromByte4(byte[] b, int offset)
           
static int networkByteOrderToInt(byte[] buf, int start, int count)
          Returns the integer represented by 4 bytes in network byte order.
static byte[] writeInt(int v)
          Write a 32 bit int as LITTLE_ENDIAN.
static byte[] writeInt(int v, byte[] b, int offset)
          Write a 32 bit int as LITTLE_ENDIAN to the given array b at offset offset.
static byte[] writeShort(short v)
          Write a 16 bit short as LITTLE_ENDIAN.
static byte[] writeShort(short v, byte[] b, int offset)
          Write a 16 bit short as LITTLE_ENDIAN to the given array b at offset offset.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ByteUtilities

public ByteUtilities()
Method Detail

networkByteOrderToInt

public static int networkByteOrderToInt(byte[] buf,
                                        int start,
                                        int count)
Returns the integer represented by 4 bytes in network byte order.


intToNetworkByteOrder

public static byte[] intToNetworkByteOrder(int num,
                                           byte[] buf,
                                           int start,
                                           int count)
Encodes an integer into 4 bytes in network byte order in the buffer supplied.


writeShort

public static final byte[] writeShort(short v)
Write a 16 bit short as LITTLE_ENDIAN.

Parameters:
v - the short to write

writeShort

public static final byte[] writeShort(short v,
                                      byte[] b,
                                      int offset)
Write a 16 bit short as LITTLE_ENDIAN to the given array b at offset offset.

Parameters:
v - the short to write

writeInt

public static final byte[] writeInt(int v)
Write a 32 bit int as LITTLE_ENDIAN.

Parameters:
v - the int to write

writeInt

public static final byte[] writeInt(int v,
                                    byte[] b,
                                    int offset)
Write a 32 bit int as LITTLE_ENDIAN to the given array b at offset offset.

Parameters:
v - the int to write

changeWordEndianess

public static final void changeWordEndianess(byte[] b,
                                             int offset,
                                             int length)

changeByteEndianess

public static final void changeByteEndianess(byte[] b,
                                             int offset,
                                             int length)

getOEMStringAsByteArray

public static final byte[] getOEMStringAsByteArray(String s)
                                            throws UnsupportedEncodingException
Throws:
UnsupportedEncodingException

getUTFStringAsByteArray

public static final byte[] getUTFStringAsByteArray(String s)
                                            throws UnsupportedEncodingException
Throws:
UnsupportedEncodingException

encodeString

public static final byte[] encodeString(String s,
                                        boolean useUnicode)
                                 throws UnsupportedEncodingException
Throws:
UnsupportedEncodingException

asHex

public static String asHex(byte[] bytes)

asHex

public static String asHex(byte[] bytes,
                           String separator)

asByteArray

public static byte[] asByteArray(String hex)

makeIntFromByte4

public static final int makeIntFromByte4(byte[] b)

makeIntFromByte4

public static final int makeIntFromByte4(byte[] b,
                                         int offset)

makeIntFromByte2

public static final int makeIntFromByte2(byte[] b)

makeIntFromByte2

public static final int makeIntFromByte2(byte[] b,
                                         int offset)

isFlagSet

public static final boolean isFlagSet(int flagSet,
                                      int testFlag)
Return true if the flag testFlag is set in the flags flagset.

Parameters:
flagset - the flagset to test
testFlag - the flag we search the presence of
Returns:
true if testFlag is present in the flagset, false otherwise.


Copyright © 2004-2010 Apache MINA Project. All Rights Reserved.