public int format(long val,byte[] buf,int off,int len){
  if (val == Long.MIN_VALUE) {
    if (len > MAX_LONG_LENGTH) {
      return format("-9223372036854775808",buf,off,len);
    }
 else {
      truncationFiller(buf,off,len);
      return off + len;
    }
  }
  long pos=Math.abs(val);
  int ndig=1;
  long dmax=ByteFormatter.NUMBER_BASE;
  while (ndig < MAX_LONG_LENGTH && pos >= dmax) {
    ndig++;
    dmax*=ByteFormatter.NUMBER_BASE;
  }
  if (val < 0) {
    ndig++;
  }
  if (ndig > len || ndig > buf.length - off) {
    truncationFiller(buf,off,len);
    return off + len;
  }
  off+=ndig;
  int xoff=off - 1;
  buf[xoff]=(byte)'0';
  boolean last=pos == 0;
  while (!last) {
    int giga=(int)(pos % LONG_TO_INT_MODULO);
    pos/=LONG_TO_INT_MODULO;
    last=pos == 0;
    for (int i=0; i < MAXIMUM_SINGLE_DIGIT_INTEGER; i++) {
      buf[xoff]=ByteFormatter.DIGITS[giga % ByteFormatter.NUMBER_BASE];
      xoff--;
      giga/=ByteFormatter.NUMBER_BASE;
      if (last && giga == 0) {
        break;
      }
    }
  }
  if (val < 0) {
    buf[xoff]=(byte)'-';
  }
  return off;
}

public int format ( long val , byte [ ] buf , int off , int len ) { if ( val == Long . MIN_VALUE ) { if ( len > MAX_LONG_LENGTH ) { return format ( "-9223372036854775808" , buf , off , len ) ; } else { truncationFiller ( buf , off , len ) ; return off + len ; } } long pos = Math . abs ( val ) ; int ndig = 1 ; long dmax = ByteFormatter . NUMBER_BASE ; while ( ndig < MAX_LONG_LENGTH && pos >= dmax ) { ndig ++ ; dmax *= ByteFormatter . NUMBER_BASE ; } if ( val < 0 ) { ndig ++ ; } if ( ndig > len || ndig > buf . length - off ) { truncationFiller ( buf , off , len ) ; return off + len ; } off += ndig ; int xoff = off - 1 ; buf [ xoff ] = ( byte ) '0' ; boolean last = pos == 0 ; while ( ! last ) { int giga = ( int ) ( pos % LONG_TO_INT_MODULO ) ; pos /= LONG_TO_INT_MODULO ; last = pos == 0 ; for ( int i = 0 ; i < MAXIMUM_SINGLE_DIGIT_INTEGER ; i ++ ) { buf [ xoff ] = ByteFormatter . DIGITS [ giga % ByteFormatter . NUMBER_BASE ] ; xoff -- ; giga /= ByteFormatter . NUMBER_BASE ; if ( last && giga == 0 ) { break ; } } } if ( val < 0 ) { buf [ xoff ] = ( byte ) '-' ; } return off ; }
format a long into an existing array .
