public static int byteArrayToInt(byte[] b, int offset) {
    int value = 0;
    for (int i = 0; i < 4; i++) {
      int shift = (4 - 1 - i) * 8;
      value += (b[i + offset] & 0x000000FF) << shift;
    }
    return value;
  }
Convert the byte array to an int starting from the given offset. Refer to
code by aeden on DZone Snippets:

@param b
         the byte array
@param offset
         the array offset
@return the integer
serde/src/java/org/apache/hadoop/hive/serde2/lazybinary/LazyBinaryUtils.java