Java Array Truncate truncateBytes(byte[] inputBytes)

Here you can find the source of truncateBytes(byte[] inputBytes)

Description

truncate Bytes

License

Open Source License

Declaration

public static byte[] truncateBytes(byte[] inputBytes) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static byte[] truncateBytes(byte[] inputBytes) {
        assert inputBytes != null;
        assert inputBytes.length > 1;

        int offsetLocation = inputBytes[inputBytes.length - 1] & 0x0F;

        assert offsetLocation >= 0;
        assert offsetLocation + 3 < inputBytes.length;

        byte[] truncated = new byte[4];
        truncated[0] = (byte) (inputBytes[offsetLocation] & 0x7F);
        truncated[1] = inputBytes[offsetLocation + 1];
        truncated[2] = inputBytes[offsetLocation + 2];
        truncated[3] = inputBytes[offsetLocation + 3];
        assert (truncated[0] & 0x80) != 0x80;
        return truncated;
    }/*  ww  w  . j a  v a  2  s.c  om*/
}

Related

  1. truncate(final byte[] arr, final int len)
  2. truncate(int[] array, int maxLen)
  3. truncate(int[] values, int value)
  4. truncate(short[] value, int maxSize)
  5. truncateAndConvertToInt(long[] longArray)
  6. truncateByteSegment(byte[] byteSegment, int toSize)
  7. truncateData(byte[] data, int numOfBytes)
  8. truncateHashToLong(byte[] bytes)
  9. truncateI(long[] v, int len)