@Immutable public class CsvReader extends Object
Constructor and Description |
---|
CsvReader()
Constructs a CsvReader
|
CsvReader(List<ColumnType> typeDetectionList)
Constructs a CsvReader with the given list of ColumnTypes
These are the only types that the CsvReader can detect and parse
|
Modifier and Type | Method and Description |
---|---|
ColumnType[] |
detectColumnTypes(InputStream stream,
CsvReadOptions options)
Estimates and returns the type for each column in the delimited text file
file |
List<ColumnType> |
getTypeArray()
Returns the list of types that specifies the order in which types are tested in the detection algorithm.
|
Table |
headerOnly(ColumnType[] types,
boolean header,
CsvReadOptions options,
File file)
Returns a Table constructed from a CSV File with the given file name
|
String |
printColumnTypes(String csvFileName,
boolean header,
char delimiter,
Locale locale)
Returns a string representation of the column types in file
csvFilename ,
as determined by the type-detection algorithm |
Table |
read(CsvReadOptions options) |
public CsvReader()
public CsvReader(List<ColumnType> typeDetectionList)
public Table read(CsvReadOptions options) throws IOException
IOException
public Table headerOnly(ColumnType[] types, boolean header, CsvReadOptions options, 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?options
- Sets the format for and instructions for parsingfile
- The fully specified file name. It is used to provide a default name for the tableIOException
- if file cannot be readpublic String printColumnTypes(String csvFileName, boolean header, char delimiter, Locale locale) 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, // 1 approval STRING, // 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:
IOException
- if file cannot be readpublic ColumnType[] detectColumnTypes(InputStream stream, CsvReadOptions options) 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
public List<ColumnType> getTypeArray()
Copyright © 2018. All rights reserved.