throws Throwable
  public static String str_pad(String string,                               int length,                               @Optional("' '") String pad,                               @Optional("STR_PAD_RIGHT") int type)    throws Throwable  {    int strLen = string.length();    int padLen = length - strLen;    if (padLen <= 0)      return string;    if (pad.length() == 0)      pad = " ";    int leftPad = 0;    int rightPad = 0;    switch (type) {    case STR_PAD_LEFT:      leftPad = padLen;      break;    case STR_PAD_RIGHT:    default:      rightPad = padLen;      break;    case STR_PAD_BOTH:      leftPad = padLen / 2;      rightPad = padLen - leftPad;      break;    }    StringBuilder sb = new StringBuilder();    int padStringLen = pad.length();    for (int i = 0; i < leftPad; i++)      sb.append(pad.charAt(i % padStringLen));    sb.append(string);    for (int i = 0; i < rightPad; i++)      sb.append(pad.charAt(i % padStringLen));    return sb.toString();  }