|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectjBittorrentAPI.Utils
public class Utils
A set of utility methods used by the program
Constructor Summary | |
---|---|
Utils()
|
Method Summary | |
---|---|
static boolean[] |
byteArray2BitArray(byte[] bytes)
Convert a byte array to a boolean array. |
static java.lang.String |
byteArrayToByteString(byte[] in)
Convert a byte[] array to readable string format. |
static int |
byteArrayToInt(byte[] b)
Convert a byte array integer (4 bytes) to its int value |
static java.lang.String |
byteArrayToURLString(byte[] in)
Convert a byte array to a URL encoded string |
static boolean |
bytesCompare(byte[] a,
byte[] b)
Compare 2 byte arrays byte to byte |
static java.lang.String |
bytesToHex(byte[] data)
Convenience method to convert a byte array to a hex string. |
static java.lang.String |
byteToHex(byte data)
Convenience method to convert a byte to a hex string. |
static int |
byteToUnsignedInt(byte b)
|
static byte[] |
concat(byte[] b1,
byte b2)
Concatenate the byte array and the byte |
static byte[] |
concat(byte[] b1,
byte[] b2)
Concatenate the 2 byte arrays |
static byte[] |
concat2(byte[] a,
byte[] b)
Concatenate the 2 byte arrays |
static void |
copy(byte[] in,
byte[] out)
Copy the input byte array to the output byte array |
static byte[] |
generateID()
Generate the client id, which is a fixed string of length 8 concatenated with 12 random bytes |
static byte[] |
hash(byte[] hashThis)
Compute the SHA-1 hash of the given byte array |
static byte[] |
hash(java.nio.ByteBuffer hashThis)
Compute the SHA-1 hash of the bytes in the given buffer |
static byte[] |
intToByteArray(int value)
Convert an integer value to its byte array representation |
static byte[] |
intToByteArray4(int i)
|
static byte[] |
subArray(byte[] b,
int offset,
int length)
Return a subarray of the byte array in parameter. |
static byte[] |
toByteArray(java.util.BitSet bits)
|
static char |
toHexChar(int i)
Convenience method to convert an int to a hex char. |
static long |
unsignedIntToLong(byte[] b)
Convert a byte array representing an unsigned integer (4bytes) to its long value |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Utils()
Method Detail |
---|
public static boolean[] byteArray2BitArray(byte[] bytes)
bytes
- byte[]
public static java.lang.String byteArrayToByteString(byte[] in)
in
- byte[] buffer to convert to string format
public static int byteArrayToInt(byte[] b)
b
- byte[]
public static java.lang.String byteArrayToURLString(byte[] in)
in
- byte[]
public static boolean bytesCompare(byte[] a, byte[] b)
a
- byte[]b
- byte[]
public static java.lang.String bytesToHex(byte[] data)
data
- the byte[] to convert
public static java.lang.String byteToHex(byte data)
data
- the byte to convert
public static int byteToUnsignedInt(byte b)
public static byte[] concat(byte[] b1, byte b2)
b1
- byte[]b2
- byte
public static byte[] concat(byte[] b1, byte[] b2)
b1
- byte[]b2
- byte[]
public static byte[] concat2(byte[] a, byte[] b)
a
- byte[]b
- byte[]
public static void copy(byte[] in, byte[] out)
in
- byte[]out
- byte[]public static byte[] generateID()
public static byte[] hash(byte[] hashThis)
hashThis
- byte[]
public static byte[] hash(java.nio.ByteBuffer hashThis)
hashThis
- ByteBuffer
public static byte[] intToByteArray(int value)
value
- int
public static byte[] intToByteArray4(int i)
public static byte[] subArray(byte[] b, int offset, int length)
b
- The original arrayoffset
- Begin index of the subarraylength
- Length of the subarray
public static byte[] toByteArray(java.util.BitSet bits)
public static char toHexChar(int i)
i
- the int to convert
public static final long unsignedIntToLong(byte[] b)
b
- byte[]
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |