public static void writeUTF8(OutputStream out, long i) throws IOException {
    if (i == 0) {
      out.write('0');
      return;
    }

    boolean negative = i < 0;
    if (negative) {
      out.write('-');
    } else {
      // negative range is bigger than positive range, so there is no risk
      // of overflow here.
      i = -i;
    }

    long start = 1000000000000000000L;
    while (i / start == 0) {
      start /= 10;
    }

    while (start > 0) {
      out.write('0' - (int) ((i / start) % 10));
      start /= 10;
    }
  }
Writes out the text representation of an integer using base 10 to an
OutputStream in UTF-8 encoding.

Note: division by a constant (like 10) is much faster than division by a
variable. That's one of the reasons that we don't make radix a parameter
here.

@param out
         the outputstream to write to
@param i
         an int to write out
@throws IOException
serde/src/java/org/apache/hadoop/hive/serde2/lazy/LazyLong.java