Convert a byte array to an int, trimming any whitespace. Null input
will return a -1. Invalid numbers will throw a NumberFormatException.

@param data
@return int
17249
public static final int asInt(byte[] data) {
        if (null == data) {
            return -1;
        }

        int start = 0;
        // skip leading whitespace
        for (; start < data.length; start++) {
            if (' ' != data[start] || '\t' == data[start]) {
                break;
            }
        }
        // skip trailing whitespace
        int i = data.length - 1;
        for (; start <= i; i--) {
            if (' ' != data[i] && '\t' != data[i]) {
                break;
            }
        }
        if (i <= start) {
            // empty content
            return -1;
        }
        int intVal = 0;
        int mark = 1;
        int digit;
        for (; start <= i; i--) {
            digit = data[i] - '0';
            if (0 > digit || 9 < digit) {
                // stop on any nondigit, if it's not a dash then throw an exc
                if ('-' != data[i]) {
                    throw new NumberFormatException("Invalid digit: " + data[i]);
                }
                break;
            }
            intVal += digit * mark;
            mark *= 10;
        }
        if (start < i) {
            // didn't use the whole content...
            throw new NumberFormatException("Invalid data");
        }

        // check for negative numbers
        if (start == i && data[i] == '-') {
            intVal = -intVal;
        }

        return intVal;
    }
715718
protected static byte[] getData(byte[] data, int size) {
        if (data == null) {
            return NO_DATA;
        }
        if (data.length <= size) {
            return data;
        }
        byte[] newData = new byte[size];
        System.arraycopy(data, 0, newData, 0, size);
        return newData;
    }
444114
public static byte[] hexStringToBytes(String data) {
        if (data == null)
            return EMPTY_BYTE_ARRAY;
        if (data.startsWith("0x"))
            data = data.substring(2);
        return Hex.decode(data);
    }
937711
public static final int readInt(byte[] array, int offset)
    {
        if (array.length < offset + 4)
        {
            throw new IllegalArgumentException("no room in array");
        }
        return
                ((array[offset]<<24) & 0xff000000) +
                ((array[offset + 1]<<16) & 0xff0000)  +
                ((array[offset + 2]<<8) & 0xff00)  +
                (array[offset + 3] & 0xff );
    }
689299
public static String encode(byte[] data, int size)
    {
        if (size % 4 != 0) {
            return null;
        }
        StringBuilder builder = new StringBuilder();
        int byteNbr = 0;
        long value = 0;
        while (byteNbr < size) {
            //  Accumulate value in base 256 (binary)
            int d = data[byteNbr++] & 0xff;
            value = value * 256 + d;
            if (byteNbr % 4 == 0) {
                //  Output value in base 85
                int divisor = 85 * 85 * 85 * 85;
                while (divisor != 0) {
                    int index = (int) (value / divisor % 85);
                    builder.append(encoder.charAt(index));
                    divisor /= 85;
                }
                value = 0;
            }
        }
        assert (builder.length() == size * 5 / 4);
        return builder.toString();
    }
1322732
public static float byteArrayToFloatLE( byte[] data ) {
        ByteBuffer buffer = ByteBuffer.wrap(data);
        buffer.order(ByteOrder.LITTLE_ENDIAN);
        return buffer.getFloat();
    }
1209508
public static final Double getPercentage(byte[] data, int offset)
   {
      int value = MPPUtility.getShort(data, offset);
      Double result = null;
      if (value >= 0 && value <= 100)
      {
         result = NumberHelper.getDouble(value);
      }
      return result;
   }
1012878
public static long byteArrayToLongBE( byte[] data ) {
        if (data == null)
            return 0x0;
        long accum = 0;
        int shiftBy = 8 * data.length - 8;
        for( byte b : data ) {
            accum |= (long) (0xff & b) << shiftBy;
            shiftBy -= 8;
        }
        return accum;
    }
1091100
public static String encode(byte[] data) {
        if (data.length == 0) {
            return "";
        }
        final byte[] bytes = copyOfRange(data, 0, data.length);
        // Count leading zeroes.
        int zeroCount = 0;
        while (zeroCount < bytes.length && bytes[zeroCount] == 0) {
            ++zeroCount;
        }
        // The actual encoding.
        byte[] temp = new byte[bytes.length * 2];
        int j = temp.length;

        int startAt = zeroCount;
        while (startAt < bytes.length) {
            byte mod = divmod58(bytes, startAt);
            if (bytes[startAt] == 0) {
                ++startAt;
            }
            temp[--j] = (byte) ALPHABET[mod];
        }

        // Strip extra '1' if there are some after decoding.
        while (j < temp.length && temp[j] == ALPHABET[0]) {
            ++j;
        }
        // Add as many leading '1' as there were leading zeros.
        while (--zeroCount >= 0) {
            temp[--j] = (byte) ALPHABET[0];
        }

        byte[] output = copyOfRange(temp, j, temp.length);
        try {
            return new String(output, "US-ASCII");
        } catch (UnsupportedEncodingException e) {
            throw new ApplicationException(e);  // Cannot happen.
        }
    }
567748
public static final Double getDouble(byte[] data, int offset)
   {
      Double result = null;
      long longValue = getLong(data, offset);
      if (longValue != NULL_DOUBLE)
      {
         double doubleValue = Double.longBitsToDouble(longValue);
         if (!Double.isNaN(doubleValue))
         {
            result = Double.valueOf(doubleValue);
         }
      }
      return result;
   }
800239
public static byte[] longToByteArrayBE( long data ) {
        return new byte[]{(byte) ((data >> 56) & 0xff), (byte) ((data >> 48) & 0xff), (byte) ((data >> 40) & 0xff),
                (byte) ((data >> 32) & 0xff), (byte) ((data >> 24) & 0xff), (byte) ((data >> 16) & 0xff),
                (byte) ((data >> 8) & 0xff), (byte) ((data >> 0) & 0xff),};
    }
328910
private static int byteArrayToInt(byte[] data)
    {
        // byte[] -> int
        int number = 0;
        for (int i = 0; i < 4; ++i)
        {
            number |= (data[3-i] & 0xff) << (i << 3);
        }
        return number;
    }
1332664
public static short byteArrayToShortLE( byte[] data ) {
        ByteBuffer buffer = ByteBuffer.wrap(data);
        buffer.order(ByteOrder.LITTLE_ENDIAN);
        return buffer.getShort();
    }
721014
public static String convertBytesToHexString(byte[] data)
    {
        StringBuilder buffer = new StringBuilder(data.length * 2);
        for (byte b : data)
        {
            buffer.append(HEX_CHARS[(b >>> 4) & 0x0F]);
            buffer.append(HEX_CHARS[b & 0x0F]);
        }
        return buffer.toString();
    }
1155441
public static int byteArrayToIntLE( byte[] data ) {
        ByteBuffer buffer = ByteBuffer.wrap(data);
        buffer.order(ByteOrder.LITTLE_ENDIAN);
        return buffer.getInt();
    }
94298
static int decodeDigit(byte data)
	{
		char charData = (char) data;
		if (charData <= 'Z' && charData >= 'A')
		{
			return charData - 'A';
		}
		if (charData <= 'z' && charData >= 'a')
		{
			return charData - 'a' + 26;
		}
		if (charData <= '9' && charData >= '0')
		{
			return charData - '0' + 52;
		}
		switch (charData)
		{
			case '+':
				return 62;
			case '/':
				return 63;
			default:
				throw new IllegalArgumentException("Invalid char to decode: " + data); //$NON-NLS-1$
		}
	}
1110728
public ScriptBuilder data(byte[] data) {
        if (data.length == 0)
            return smallNum(0);
        else
            return data(chunks.size(), data);
    }