public static byte[] toBytes(int val) {
    byte[] b = new byte[4];
    for (int i = 3; i > 0; i--) {
      b[i] = (byte) val;
      val >>>= 8;
    }
    b[0] = (byte) val;
    return b;
  }
Convert an int value to a byte array. Big-endian. Same as what DataOutputStream.writeInt does.
@param val value
@return the byte array
hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java