Copyright © 2008-2011 Ralph Schuster. All Rights Reserved.

csv.util
Class CSVUtils

java.lang.Object
  extended by csv.util.CSVUtils

public class CSVUtils
extends java.lang.Object

Various methods for working with TableReader and TableWriter. This class provides useful method for easily copying table-like data from either JDBC results, JTable or table readers into table writers.

Author:
RalphSchuster

Constructor Summary
CSVUtils()
           
 
Method Summary
static java.lang.String[] convertArray(java.lang.Object[] columns, int minLength)
          Returns an array from the columns.
static java.lang.Object[] convertList(java.util.List<java.lang.Object> columns, int minLength)
          Trims array to correct length of minimum column count.
static int copy(java.util.Collection<? extends java.lang.Object[]> collection, TableWriter writer)
          Copies the arrays from the collection to the stream.
static int copy(java.util.Iterator<? extends java.lang.Object[]> i, TableWriter writer)
          Copies the arrays from the iterator to the stream.
static void copy(javax.swing.JTable table, TableWriter writer, boolean writeHeaderRow, boolean selectedOnly)
          Deprecated. Use JTableReader and copy(TableReader, TableWriter, boolean)
static int copy(java.lang.Object[][] arr, TableWriter writer)
          Copies the arrays from the iterator to the stream.
static void copy(java.sql.ResultSet resultSet, TableWriter writer, boolean writeHeaderRow)
          Deprecated. Use JdbcReader and copy(TableReader, TableWriter, boolean)
static void copy(TableReader reader, TableWriter writer)
          Copies content from one reader to another writer without header row.
static void copy(TableReader reader, TableWriter writer, boolean copyHeaderRow)
          Copies content from one reader to another writer.
static int copyBeans(java.util.Collection<? extends java.lang.Object> collection, TableWriter writer)
          Copies the beans from the collection to the stream.
static int copyBeans(java.util.Iterator<? extends java.lang.Object> i, TableWriter writer)
          Copies the beans from the collection to the stream.
static int copyBeans(java.lang.Object[] arr, TableWriter writer)
          Copies the beans from the array to the stream.
static void copyHeader(java.sql.ResultSet resultSet, TableWriter writer)
          Copies the header of the JDBC result set into the table writer.
static void copyTableHeader(javax.swing.table.JTableHeader tableHeader, TableWriter writer)
          Copies the table header into the table writer.
static java.lang.Object[] extendArray(java.lang.Object[] columns, int minLength)
          Trims array to correct length of minimum column count.
static java.lang.String[] extendArray(java.lang.String[] columns, int minLength)
          Trims array to correct length of minimum column count.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CSVUtils

public CSVUtils()
Method Detail

copyHeader

public static void copyHeader(java.sql.ResultSet resultSet,
                              TableWriter writer)
                       throws java.lang.Exception
Copies the header of the JDBC result set into the table writer.

Parameters:
resultSet - result set to copy
writer - CSV writer to write to
Throws:
java.lang.Exception - if an exception occurs

copy

public static void copy(java.sql.ResultSet resultSet,
                        TableWriter writer,
                        boolean writeHeaderRow)
                 throws java.lang.Exception
Deprecated. Use JdbcReader and copy(TableReader, TableWriter, boolean)

Copies the JDBC result set into the table writer.

Parameters:
resultSet - result set to copy
writer - table writer to write to
writeHeaderRow - whether header row shall be written
Throws:
java.lang.Exception - if an exception occurs

copyTableHeader

public static void copyTableHeader(javax.swing.table.JTableHeader tableHeader,
                                   TableWriter writer)
                            throws java.lang.Exception
Copies the table header into the table writer.

Parameters:
tableHeader - table header to get content from
writer - table writer
Throws:
java.lang.Exception - when an exception occurs

copy

public static void copy(javax.swing.JTable table,
                        TableWriter writer,
                        boolean writeHeaderRow,
                        boolean selectedOnly)
                 throws java.lang.Exception
Deprecated. Use JTableReader and copy(TableReader, TableWriter, boolean)

Copies the table content into the table writer.

Parameters:
table - table to get content from
writer - table writer
writeHeaderRow - whether header row shall be written
selectedOnly - whether selected rows shall be written only
Throws:
java.lang.Exception - when an exception occurs

copy

public static void copy(TableReader reader,
                        TableWriter writer)
                 throws java.lang.Exception
Copies content from one reader to another writer without header row.

Parameters:
reader - reader to copy data from
writer - writer to write data to
Throws:
java.lang.Exception - when an exception occurs

copy

public static void copy(TableReader reader,
                        TableWriter writer,
                        boolean copyHeaderRow)
                 throws java.lang.Exception
Copies content from one reader to another writer. The header row will only be written if the reader delivers such a row.

Parameters:
reader - reader to copy data from
writer - writer to write data to
copyHeaderRow - whether a header row shall be copied too (only if reader supports it)
Throws:
java.lang.Exception - when an exception occurs

copy

public static int copy(java.util.Collection<? extends java.lang.Object[]> collection,
                       TableWriter writer)
                throws java.io.IOException
Copies the arrays from the collection to the stream.

Parameters:
collection - collection that contains rows
writer - writer to write rows to
Returns:
number of rows written
Throws:
java.io.IOException - when there is a problem with the writer.

copy

public static int copy(java.util.Iterator<? extends java.lang.Object[]> i,
                       TableWriter writer)
                throws java.io.IOException
Copies the arrays from the iterator to the stream.

Parameters:
i - iterator that delivers rows
writer - writer to write rows to
Returns:
number of rows written
Throws:
java.io.IOException - when there is a problem with the writer.

copy

public static int copy(java.lang.Object[][] arr,
                       TableWriter writer)
                throws java.io.IOException
Copies the arrays from the iterator to the stream.

Parameters:
arr - two-dimensional array with rows and columns
writer - writer to write rows to
Returns:
number of rows written
Throws:
java.io.IOException - when there is a problem with the writer.

copyBeans

public static int copyBeans(java.util.Collection<? extends java.lang.Object> collection,
                            TableWriter writer)
                     throws java.io.IOException
Copies the beans from the collection to the stream. The method will use BeanWriter

Parameters:
collection - collection that contains JavaBeans
writer - writer to write rows to
Returns:
number of rows written
Throws:
java.io.IOException - when there is a problem with the writer.

copyBeans

public static int copyBeans(java.util.Iterator<? extends java.lang.Object> i,
                            TableWriter writer)
                     throws java.io.IOException
Copies the beans from the collection to the stream. The method will use BeanWriter

Parameters:
i - iterator that delivers JavaBeans
writer - writer to write rows to
Returns:
number of rows written
Throws:
java.io.IOException - when there is a problem with the writer.

copyBeans

public static int copyBeans(java.lang.Object[] arr,
                            TableWriter writer)
                     throws java.io.IOException
Copies the beans from the array to the stream. The method will use BeanWriter

Parameters:
arr - array of JavaBeans
writer - writer to write rows to
Returns:
number of rows written
Throws:
java.io.IOException - when there is a problem with the writer.

convertArray

public static java.lang.String[] convertArray(java.lang.Object[] columns,
                                              int minLength)
Returns an array from the columns. This function exists for convinience to take care of minimum column count.

Parameters:
columns - columns to return
minLength - minimum number of columns in return array
Returns:
arrray with column values

extendArray

public static java.lang.Object[] extendArray(java.lang.Object[] columns,
                                             int minLength)
Trims array to correct length of minimum column count.

Parameters:
columns - minimum columns
Returns:
array with at least minimum number of columns defined.

extendArray

public static java.lang.String[] extendArray(java.lang.String[] columns,
                                             int minLength)
Trims array to correct length of minimum column count.

Parameters:
columns - minimum columns
Returns:
array with at least minimum number of columns defined.

convertList

public static java.lang.Object[] convertList(java.util.List<java.lang.Object> columns,
                                             int minLength)
Trims array to correct length of minimum column count.

Parameters:
columns - minimum columns
Returns:
array with at least minimum number of columns defined.

Copyright © 2008-2011 Ralph Schuster. All Rights Reserved.

Copyright © 2008-2011 Ralph Schuster. All Rights Reserved.