private int[] colWidths(ResultSetRewindable rs) { int numCols = rs.getResultVars().size() ; int numRows = 0 ; int[] colWidths = new int[numCols] ; // Widths at least that of the variable name. Assumes we will print col headings. for ( int i = 0 ; i < numCols ; i++ ) colWidths[i] = (rs.getResultVars().get(i)).length() ; // Preparation pass : find the maximum width for each column for ( ; rs.hasNext() ; ) { numRows++ ; QuerySolution rBind = rs.nextSolution() ; int col = -1 ; for ( String s1 : rs.getResultVars() ) { col++; String rVar = s1; String s = getVarValueAsString( rBind, rVar ); if ( colWidths[col] < s.length() ) { colWidths[col] = s.length(); } } } rs.reset() ; return colWidths ; }
for ( int col = 0 ; col < numCols ; col++ ) { String rVar = resultSet.getResultVars().get(col); row[col] = this.getVarValueAsString(rBind, rVar);