@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(ColumnType[] types,
boolean header,
char columnSeparator,
String fileName)
Deprecated.
use read(CsvReadOptions) instead
|
static Table |
read(ColumnType[] types,
String... fileNames)
Deprecated.
use read(CsvReadOptions) instead
|
static Table |
read(CsvReadOptions options) |
static Table |
read(File file,
boolean header,
char delimiter)
Deprecated.
use read(CsvReadOptions) instead
|
static Table |
read(File file,
String tableName,
boolean header,
char delimiter,
boolean skipSampling) |
static Table |
read(File file,
String tableName,
ColumnType[] types,
boolean header,
char columnSeparator)
Deprecated.
use read(CsvReadOptions) instead
|
static Table |
read(InputStream stream,
String tableName,
boolean header,
char delimiter)
Deprecated.
use read(CsvReadOptions) instead
|
static Table |
read(InputStream stream,
String tableName,
boolean header,
char delimiter,
boolean skipSampling)
Deprecated.
use read(CsvReadOptions) instead
|
static Table |
read(InputStream stream,
String tableName,
ColumnType[] types,
boolean header,
char columnSeparator)
Deprecated.
use read(CsvReadOptions) instead
|
@Deprecated public static Table read(ColumnType[] types, String... fileNames) throws 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.
IOException
- If there is an issue reading any of the files@Deprecated public static Table read(ColumnType[] types, boolean header, char columnSeparator, String fileName) 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 delimiterfileName
- The fully specified file name. It is used to provide a default name for the tableIOException
- if file cannot be read@Deprecated public static Table read(File file, boolean header, char delimiter) throws IOException
file
- 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 tabIOException
- if file cannot be read@Deprecated public static Table read(InputStream stream, String tableName, boolean header, char delimiter) throws IOException
stream
- The CSVtableName
- Name to give the tableheader
- 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 tabIOException
- if file cannot be readpublic static Table read(File file, String tableName, boolean header, char delimiter, boolean skipSampling) throws IOException
IOException
@Deprecated public static Table read(InputStream stream, String tableName, boolean header, char delimiter, boolean skipSampling) throws IOException
IOException
@Deprecated public static Table read(File file, String tableName, ColumnType[] types, boolean header, char columnSeparator) throws IOException
IOException
@Deprecated public static Table read(InputStream stream, String tableName, ColumnType[] types, boolean header, char columnSeparator) throws IOException
IOException
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 © 2017. All rights reserved.