code: public static String pad(String rawString, int length, char padChar)
    {
      String padded = rawString;
      String padFiller = null;
  
      if (padded.length() == length)
      {
        return padded;
      }
  
      if (padded.length() < length)
      {
        //
        // Keep a zero string that is big enough to pad the
        // largest field that we have, then to pad each field
        // we just append this string to the field and then
        // substr to the desired size.
        //
        StringBuffer buff = new StringBuffer(length);
  
        for (int i = buff.length(); i < length; i++)
        {
          buff.append(padChar);
        }
        padFiller = buff.toString();
  
        padded = rawString + padFiller;
        return padded.substring(0, length);
  
      }
      else
      {
        return padded.substring(0, length);
      }
    }
docs: Pad string with a character at end of text.
  
  @param rawString
  @param length - total length of the desired string
  @param padChar - character to pad at the end of the text.
  @return the padded String