public static void appendPaddedInteger(StringBuffer buf,long value,int size){
  int intValue=(int)value;
  if (intValue == value) {
    appendPaddedInteger(buf,intValue,size);
  }
 else   if (size <= 19) {
    buf.append(Long.toString(value));
  }
 else {
    if (value < 0) {
      buf.append('-');
      if (value != Long.MIN_VALUE) {
        value=-value;
      }
 else {
        for (; size > 19; size--) {
          buf.append('0');
        }
        buf.append("9223372036854775808");
        return;
      }
    }
    int digits=(int)(Math.log(value) / LOG_10) + 1;
    for (; size > digits; size--) {
      buf.append('0');
    }
    buf.append(Long.toString(value));
  }
}

public static void appendPaddedInteger ( StringBuffer buf , long value , int size ) { int intValue = ( int ) value ; if ( intValue == value ) { appendPaddedInteger ( buf , intValue , size ) ; } else if ( size <= 19 ) { buf . append ( Long . toString ( value ) ) ; } else { if ( value < 0 ) { buf . append ( '-' ) ; if ( value != Long . MIN_VALUE ) { value = - value ; } else { for ( ; size > 19 ; size -- ) { buf . append ( '0' ) ; } buf . append ( "9223372036854775808" ) ; return ; } } int digits = ( int ) ( Math . log ( value ) / LOG_10 ) + 1 ; for ( ; size > digits ; size -- ) { buf . append ( '0' ) ; } buf . append ( Long . toString ( value ) ) ; } }
converts an integer to a string , prepended with a variable amount of ' 0 ' pad characters , and appends it to the given buffer . < p > this method is optimized for converting small values to strings .
