Initial Commit. Added all the source files. Enjoy ;)
This commit is contained in:
parent
de0ad57063
commit
d6f7eb9591
8 changed files with 877 additions and 0 deletions
58
src/ArrayUtils.java
Normal file
58
src/ArrayUtils.java
Normal file
|
@ -0,0 +1,58 @@
|
|||
|
||||
|
||||
public class ArrayUtils
|
||||
{
|
||||
public static boolean arrayIsPartOfOtherArrayOnOffset(byte[] src, byte[] part, int offset)
|
||||
{
|
||||
if(offset<0 || part.length+offset > src.length) return false;
|
||||
for(int i=0; i<part.length; i++)
|
||||
{
|
||||
if(part[i] != src[i+offset]) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static char[] bytesToChars(byte[] b)
|
||||
{
|
||||
char[] c = new char[b.length];
|
||||
for(int i=0; i<b.length; i++)
|
||||
c[i] = (char) b[i];
|
||||
return c;
|
||||
}
|
||||
|
||||
public static byte[] charsToBytes(char[] c)
|
||||
{
|
||||
byte[] b = new byte[c.length];
|
||||
for(int i=0; i<c.length; i++)
|
||||
b[i] = (byte) c[i];
|
||||
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;
|
||||
byte[] c = new byte[aLen+bLen];
|
||||
System.arraycopy(out, 0, c, 0, aLen);
|
||||
System.arraycopy(bs, 0, c, aLen, bLen);
|
||||
return c;
|
||||
}
|
||||
|
||||
public static final byte[] intToByteArray(int value) {
|
||||
return new byte[] {
|
||||
(byte)(value >>> 24),
|
||||
(byte)(value >>> 16),
|
||||
(byte)(value >>> 8),
|
||||
(byte)value};
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue