com.wowza.util
Class BufferUtils

Object
  extended by com.wowza.util.BufferUtils

public class BufferUtils
extends Object

BufferUtils: utilities for converting between binary data and Java primitive types. Faster than Java runtime equivalents


Constructor Summary
BufferUtils()
           
 
Method Summary
static int byteArrayToInt(byte[] b)
          Convert byte array to int
static int byteArrayToInt(byte[] b, int offset)
          Conver byte array to int with offset
static int byteArrayToInt(byte[] b, int offset, int count)
          Convert byte array to int with offset.
static int byteArrayToInt(byte[] b, int offset, int count, boolean isReverse)
          Convert byte array to int with offset.
static long byteArrayToLong(byte[] b)
          Convert byte array to long
static long byteArrayToLong(byte[] b, int offset)
          Conver byte array to long with offset
static long byteArrayToLong(byte[] b, int offset, int count)
          Convert byte array to long with offset.
static long byteArrayToLong(byte[] b, int offset, int count, boolean isReverse)
          Convert byte array to long with offset.
static int byteArrayToShort(byte[] b)
          Convert byte array to int
static int byteArrayToShort(byte[] b, int offset)
          Conver byte array to int with offset
static int byteArrayToShort(byte[] b, int offset, int count)
          Convert byte array to int with offset.
static int byteArrayToShort(byte[] b, int offset, int count, boolean isReverse)
          Convert byte array to int with offset.
static String byteArrayToString(byte[] b)
          Convert a byte array to a String (UTF-8 encoding assumed)
static String byteArrayToString(byte[] b, int offset, int count)
          Convert a byte array to a String (UTF-8 encoding assumed)
static byte[] decodeHexString(String hexStr)
          Decode a string as a byte array
static int doCRC32(int crc, byte[] buffer, int offset, int len)
          Calculate an IEEE CRC32 value for MPEG transport stream from a starting crc value
static String encodeHexString(byte[] bytes)
          Encode a byte array as a string
static String encodeHexString(byte[] bytes, int offset, int len)
          Encode a byte array as a string
static int getUnsignedShort(java.nio.ByteBuffer buffer)
           
static byte[] intToByteArray(int value)
          Convert a int value to a byte array in network order
static void intToByteArray(int value, byte[] buffer, int offset, int size)
          Convert a int value to a byte array in network order
static void intToByteArray(int value, byte[] buffer, int offset, int size, boolean isReverse)
          Convert a int value to a byte array in network order
static byte[] intToByteArray(int value, int size)
          Convert a int value to a byte array in network order
static byte[] longToByteArray(long value)
          Convert a long value to a byte array in network order
static void longToByteArray(long value, byte[] buffer, int offset, int size)
          Convert a long value to a byte array in network order
static void longToByteArray(long value, byte[] buffer, int offset, int size, boolean isReverse)
          Convert a long value to a byte array in network order
static byte[] longToByteArray(long value, int size)
          Convert a long value to a byte array in network order
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BufferUtils

public BufferUtils()
Method Detail

byteArrayToInt

public static int byteArrayToInt(byte[] b)
Convert byte array to int

Parameters:
b - byte array (4 bytes)
Returns:
int value

byteArrayToInt

public static int byteArrayToInt(byte[] b,
                                 int offset)
Conver byte array to int with offset

Parameters:
b - byte array (4 bytes)
offset - offset
Returns:
int value

byteArrayToInt

public static int byteArrayToInt(byte[] b,
                                 int offset,
                                 int count)
Convert byte array to int with offset. Count is the number of bytes. Can be less than 4. If less than 4 just fills lower bits in value.

Parameters:
b - byte array
offset - offset
count - number of bytes
Returns:
int value

byteArrayToInt

public static int byteArrayToInt(byte[] b,
                                 int offset,
                                 int count,
                                 boolean isReverse)
Convert byte array to int with offset. Count is the number of bytes. Can be less than 4. If less than 4 just fills lower bits in value. The reverse flag allows data to be in reverse order.

Parameters:
b - byte array
offset - offset
count - number of bytes
isReverse - is data in reverse order
Returns:
int value

byteArrayToLong

public static long byteArrayToLong(byte[] b)
Convert byte array to long

Parameters:
b - byte array (8 bytes)
Returns:
long value

byteArrayToLong

public static long byteArrayToLong(byte[] b,
                                   int offset)
Conver byte array to long with offset

Parameters:
b - byte array (8 bytes)
offset - offset
Returns:
long value

byteArrayToLong

public static long byteArrayToLong(byte[] b,
                                   int offset,
                                   int count)
Convert byte array to long with offset. Count is the number of bytes. Can be less than 8. If less than 8 just fills lower bits in value.

Parameters:
b - byte array
offset - offset
count - number of bytes
Returns:
long value

byteArrayToLong

public static long byteArrayToLong(byte[] b,
                                   int offset,
                                   int count,
                                   boolean isReverse)
Convert byte array to long with offset. Count is the number of bytes. Can be less than 8. If less than 8 just fills lower bits in value. The reverse flag allows data to be in reverse order.

Parameters:
b - byte array
offset - offset
count - number of bytes
isReverse - is data in reverse order
Returns:
long value

byteArrayToShort

public static int byteArrayToShort(byte[] b)
Convert byte array to int

Parameters:
b - byte array (2 bytes)
Returns:
int value

byteArrayToShort

public static int byteArrayToShort(byte[] b,
                                   int offset)
Conver byte array to int with offset

Parameters:
b - byte array (2 bytes)
offset - offset
Returns:
int value

byteArrayToShort

public static int byteArrayToShort(byte[] b,
                                   int offset,
                                   int count)
Convert byte array to int with offset. Count is the number of bytes. Can be less than 2. If less than 2 just fills lower bits in value.

Parameters:
b - byte array
offset - offset
count - number of bytes
Returns:
int value

byteArrayToShort

public static int byteArrayToShort(byte[] b,
                                   int offset,
                                   int count,
                                   boolean isReverse)
Convert byte array to int with offset. Count is the number of bytes. Can be less than 2. If less than 2 just fills lower bits in value. The reverse flag allows data to be in reverse order.

Parameters:
b - byte array
offset - offset
count - number of bytes
isReverse - is data in reverse order
Returns:
int value

byteArrayToString

public static String byteArrayToString(byte[] b)
Convert a byte array to a String (UTF-8 encoding assumed)

Parameters:
b - byte array
Returns:
resultant string

byteArrayToString

public static String byteArrayToString(byte[] b,
                                       int offset,
                                       int count)
Convert a byte array to a String (UTF-8 encoding assumed)

Parameters:
b - byte array
offset - offset
count - len
Returns:
resultant string

decodeHexString

public static byte[] decodeHexString(String hexStr)
Decode a string as a byte array

Parameters:
hexStr - string
Returns:
byte array

doCRC32

public static int doCRC32(int crc,
                          byte[] buffer,
                          int offset,
                          int len)
Calculate an IEEE CRC32 value for MPEG transport stream from a starting crc value

Parameters:
crc - starting crc value
buffer - buffer
offset - offset
len - len
Returns:
crc value

encodeHexString

public static String encodeHexString(byte[] bytes)
Encode a byte array as a string

Parameters:
bytes - byte array
Returns:
string

encodeHexString

public static String encodeHexString(byte[] bytes,
                                     int offset,
                                     int len)
Encode a byte array as a string

Parameters:
bytes - byte array
offset - offset
len - length
Returns:
string

getUnsignedShort

public static int getUnsignedShort(java.nio.ByteBuffer buffer)

intToByteArray

public static byte[] intToByteArray(int value)
Convert a int value to a byte array in network order

Parameters:
value - value
Returns:
4-byte array with value

intToByteArray

public static void intToByteArray(int value,
                                  byte[] buffer,
                                  int offset,
                                  int size)
Convert a int value to a byte array in network order

Parameters:
value - value
buffer - destination byte array
offset - starting offset in byte array
size - number of bytes to write

intToByteArray

public static void intToByteArray(int value,
                                  byte[] buffer,
                                  int offset,
                                  int size,
                                  boolean isReverse)
Convert a int value to a byte array in network order

Parameters:
value - value
buffer - destination byte array
offset - starting offset in byte array
size - number of bytes to write
isReverse - is data in reverse order

intToByteArray

public static byte[] intToByteArray(int value,
                                    int size)
Convert a int value to a byte array in network order

Parameters:
value - value
size - size of resultant byte array
Returns:
size-byte array with value

longToByteArray

public static byte[] longToByteArray(long value)
Convert a long value to a byte array in network order

Parameters:
value - value
Returns:
8-byte array with value

longToByteArray

public static void longToByteArray(long value,
                                   byte[] buffer,
                                   int offset,
                                   int size)
Convert a long value to a byte array in network order

Parameters:
value - value
buffer - destination byte array
offset - starting offset in byte array
size - number of bytes to write

longToByteArray

public static void longToByteArray(long value,
                                   byte[] buffer,
                                   int offset,
                                   int size,
                                   boolean isReverse)
Convert a long value to a byte array in network order

Parameters:
value - value
buffer - destination byte array
offset - starting offset in byte array
size - number of bytes to write
isReverse - is data in reverse order

longToByteArray

public static byte[] longToByteArray(long value,
                                     int size)
Convert a long value to a byte array in network order

Parameters:
value - value
size - size of resultant byte array
Returns:
size-byte array with value