Converts a byte array to an int value.

@param data  byte array to be converted
@return  int value of the byte array
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;
    }
100775
public static int readLen(byte[] data) {
        if (data.length < Datagram.HEADER_LEN) {
            log.warn("要读取长度的数据报报头不完整");
            return -1;
        } else {
            return convert(data, Datagram.LEN_OFFSET);
        }
    }
465181
public static byte[] intToBytes(int value) {
        byte[] result = new byte[4];
        result[0] = (byte)(value >> 24 & 0xff);
        result[1] = (byte)(value >> 16 & 0xff);
        result[2] = (byte)(value >> 8 & 0xff);
        result[3] = (byte)(value & 0xff);
        return result;
    }
407987
public static byte[] encode(byte[] data)
	{
		int sourceChunks = data.length / 3;
		int len = (data.length + 2) / 3 * 4;
		byte[] result = new byte[len];
		int extraBytes = data.length - sourceChunks * 3;
		// Each 4 bytes of input (encoded) we end up with 3 bytes of output
		int dataIndex = 0;
		int resultIndex = 0;
		int allBits = 0;
		for (int i = 0; i < sourceChunks; i++)
		{
			allBits = 0;
			// Loop 3 times gathering input bits (3 * 8 = 24)
			for (int j = 0; j < 3; j++)
			{
				allBits = allBits << 8 | data[dataIndex++] & 0xff;
			}
			// Loop 4 times generating output bits (4 * 6 = 24)
			for (int j = resultIndex + 3; j >= resultIndex; j--)
			{
				result[j] = (byte) digits[allBits & 0x3f]; // Bottom
				// 6
				// bits
				allBits = allBits >>> 6;
			}
			resultIndex += 4; // processed 4 result bytes
		}
		// Now we do the extra bytes in case the original (non-encoded) data
		// is not multiple of 4 bytes
		switch (extraBytes)
		{
			case 1:
				allBits = data[dataIndex++]; // actual byte
				allBits = allBits << 8; // 8 bits of zeroes
				allBits = allBits << 8; // 8 bits of zeroes
				// Loop 4 times generating output bits (4 * 6 = 24)
				for (int j = resultIndex + 3; j >= resultIndex; j--)
				{
					result[j] = (byte) digits[allBits & 0x3f]; // Bottom
					// 6
					// bits
					allBits = allBits >>> 6;
				}
				// 2 pad tags
				result[result.length - 1] = equalSign;
				result[result.length - 2] = equalSign;
				break;
			case 2:
				allBits = data[dataIndex++]; // actual byte
				allBits = allBits << 8 | data[dataIndex++] & 0xff; // actual
				// byte
				allBits = allBits << 8; // 8 bits of zeroes
				// Loop 4 times generating output bits (4 * 6 = 24)
				for (int j = resultIndex + 3; j >= resultIndex; j--)
				{
					result[j] = (byte) digits[allBits & 0x3f]; // Bottom
					// 6
					// bits
					allBits = allBits >>> 6;
				}
				// 1 pad tag
				result[result.length - 1] = equalSign;
				break;
		}
		return result;
	}
1155441
public static int byteArrayToIntLE( byte[] data ) {
        ByteBuffer buffer = ByteBuffer.wrap(data);
        buffer.order(ByteOrder.LITTLE_ENDIAN);
        return buffer.getInt();
    }
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;
   }
92603
public static int convert(byte[] data, int start) {
        return (Byte.toUnsignedInt(data[start]) << 24) | (Byte.toUnsignedInt(data[start + 1]) << 16)
               | (Byte.toUnsignedInt(data[start + 2]) << 8) | Byte.toUnsignedInt(data[start + 3]);
    }
490083
public static byte[] increment(final byte[] data) {
		for (int i = 0; i < data.length && (data[i] += (byte)1) == 0; ++i);
		return data;
	}
1021785
public void fromBytes(byte[] data) {
        if (data == null || data.length != 4) {
            throw new IllegalArgumentException("invalid header data. It can't be null and the length must be 4 byte.");
        }
        this.packetBodyLength = (data[0] & 0xFF) | ((data[1] & 0xFF) << 8) | ((data[2] & 0xFF) << 16);
        this.setPacketSequenceNumber(data[3]);
    }
1063380
@Override
    public Float fromBytes(Class targetClass, byte[] data)
    {
        if (data == null || data.length != 4)
            return (float) 0x0;

        return Float.intBitsToFloat(toInt(data));
    }
715925
public static long readInt(byte[] data, int start) {
		long ret = (((long) (data[start] & 0xFF) << 24) & 0xFFFFFFFFL)
				| ((data[start + 1] & 0xFF) << 16)
				| ((data[start + 2] & 0xFF) << 8)
				| ((data[start + 3] & 0xFF) << 0);

		return ret;
	}
596145
public static String toHexString(byte[] data) {
    StringBuilder sb = new StringBuilder(data.length * 2);
    for (byte element : data) {
      sb.append(Integer.toHexString((element >> 4) & 15));
      sb.append(Integer.toHexString(element & 15));
    }
    return sb.toString();
  }
294204
public static int parseInt(byte[] bytes) {
        int result = 0;
        for (byte aByte : bytes) {
            if (aByte == ' ') return result;

            result *= 10;
            result += (aByte - (byte) '0');
        }

        return result;
    }
631162
static public int unpackInt(DataInput in) throws IOException {
        int ret = 0;
        byte v;
        do{
            v = in.readByte();
            ret = (ret<<7 ) | (v & 0x7F);
        }while((v&0x80)==0);

        return ret;
    }
105034
public static int parseBE4BytesAsInt(byte[] data, int offset)
    {
        int value = ((data[offset + 0] & 0xFF) << 24)
                  | ((data[offset + 1] & 0xFF) << 16)
                  | ((data[offset + 2] & 0xFF) <<  8)
                  | ((data[offset + 3] & 0xFF));

        return value;
    }
275348
public void readArray(int[] data) throws IOException {
        int size = data.length;
        for (int i = 0; i < size; ++i)
            data[i] = getInt();
    }
1055719
@Override
    public Double fromBytes(Class targetClass, byte[] data)
    {
        if (data == null || data.length != 8)
            return (double) 0x0;

        return Double.longBitsToDouble(toLong(data));
    }