Commented a lot

This commit is contained in:
vanitasvitae 2015-04-13 22:42:16 +02:00
parent 94993a907f
commit d7ccf6883c
6 changed files with 470 additions and 53 deletions

View file

@ -2,6 +2,13 @@
public class ArrayUtils
{
/**
* Return true, if the array part is sub array of src from offset
* @param src array
* @param part array
* @param offset int
* @return true, if part is completely a subarray of src on offset offset, else false
*/
public static boolean arrayIsPartOfOtherArrayOnOffset(byte[] src, byte[] part, int offset)
{
if(offset<0 || part.length+offset > src.length) return false;
@ -12,6 +19,11 @@ public class ArrayUtils
return true;
}
/**
* converts the byte array b into a char array by casting all the bytes into chars
* @param b byte array
* @return char array
*/
public static char[] bytesToChars(byte[] b)
{
char[] c = new char[b.length];
@ -20,6 +32,11 @@ public class ArrayUtils
return c;
}
/**
* converts the char array into a byte array by casting all the chars into bytes
* @param c char array
* @return byte array
*/
public static byte[] charsToBytes(char[] c)
{
byte[] b = new byte[c.length];
@ -28,17 +45,28 @@ public class ArrayUtils
return b;
}
public static byte[] concatenate (byte[] out, byte[] bs) {
if(out == null) return bs;
if(bs == null) return out;
int aLen = out.length;
int bLen = bs.length;
/**
* concatenate two byte arrays
* @param first first byte array
* @param second second byte array
* @return first + second
*/
public static byte[] concatenate (byte[] first, byte[] second) {
if(first == null) return second;
if(second == null) return first;
int aLen = first.length;
int bLen = second.length;
byte[] c = new byte[aLen+bLen];
System.arraycopy(out, 0, c, 0, aLen);
System.arraycopy(bs, 0, c, aLen, bLen);
System.arraycopy(first, 0, c, 0, aLen);
System.arraycopy(second, 0, c, aLen, bLen);
return c;
}
/**
* convert an integer into a 32 bit byte array
* @param value integer
* @return byte array
*/
public static final byte[] intToByteArray(int value) {
return new byte[] {
(byte)(value >>> 24),
@ -47,12 +75,16 @@ public class ArrayUtils
(byte)value};
}
/**
* convert a signed byte array into an unsigned byte array (sort of)
* @param b byte array of signed bytes
* @return byte array of unsigned bytes
*/
public static byte[] unsign(byte[] b)
{
byte[] u = new byte[b.length];
for(int i=0; i<b.length; i++)
u[i] = (byte) (b[i]&0xFF);
return u;
}
}