DepthMapNeedle/src/ArrayUtils.java

59 lines
1.2 KiB
Java

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;
}
}