Package csv.util
Class CSVUtils
java.lang.Object
csv.util.CSVUtils
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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String[]convertArray(Object[] columns, int minLength) Returns an array from the columns.static Object[]convertList(List<?> columns, int minLength) Trims array to correct length of minimum column count.static voidcopy(TableReader reader, TableWriter writer) Copies content from one reader to another writer without header row.static voidcopy(TableReader reader, TableWriter writer, boolean copyHeaderRow) Copies content from one reader to another writer.static intcopy(Object[][] arr, TableWriter writer) Copies the arrays from the iterator to the stream.static intcopy(Collection<? extends Object[]> collection, TableWriter writer) Copies the arrays from the collection to the stream.static intcopy(Iterator<? extends Object[]> i, TableWriter writer) Copies the arrays from the iterator to the stream.static <T> intcopyBeans(Collection<T> collection, TableWriter writer) Copies the beans from the collection to the stream.static <T> intcopyBeans(Iterator<T> i, TableWriter writer) Copies the beans from the collection to the stream.static <T> intcopyBeans(T[] arr, TableWriter writer) Copies the beans from the array to the stream.static voidcopyHeader(ResultSet resultSet, TableWriter writer) Copies the header of the JDBC result set into the table writer.static voidcopyTableHeader(JTableHeader tableHeader, TableWriter writer) Copies the table header into the table writer.static Object[]extendArray(Object[] columns, int minLength) Trims array to correct length of minimum column count.static String[]extendArray(String[] columns, int minLength) Trims array to correct length of minimum column count.static CharsetReturns thedefaultCharset.static voidsetDefaultCharset(String defaultCharset) Sets thedefaultCharset.static voidsetDefaultCharset(Charset defaultCharset) Sets thedefaultCharset.
-
Constructor Details
-
CSVUtils
public CSVUtils()
-
-
Method Details
-
getDefaultCharset
Returns thedefaultCharset.- Returns:
- the defaultCharset
-
setDefaultCharset
Sets thedefaultCharset.- Parameters:
defaultCharset- the defaultCharset to set
-
setDefaultCharset
Sets thedefaultCharset.- Parameters:
defaultCharset- the defaultCharset to set
-
copyHeader
Copies the header of the JDBC result set into the table writer.- Parameters:
resultSet- result set to copywriter- CSV writer to write to- Throws:
Exception- if an exception occurs
-
copyTableHeader
Copies the table header into the table writer.- Parameters:
tableHeader- table header to get content fromwriter- table writer- Throws:
Exception- when an exception occurs
-
copy
Copies content from one reader to another writer without header row.- Parameters:
reader- reader to copy data fromwriter- writer to write data to- Throws:
Exception- when an exception occurs
-
copy
public static void copy(TableReader reader, TableWriter writer, boolean copyHeaderRow) throws 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 fromwriter- writer to write data tocopyHeaderRow- whether a header row shall be copied too (only if reader supports it)- Throws:
Exception- when an exception occurs
-
copy
public static int copy(Collection<? extends Object[]> collection, TableWriter writer) throws IOException Copies the arrays from the collection to the stream.- Parameters:
collection- collection that contains rowswriter- writer to write rows to- Returns:
- number of rows written
- Throws:
IOException- when there is a problem with the writer.
-
copy
Copies the arrays from the iterator to the stream.- Parameters:
i- iterator that delivers rowswriter- writer to write rows to- Returns:
- number of rows written
- Throws:
IOException- when there is a problem with the writer.
-
copy
Copies the arrays from the iterator to the stream.- Parameters:
arr- two-dimensional array with rows and columnswriter- writer to write rows to- Returns:
- number of rows written
- Throws:
IOException- when there is a problem with the writer.
-
copyBeans
Copies the beans from the collection to the stream. The method will useBeanWriter- Type Parameters:
T- The type of bean in the collection- Parameters:
collection- collection that contains JavaBeanswriter- writer to write rows to- Returns:
- number of rows written
- Throws:
IOException- when there is a problem with the writer.
-
copyBeans
Copies the beans from the collection to the stream. The method will useBeanWriter- Type Parameters:
T- The type of bean in the collection- Parameters:
i- iterator that delivers JavaBeanswriter- writer to write rows to- Returns:
- number of rows written
- Throws:
IOException- when there is a problem with the writer.
-
copyBeans
Copies the beans from the array to the stream. The method will useBeanWriter- Type Parameters:
T- The type of bean in the array- Parameters:
arr- array of JavaBeanswriter- writer to write rows to- Returns:
- number of rows written
- Throws:
IOException- when there is a problem with the writer.
-
convertArray
Returns an array from the columns. This function exists for convinience to take care of minimum column count.- Parameters:
columns- columns to returnminLength- minimum number of columns in return array- Returns:
- arrray with column values
-
extendArray
Trims array to correct length of minimum column count.- Parameters:
columns- columns arrayminLength- minimum number of columns- Returns:
- array with at least minimum number of columns defined.
-
extendArray
Trims array to correct length of minimum column count.- Parameters:
columns- columns arrayminLength- minimum number of columns- Returns:
- array with at least minimum number of columns defined.
-
convertList
Trims array to correct length of minimum column count.- Parameters:
columns- columns listminLength- minimum number of columns- Returns:
- array with at least minimum number of columns defined.
-