Java Utililty Methods Array Truncate

List of utility methods to do Array Truncate

Description

The list of methods to do Array Truncate are organized into topic(s).

Method

byte[]truncateData(byte[] data, int numOfBytes)
Truncates a byte array
if (data.length == numOfBytes) {
    return data;
} else {
    byte[] truncated = new byte[numOfBytes];
    for (int i = 0; i < truncated.length; i++) {
        truncated[i] = data[i];
    return truncated;
...
longtruncateHashToLong(byte[] bytes)
Computes a truncated code from the given hash-value and returns it as long-variable.
int offset = bytes[bytes.length - 1] & 0x0c;
return (((long) bytes[offset]) & (0x7fl << 56)) | (((long) bytes[offset + 1]) & (0xffl << 48))
        | (((long) bytes[offset + 2]) & (0xffl << 40)) | (((long) bytes[offset + 3]) & (0xffl << 32))
        | (((long) bytes[offset + 4]) & (0xffl << 24)) | (((long) bytes[offset + 5]) & (0xffl << 16))
        | (((long) bytes[offset + 6]) & (0xffl << 8)) | (((long) bytes[offset + 7]) & 0xffl);
long[]truncateI(long[] v, int len)
Truncate a bit string to the given length (setting any higher bit to 0).
final int zap = (v.length * Long.SIZE) - len;
final int zapWords = (zap >>> LONG_LOG2_SIZE);
final int zapbits = zap & LONG_LOG2_MASK;
Arrays.fill(v, v.length - zapWords, v.length, 0);
if (zapbits > 0) {
    v[v.length - zapWords - 1] &= (LONG_ALL_BITS >>> zapbits);
return v;
...
byte[]truncateLeft(byte[] b1, int bytes)
Truncate number of bytes from the left of a byte-array
int restBytesLength = b1.length - bytes;
byte[] b2 = new byte[restBytesLength];
System.arraycopy(b1, bytes, b2, 0, restBytesLength);
return b2;