public static int putLong(OutputStream out, final long value, final int fitInBytes)
    throws IOException {
    long tmpValue = value;
    for (int i = 0; i < fitInBytes; ++i) {
      out.write((byte) (tmpValue & 0xff));
      tmpValue >>>= 8;
    }
    return fitInBytes;
  }
Copy data from a buffer to an output stream. Does not update the position in the buffer.
@param out    the output stream to write bytes to
@param in     the buffer to read bytes from
@param offset the offset in the buffer (from the buffer's array offset) to start copying bytes
              from
@param length the number of bytes to copy
hbase-common/src/main/java/org/apache/hadoop/hbase/util/ByteBufferUtils.java