Here you can find the source of indent_DisplayBanner(PrintWriter out, ResultSetMetaData rsmd, int indentLevel, int[] displayColumns, int[] displayColumnWidths)
static private int indent_DisplayBanner(PrintWriter out, ResultSetMetaData rsmd, int indentLevel, int[] displayColumns, int[] displayColumnWidths) throws SQLException
//package com.java2s; /*//from w ww . j a va 2 s . c om Derby - Class org.apache.derby.tools.JDBCDisplayUtil Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ import java.io.PrintStream; import java.io.PrintWriter; import java.sql.SQLException; import java.sql.ResultSetMetaData; public class Main { static private int indent_DisplayBanner(PrintWriter out, ResultSetMetaData rsmd, int indentLevel, int[] displayColumns, int[] displayColumnWidths) throws SQLException { StringBuffer buf = new StringBuffer(); int numCols = displayColumnWidths.length; int rowLen; // do some precalculation so the buffer is allocated only once // buffer is twice as long as the display length plus one for a newline rowLen = (numCols - 1); // for the column separators for (int i = 1; i <= numCols; i++) rowLen += displayColumnWidths[i - 1]; buf.ensureCapacity(rowLen); // get column header info // truncate it to the column display width // add a bar between each item. for (int i = 1; i <= numCols; i++) { int colnum = displayColumns == null ? i : displayColumns[i - 1]; if (i > 1) buf.append('|'); String s = rsmd.getColumnLabel(colnum); int w = displayColumnWidths[i - 1]; if (s.length() < w) { buf.append(s); // try to paste on big chunks of space at a time. int k = w - s.length(); for (; k >= 64; k -= 64) buf.append(" "); for (; k >= 16; k -= 16) buf.append(" "); for (; k >= 4; k -= 4) buf.append(" "); for (; k > 0; k--) buf.append(' '); } else if (s.length() > w) { if (w > 1) buf.append(s.substring(0, w - 1)); if (w > 0) buf.append('&'); } else { buf.append(s); } } buf.setLength(Math.min(rowLen, 1024)); indentedPrintLine(out, indentLevel, buf); // now print a row of '-'s for (int i = 0; i < Math.min(rowLen, 1024); i++) buf.setCharAt(i, '-'); indentedPrintLine(out, indentLevel, buf); buf = null; return rowLen; } static private int indent_DisplayBanner(PrintStream out, ResultSetMetaData rsmd, int indentLevel, int[] displayColumns, int[] displayColumnWidths) throws SQLException { StringBuffer buf = new StringBuffer(); int numCols = displayColumnWidths.length; int rowLen; // do some precalculation so the buffer is allocated only once // buffer is twice as long as the display length plus one for a newline rowLen = (numCols - 1); // for the column separators for (int i = 1; i <= numCols; i++) { rowLen += displayColumnWidths[i - 1]; } buf.ensureCapacity(rowLen); // get column header info // truncate it to the column display width // add a bar between each item. for (int i = 1; i <= numCols; i++) { int colnum = displayColumns == null ? i : displayColumns[i - 1]; if (i > 1) buf.append('|'); String s = rsmd.getColumnLabel(colnum); int w = displayColumnWidths[i - 1]; if (s.length() < w) { // build a string buffer to hold the whitespace StringBuffer blanks = new StringBuffer(s); blanks.ensureCapacity(w); // try to paste on big chunks of space at a time. for (int k = blanks.length() + 64; k <= w; k += 64) blanks.append(" "); for (int k = blanks.length() + 16; k <= w; k += 16) blanks.append(" "); for (int k = blanks.length() + 4; k <= w; k += 4) blanks.append(" "); for (int k = blanks.length(); k < w; k++) blanks.append(' '); buf.append(blanks); // REMIND: could do more cleverness, like keep around // past buffers to reuse... } else if (s.length() > w) { if (w > 1) buf.append(s.substring(0, w - 1)); if (w > 0) buf.append('&'); } else { buf.append(s); } } buf.setLength(Math.min(rowLen, 1024)); indentedPrintLine(out, indentLevel, buf); // now print a row of '-'s for (int i = 0; i < Math.min(rowLen, 1024); i++) buf.setCharAt(i, '-'); indentedPrintLine(out, indentLevel, buf); buf = null; return rowLen; } static private void indentedPrintLine(PrintWriter out, int indentLevel, String text) { indent(out, indentLevel); out.println(text); } static private void indentedPrintLine(PrintWriter out, int indentLevel, StringBuffer text) { indent(out, indentLevel); out.println(text); } static private void indentedPrintLine(PrintStream out, int indentLevel, String text) { indent(out, indentLevel); out.println(text); } static private void indentedPrintLine(PrintStream out, int indentLevel, StringBuffer text) { indent(out, indentLevel); out.println(text); } static private void indent(PrintWriter out, int indentLevel) { for (int ictr = 0; ictr < indentLevel; ictr++) { out.print(" "); } } static private void indent(PrintStream out, int indentLevel) { for (int ictr = 0; ictr < indentLevel; ictr++) { out.print(" "); } } }