public static int putAsShort(byte[] bytes, int offset, int val) {
    if (bytes.length - offset < SIZEOF_SHORT) {
      throw new IllegalArgumentException("Not enough room to put a short at" + " offset " + offset
        + " in a " + bytes.length + " byte array");
    }
    bytes[offset + 1] = (byte) val;
    val >>= 8;
    bytes[offset] = (byte) val;
    return offset + SIZEOF_SHORT;
  }
Put an int value as short out to the specified byte array position. Only the lower 2 bytes of
the short will be put into the array. The caller of the API need to make sure they will not
loose the value by doing so. This is useful to store an unsigned short which is represented as
int in other parts.
@param bytes  the byte array
@param offset position in the array
@param val    value to write out
@return incremented offset
@throws IllegalArgumentException if the byte array given doesn't have enough room at the offset
                                 specified.
hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java