Package gnu.java.zrtp.utils
Class ZrtpUtils
- java.lang.Object
-
- gnu.java.zrtp.utils.ZrtpUtils
-
public class ZrtpUtils extends Object
Some helpful functions, all public static- Author:
- Werner Dittmann <Werner.Dittmann@t-online.de>
-
-
Constructor Summary
Constructors Constructor Description ZrtpUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static intbyteArrayCompare(byte[] arg1, byte[] arg2, int length)static char[]bytesToHexString(byte[] in, int length)static voidhexdump(String title, byte[] buf, int len)Dump a buffer in hex and readable format.static byte[]int32ToArray(int data)Convert a 32 bit integer into a byte array, network order.static voidint32ToArrayInPlace(int data, byte[] buffer, int offset)Convert a 32 bit integer into a byte array, network order.static intreadInt(byte[] buffer, int offset)Extract four bytes from a buffer and convert into an integer.static byte[]readRegion(byte[] buffer, int offset, int length)Read a byte region from specified offset with specified lengthstatic shortreadShort(byte[] buffer, int offset)Extract two bytes from a buffer and convert into a short integer.static byte[]short16ToArray(int data)Convert a 16 bit integer into a byte array, network order.static voidshort16ToArrayInPlace(int data, byte[] buffer, int offset)Convert a 16 bit integer into a byte array, network order.
-
-
-
Method Detail
-
int32ToArray
public static byte[] int32ToArray(int data)
Convert a 32 bit integer into a byte array, network order.- Parameters:
data- the 32 bit integer to send over the network- Returns:
- the byte array conating the converted integer
-
int32ToArrayInPlace
public static void int32ToArrayInPlace(int data, byte[] buffer, int offset)Convert a 32 bit integer into a byte array, network order. This method places the converted four bytes into the buffer starting at the given offset.- Parameters:
data- the 32 bit integer to send over the networkbuffer- the byte array that receives the converted integeroffset- the offset into the buffer
-
short16ToArray
public static byte[] short16ToArray(int data)
Convert a 16 bit integer into a byte array, network order.- Parameters:
data- the 16 bit integer to send over the network- Returns:
- the byte array conating the converted short integer
-
short16ToArrayInPlace
public static void short16ToArrayInPlace(int data, byte[] buffer, int offset)Convert a 16 bit integer into a byte array, network order.- Parameters:
data- the 16 bit integer to send over the network
-
readShort
public static short readShort(byte[] buffer, int offset)Extract two bytes from a buffer and convert into a short integer. The method reads 2 bytes from the buffer starting at the specified offset and converts it into a short integer. The buffer contains the bytes in network order.- Parameters:
buffer- The buffer containing the bytes in network order.offset- Offset into buffer.
-
readInt
public static int readInt(byte[] buffer, int offset)Extract four bytes from a buffer and convert into an integer. The method reads 4 bytes from the buffer starting at the specified offset and converts it into a integer. The buffer contains the bytes in network order.- Parameters:
buffer- The buffer containing the bytes in network order.offset- Offset into buffer.
-
readRegion
public static byte[] readRegion(byte[] buffer, int offset, int length)Read a byte region from specified offset with specified length- Parameters:
buffer- the buffer to copy fromoffset- start offset of the region to be readlength- length of the region to be read- Returns:
- byte array of [offset, offset + length)
-
hexdump
public static void hexdump(String title, byte[] buf, int len)
Dump a buffer in hex and readable format.- Parameters:
title- Printed at the beginning of the dumpbuf- Byte buffer to dumplen- Number of bytes to dump, should be less or equal the buffer length
-
bytesToHexString
public static char[] bytesToHexString(byte[] in, int length)
-
byteArrayCompare
public static int byteArrayCompare(byte[] arg1, byte[] arg2, int length)
-
-