@Immutable
public class CsvReader
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static Table |
detectedColumnTypes(java.lang.String csvFileName,
boolean header,
char delimiter)
Returns the structure of the table given by
csvFileName as detected by analysis of a sample of the data |
static Table |
headerOnly(ColumnType[] types,
boolean header,
char columnSeparator,
java.lang.String fileName)
Returns a Table constructed from a CSV File with the given file name
|
static Table |
headerOnly(java.lang.String name,
ColumnType[] types,
boolean header,
char columnSeparator,
java.io.InputStream stream)
Returns a Table constructed from a CSV File with the given file name
|
static java.lang.String |
printColumnTypes(java.lang.String csvFileName,
boolean header,
char delimiter)
Returns a string representation of the file types in file
csvFilename ,
as determined by the type-detection algorithm |
static Table |
read(ColumnType[] types,
boolean header,
char columnSeparator,
java.lang.String fileName)
Returns a Table constructed from a CSV File with the given file name
|
static Table |
read(ColumnType[] types,
java.lang.String... fileNames)
Constructs and returns a table from one or more CSV files, all containing the same column types
|
static Table |
read(java.lang.String fileName,
boolean header,
char delimiter)
Retuns the given file after autodetecting the column types, or trying to
|
static Table |
read(java.lang.String tableName,
ColumnType[] types,
boolean header,
char columnSeparator,
java.io.InputStream stream) |
public static Table read(ColumnType[] types, java.lang.String... fileNames) throws java.io.IOException
This constructor assumes the files have a one-line header, which is used to populate the column names, and that they use a comma to separate between columns.
java.io.IOException
- If there is an issue reading any of the filespublic static Table read(ColumnType[] types, boolean header, char columnSeparator, java.lang.String fileName) throws java.io.IOException
The @code{fileName} is used as the initial table name for the new table
types
- An array of the types of columns in the file, in the order they appearheader
- Is the first row in the file a header?columnSeparator
- the delimiterfileName
- The fully specified file name. It is used to provide a default name for the tablejava.io.IOException
public static Table read(java.lang.String fileName, boolean header, char delimiter) throws java.io.IOException
fileName
- The name of the file to loadheader
- True if the file has a single header row. False if it has no header row.
Multi-line headers are not supporteddelimiter
- a char that divides the columns in the source file, often a comma or tabjava.io.IOException
public static Table read(java.lang.String tableName, ColumnType[] types, boolean header, char columnSeparator, java.io.InputStream stream) throws java.io.IOException
java.io.IOException
public static Table headerOnly(java.lang.String name, ColumnType[] types, boolean header, char columnSeparator, java.io.InputStream stream) throws java.io.IOException
The @code{fileName} is used as the initial table name for the new table
types
- An array of the types of columns in the file, in the order they appearheader
- Is the first row in the file a header?columnSeparator
- the delimitername
- The fully specified file name. It is used to provide a default name for the tablejava.io.IOException
public static Table headerOnly(ColumnType[] types, boolean header, char columnSeparator, java.lang.String fileName) throws java.io.IOException
The @code{fileName} is used as the initial table name for the new table
types
- An array of the types of columns in the file, in the order they appearheader
- Is the first row in the file a header?columnSeparator
- the delimiterfileName
- The fully specified file name. It is used to provide a default name for the tablejava.io.IOException
public static Table detectedColumnTypes(java.lang.String csvFileName, boolean header, char delimiter) throws java.io.IOException
csvFileName
as detected by analysis of a sample of the datajava.io.IOException
public static java.lang.String printColumnTypes(java.lang.String csvFileName, boolean header, char delimiter) throws java.io.IOException
csvFilename
,
as determined by the type-detection algorithm
This method is intended to help analysts quickly fix any erroneous types, by printing out the types in a format such that they can be edited to correct any mistakes, and used in an array literal
For example:
LOCAL_DATE, // 0 date SHORT_INT, // 1 approval CATEGORY, // 2 who
Note that the types are array separated, and that the index position and the column name are printed such that they would be interpreted as comments if you paste the output into an array:
ColumnType[] types = { LOCAL_DATE, // 0 date SHORT_INT, // 1 approval CATEGORY, // 2 who }
java.io.IOException