private void printRow(final PrintStream stream,final String[] items,final int[] columnDisplayWidths){
  if (overallIndent > 0) {
    printSpaces(stream,overallIndent);
  }
  boolean needsNewRow=false;
  final String[] newRow=new String[items.length];
  for (int i=0; i < columns.length; i++) {
    if (i > 0) {
      printSpaces(stream,gutterWidthCharacters);
    }
    if (i > items.length - 1) {
      break;
    }
    final int columnWidth=columnDisplayWidths[i];
    String text=items[i];
    if (text == null) {
      if ((i + 1) < columns.length) {
        printSpaces(stream,columnWidth);
      }
      continue;
    }
    if (wrapColumnText && text.length() > columnWidth) {
      final String sub=text.substring(0,columnWidth);
      int wrapIndex=-1;
      for (      final char wrapChar : CHARACTERS_FOR_WRAPPING) {
        wrapIndex=sub.lastIndexOf(wrapChar);
        if (wrapIndex >= 0) {
          int moonWalker=wrapIndex;
          while (moonWalker >= 0 && isWrappingBreakCharacter(sub.charAt(moonWalker))) {
            moonWalker--;
          }
          if (moonWalker > -1) {
            wrapIndex=moonWalker + 1;
            break;
          }
        }
      }
      if (wrapIndex == -1) {
        wrapIndex=sub.length() - 1;
      }
      if (wrapIndex + 1 <= text.length()) {
        newRow[i]=StringUtil.trimBegin(text.substring(wrapIndex + 1));
      }
      text=StringUtil.trimEnd(sub.substring(0,wrapIndex + 1));
      needsNewRow=true;
    }
    if (truncateLongLines) {
      stream.print(text.substring(0,Math.min(columnWidth,text.length())));
    }
 else {
      stream.print(text);
    }
    if ((text.length() < columnWidth) && ((i + 1) < columns.length)) {
      printSpaces(stream,columnWidth - text.length());
    }
  }
  stream.println();
  if (needsNewRow) {
    printRow(stream,newRow,columnDisplayWidths);
  }
}

private void printRow ( final PrintStream stream , final String [ ] items , final int [ ] columnDisplayWidths ) { if ( overallIndent > 0 ) { printSpaces ( stream , overallIndent ) ; } boolean needsNewRow = false ; final String [ ] newRow = new String [ items . length ] ; for ( int i = 0 ; i < columns . length ; i ++ ) { if ( i > 0 ) { printSpaces ( stream , gutterWidthCharacters ) ; } if ( i > items . length - 1 ) { break ; } final int columnWidth = columnDisplayWidths [ i ] ; String text = items [ i ] ; if ( text == null ) { if ( ( i + 1 ) < columns . length ) { printSpaces ( stream , columnWidth ) ; } continue ; } if ( wrapColumnText && text . length ( ) > columnWidth ) { final String sub = text . substring ( 0 , columnWidth ) ; int wrapIndex = - 1 ; for ( final char wrapChar : CHARACTERS_FOR_WRAPPING ) { wrapIndex = sub . lastIndexOf ( wrapChar ) ; if ( wrapIndex >= 0 ) { int moonWalker = wrapIndex ; while ( moonWalker >= 0 && isWrappingBreakCharacter ( sub . charAt ( moonWalker ) ) ) { moonWalker -- ; } if ( moonWalker > - 1 ) { wrapIndex = moonWalker + 1 ; break ; } } } if ( wrapIndex == - 1 ) { wrapIndex = sub . length ( ) - 1 ; } if ( wrapIndex + 1 <= text . length ( ) ) { newRow [ i ] = StringUtil . trimBegin ( text . substring ( wrapIndex + 1 ) ) ; } text = StringUtil . trimEnd ( sub . substring ( 0 , wrapIndex + 1 ) ) ; needsNewRow = true ; } if ( truncateLongLines ) { stream . print ( text . substring ( 0 , Math . min ( columnWidth , text . length ( ) ) ) ) ; } else { stream . print ( text ) ; } if ( ( text . length ( ) < columnWidth ) && ( ( i + 1 ) < columns . length ) ) { printSpaces ( stream , columnWidth - text . length ( ) ) ; } } stream . println ( ) ; if ( needsNewRow ) { printRow ( stream , newRow , columnDisplayWidths ) ; } }
prints a row ( possibly as multiple lines , if wrapping is enabled ) .
