@Immutable public class CsvReader extends Object
Modifier and Type | Method and Description |
---|---|
protected static ColumnType[] |
detectColumnTypes(InputStream stream,
boolean header,
char delimiter,
boolean skipSampling)
Estimates and returns the type for each column in the delimited text file
file |
static Table |
headerOnly(ColumnType[] types,
boolean header,
char columnSeparator,
File file)
Returns a Table constructed from a CSV File with the given file name
|
static String |
printColumnTypes(String csvFileName,
boolean header,
char delimiter)
Returns a string representation of the column types in file
csvFilename ,
as determined by the type-detection algorithm |
static Table |
read(CsvReadOptions options) |
public static Table read(CsvReadOptions options) throws IOException
IOException
public static Table headerOnly(ColumnType[] types, boolean header, char columnSeparator, File file) throws 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 delimiterfile
- The fully specified file name. It is used to provide a default name for the tableIOException
- if file cannot be readpublic static String printColumnTypes(String csvFileName, boolean header, char delimiter) throws 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 }
IOException
- if file cannot be readprotected static ColumnType[] detectColumnTypes(InputStream stream, boolean header, char delimiter, boolean skipSampling) throws IOException
file
The type is determined by checking a sample of the data in the file. Because only a sample of the data is checked, the types may be incorrect. If that is the case a Parse Exception will be thrown.
The method printColumnTypes()
can be used to print a list of the detected columns that can be
corrected and
used to explicitly specify the correct column types.
IOException
Copyright © 2018. All rights reserved.