Package com.axelor.common.csv
Class CSVFile
- java.lang.Object
-
- com.axelor.common.csv.CSVFile
-
public final class CSVFile extends Object
This class provides api to work with csv files usingCSVParser
andCSVPrinter
.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static String[]
header(org.apache.commons.csv.CSVParser parser)
Return header as array.static boolean
isEmpty(org.apache.commons.csv.CSVRecord record)
Check whether the record is empty.static boolean
notEmpty(org.apache.commons.csv.CSVRecord record)
Check whether the record is not empty.org.apache.commons.csv.CSVParser
parse(File in)
org.apache.commons.csv.CSVParser
parse(File in, Charset charset)
void
parse(File in, Consumer<org.apache.commons.csv.CSVParser> task)
org.apache.commons.csv.CSVParser
parse(InputStream in)
org.apache.commons.csv.CSVParser
parse(InputStream in, Charset charset)
org.apache.commons.csv.CSVParser
parse(Reader in)
void
parse(Reader in, Consumer<org.apache.commons.csv.CSVParser> task)
static Stream<org.apache.commons.csv.CSVRecord>
stream(org.apache.commons.csv.CSVParser parser)
Return a stream ofCSVRecord
by filtering out empty records.static String[]
values(org.apache.commons.csv.CSVRecord record)
Return values as array.CSVFile
withDelimiter(char delimiter)
CSVFile
withEscape(char escape)
CSVFile
withFirstRecordAsHeader()
CSVFile
withHeader(String... header)
CSVFile
withQuoteAll()
org.apache.commons.csv.CSVPrinter
write(File out)
org.apache.commons.csv.CSVPrinter
write(File out, Charset charset)
org.apache.commons.csv.CSVPrinter
write(OutputStream out, Charset charset)
org.apache.commons.csv.CSVPrinter
write(Writer out)
-
-
-
Method Detail
-
withDelimiter
public CSVFile withDelimiter(char delimiter)
-
withEscape
public CSVFile withEscape(char escape)
-
withQuoteAll
public CSVFile withQuoteAll()
-
withFirstRecordAsHeader
public CSVFile withFirstRecordAsHeader()
-
parse
public org.apache.commons.csv.CSVParser parse(InputStream in) throws IOException
- Throws:
IOException
-
parse
public org.apache.commons.csv.CSVParser parse(InputStream in, Charset charset) throws IOException
- Throws:
IOException
-
parse
public org.apache.commons.csv.CSVParser parse(Reader in) throws IOException
- Throws:
IOException
-
parse
public org.apache.commons.csv.CSVParser parse(File in) throws IOException
- Throws:
IOException
-
parse
public org.apache.commons.csv.CSVParser parse(File in, Charset charset) throws IOException
- Throws:
IOException
-
write
public org.apache.commons.csv.CSVPrinter write(Writer out) throws IOException
- Throws:
IOException
-
write
public org.apache.commons.csv.CSVPrinter write(OutputStream out, Charset charset) throws IOException
- Throws:
IOException
-
write
public org.apache.commons.csv.CSVPrinter write(File out, Charset charset) throws IOException
- Throws:
IOException
-
write
public org.apache.commons.csv.CSVPrinter write(File out) throws IOException
- Throws:
IOException
-
parse
public void parse(File in, Consumer<org.apache.commons.csv.CSVParser> task) throws IOException
- Throws:
IOException
-
parse
public void parse(Reader in, Consumer<org.apache.commons.csv.CSVParser> task) throws IOException
- Throws:
IOException
-
stream
public static Stream<org.apache.commons.csv.CSVRecord> stream(org.apache.commons.csv.CSVParser parser)
Return a stream ofCSVRecord
by filtering out empty records.- Parameters:
parser
- theCSVParser
- Returns:
- stream of
CSVRecord
-
header
public static String[] header(org.apache.commons.csv.CSVParser parser)
Return header as array.- Parameters:
parser
- theCSVParser
- Returns:
- array of header names
-
values
public static String[] values(org.apache.commons.csv.CSVRecord record)
Return values as array.- Parameters:
record
- theCSVRecord
- Returns:
- array of values
-
isEmpty
public static boolean isEmpty(org.apache.commons.csv.CSVRecord record)
Check whether the record is empty.- Parameters:
record
- theCSVRecord
- Returns:
- true if record is empty
-
notEmpty
public static boolean notEmpty(org.apache.commons.csv.CSVRecord record)
Check whether the record is not empty.- Parameters:
record
- theCSVRecord
- Returns:
- true if record is not empty
-
-