code: static public int longToBytes(long l, byte[] buffer, int index) {
          int length = buffer.length - index;
          if (length > 8) length = 8;
          for (int i = 0; i < length; i++) {
              buffer[index + length - i - 1] = (byte) (l >> (i * 8));
          }
          return length;
      }
docs: This function converts a long into its corresponding byte format and inserts
  it into the specified buffer at the specified index.
  
  @param l The long to be converted.
  @param buffer The byte array.
  @param index The index in the array to begin inserting bytes.
  @return The number of bytes inserted.