/** Calculates column display widths from the default widths of the result set. */
  private static int[] getColumnDisplayWidths(
      ResultSetMetaData rsmd, int[] dispColumns, boolean localizedOutput) throws SQLException {
    int count = (dispColumns == null) ? rsmd.getColumnCount() : dispColumns.length;
    int[] widths = new int[count];

    for (int i = 0; i < count; i++) {
      int colnum = (dispColumns == null) ? (i + 1) : dispColumns[i];
      int dispsize =
          localizedOutput
              ? LocalizedResource.getInstance().getColumnDisplaySize(rsmd, colnum)
              : rsmd.getColumnDisplaySize(colnum);
      widths[i] =
          Math.min(
              maxWidth,
              Math.max(
                  (rsmd.isNullable(colnum) == ResultSetMetaData.columnNoNulls) ? 0 : MINWIDTH,
                  dispsize));
    }
    return widths;
  }
  /**
   * Print one row of a result set, padding each field to the display width and separating them with
   * '|'s
   *
   * @param out the place to write to
   * @param rs the ResultSet to use
   * @param rsmd the ResultSetMetaData to use
   * @param rowLen
   * @param nestedResults
   * @param conn
   * @param indentLevel number of tab stops to indent line
   * @param displayColumns A list of column numbers to display
   * @param displayColumnWidths If displayColumns is set, the width of columns to display, in
   *     characters.
   * @exception SQLException thrown on JDBC access failure
   */
  private static void DisplayRow(
      PrintWriter out,
      ResultSet rs,
      ResultSetMetaData rsmd,
      int rowLen,
      Vector nestedResults,
      Connection conn,
      int indentLevel,
      int[] displayColumns,
      int[] displayColumnWidths)
      throws SQLException {
    StringBuffer buf = new StringBuffer();
    buf.ensureCapacity(rowLen);

    int numCols = displayColumnWidths.length;
    int i;

    // get column header info
    // truncate it to the column display width
    // add a bar between each item.
    for (i = 1; i <= numCols; i++) {
      int colnum = displayColumns == null ? i : displayColumns[i - 1];
      if (i > 1) buf.append('|');

      String s;
      switch (rsmd.getColumnType(colnum)) {
        default:
          s = LocalizedResource.getInstance().getLocalizedString(rs, rsmd, colnum);
          break;
        case Types.JAVA_OBJECT:
        case Types.OTHER:
          {
            Object o = rs.getObject(colnum);
            if (o == null) {
              s = "NULL";
            } else if (o instanceof ResultSet && nestedResults != null) {
              s =
                  LocalizedResource.getMessage(
                      "UT_Resul0_20", LocalizedResource.getNumber(nestedResults.size()));
              nestedResults.addElement(o);
            } else {
              try {
                s = rs.getString(colnum);
              } catch (SQLException se) {
                // oops, they don't support refetching the column
                s = o.toString();
              }
            }
          }
          break;
      }
      if (s == null) s = "NULL";

      int w = displayColumnWidths[i - 1];
      if (s.length() < w) {
        StringBuffer fullS = new StringBuffer(s);
        fullS.ensureCapacity(w);
        for (int k = s.length(); k < w; k++) fullS.append(' ');
        s = fullS.toString();
      } else if (s.length() > w)
        // add the & marker to know it got cut off
        s = s.substring(0, w - 1) + "&";

      buf.append(s);
    }
    indentedPrintLine(out, indentLevel, buf);
  } // DisplayRow
 static {
   // initialize the locale support functions to default value of JVM
   LocalizedResource.getInstance();
 }