Package com.wowza.util
Class BufferUtils
- Object
- 
- com.wowza.util.BufferUtils
 
- 
 public class BufferUtils extends ObjectBufferUtils: utilities for converting between binary data and Java primitive types. Faster than Java runtime equivalents 
- 
- 
Field SummaryFields Modifier and Type Field Description static String[]alphasstatic String[]hexadecimal
 - 
Constructor SummaryConstructors Constructor Description BufferUtils()
 - 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static intbyteArrayToInt(byte[] b)Convert byte array to intstatic intbyteArrayToInt(byte[] b, int offset)Conver byte array to int with offsetstatic intbyteArrayToInt(byte[] b, int offset, int count)Convert byte array to int with offset.static intbyteArrayToInt(byte[] b, int offset, int count, boolean isReverse)Convert byte array to int with offset.static longbyteArrayToLong(byte[] b)Convert byte array to longstatic longbyteArrayToLong(byte[] b, int offset)Conver byte array to long with offsetstatic longbyteArrayToLong(byte[] b, int offset, int count)Convert byte array to long with offset.static longbyteArrayToLong(byte[] b, int offset, int count, boolean isReverse)Convert byte array to long with offset.static intbyteArrayToShort(byte[] b)Convert byte array to intstatic intbyteArrayToShort(byte[] b, int offset)Conver byte array to int with offsetstatic intbyteArrayToShort(byte[] b, int offset, int count)Convert byte array to int with offset.static intbyteArrayToShort(byte[] b, int offset, int count, boolean isReverse)Convert byte array to int with offset.static StringbyteArrayToString(byte[] b)Convert a byte array to a String (UTF-8 encoding assumed)static StringbyteArrayToString(byte[] b, int offset, int count)Convert a byte array to a String (UTF-8 encoding assumed)static StringbyteArrayToString(byte[] b, int offset, int count, String charsetName)Convert a byte array to a Stringstatic byte[]decodeHexString(String hexStr)Decode a string as a byte arraystatic intdoCRC32(int crc, byte[] buffer, int offset, int len)Calculate an IEEE CRC32 value for MPEG transport stream from a starting crc valuestatic StringencodeHexString(byte[] bytes)Encode a byte array as a stringstatic StringencodeHexString(byte[] bytes, int offset, int len)Encode a byte array as a stringstatic intgetUnsignedShort(java.nio.ByteBuffer buffer)static intindexOf(byte[] source, byte[] pattern)Finds the first occurrence of a byte pattern in a byte buffer.static intindexOfDifferent(byte[] buffer1, byte[] buffer2)Compare two byte buffers, and return the index of the first byte that is different.static byte[]intToByteArray(int value)Convert a int value to a byte array in network orderstatic voidintToByteArray(int value, byte[] buffer, int offset, int size)Convert a int value to a byte array in network orderstatic voidintToByteArray(int value, byte[] buffer, int offset, int size, boolean isReverse)Convert a int value to a byte array in network orderstatic byte[]intToByteArray(int value, int size)Convert a int value to a byte array in network orderstatic byte[]longToByteArray(long value)Convert a long value to a byte array in network orderstatic voidlongToByteArray(long value, byte[] buffer, int offset, int size)Convert a long value to a byte array in network orderstatic voidlongToByteArray(long value, byte[] buffer, int offset, int size, boolean isReverse)Convert a long value to a byte array in network orderstatic byte[]longToByteArray(long value, int size)Convert a long value to a byte array in network orderstatic booleanpatternMatches(byte[] source, int offset, byte... pattern)static booleanstartsWith(byte[] source, byte[] pattern)
 
- 
- 
- 
Method Detail- 
encodeHexStringpublic static String encodeHexString(byte[] bytes) Encode a byte array as a string- Parameters:
- bytes- byte array
- Returns:
- string
 
 - 
encodeHexStringpublic 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
 
 - 
decodeHexStringpublic static byte[] decodeHexString(String hexStr) Decode a string as a byte array- Parameters:
- hexStr- string
- Returns:
- byte array
 
 - 
byteArrayToStringpublic static String byteArrayToString(byte[] b) Convert a byte array to a String (UTF-8 encoding assumed)- Parameters:
- b- byte array
- Returns:
- resultant string
 
 - 
byteArrayToStringpublic 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
 
 - 
byteArrayToStringpublic static String byteArrayToString(byte[] b, int offset, int count, String charsetName)Convert a byte array to a String- Parameters:
- b- byte array
- offset- offset
- count- len
- charsetName- character set name
- Returns:
- resultant string
 
 - 
byteArrayToLongpublic static long byteArrayToLong(byte[] b) Convert byte array to long- Parameters:
- b- byte array (8 bytes)
- Returns:
- long value
 
 - 
byteArrayToLongpublic 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
 
 - 
byteArrayToLongpublic 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
 
 - 
byteArrayToLongpublic 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
 
 - 
byteArrayToIntpublic static int byteArrayToInt(byte[] b) Convert byte array to int- Parameters:
- b- byte array (4 bytes)
- Returns:
- int value
 
 - 
byteArrayToIntpublic 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
 
 - 
byteArrayToIntpublic 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
 
 - 
byteArrayToIntpublic 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
 
 - 
byteArrayToShortpublic static int byteArrayToShort(byte[] b) Convert byte array to int- Parameters:
- b- byte array (2 bytes)
- Returns:
- int value
 
 - 
byteArrayToShortpublic 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
 
 - 
byteArrayToShortpublic 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
 
 - 
byteArrayToShortpublic 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
 
 - 
intToByteArraypublic 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
 
 - 
intToByteArraypublic 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
 
 - 
intToByteArraypublic 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
 
 - 
intToByteArraypublic 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
 
 - 
longToByteArraypublic 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
 
 - 
longToByteArraypublic 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
 
 - 
longToByteArraypublic 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
 
 - 
longToByteArraypublic 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
 
 - 
getUnsignedShortpublic static int getUnsignedShort(java.nio.ByteBuffer buffer) 
 - 
doCRC32public 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
 
 - 
indexOfpublic static int indexOf(byte[] source, byte[] pattern)Finds the first occurrence of a byte pattern in a byte buffer.Note: If we want to improve the performance, we could implement the Knuth-Morris-Pratt algorithm. But I don't need the speed nor do I have time today! - Parameters:
- source- The source byte buffer
- pattern- the pattern we're looking for.
- Returns:
- the index of source where the pattern is found, else -1
 
 - 
patternMatchespublic static boolean patternMatches(byte[] source, int offset, byte... pattern)- Parameters:
- source- byte array, which is to be searched
- offset- offset that the pattern will be matched from
- pattern- variable number of bytes to look for from index
- Returns:
- Return true if the input pattern matches from offset in the byte array passed in. Otherwise, return false.
 
 - 
indexOfDifferentpublic static int indexOfDifferent(byte[] buffer1, byte[] buffer2)Compare two byte buffers, and return the index of the first byte that is different.- Parameters:
- buffer1- byte array1
- buffer2- byte array2
- Returns:
- index where buffers differ, or -1.
 
 - 
startsWithpublic static boolean startsWith(byte[] source, byte[] pattern)
 
- 
 
-