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 usingCSVParserandCSVPrinter.
-
-
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 booleanisEmpty(org.apache.commons.csv.CSVRecord record)Check whether the record is empty.static booleannotEmpty(org.apache.commons.csv.CSVRecord record)Check whether the record is not empty.org.apache.commons.csv.CSVParserparse(File in)org.apache.commons.csv.CSVParserparse(File in, Charset charset)voidparse(File in, Consumer<org.apache.commons.csv.CSVParser> task)org.apache.commons.csv.CSVParserparse(InputStream in)org.apache.commons.csv.CSVParserparse(InputStream in, Charset charset)org.apache.commons.csv.CSVParserparse(Reader in)voidparse(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 ofCSVRecordby filtering out empty records.static String[]values(org.apache.commons.csv.CSVRecord record)Return values as array.CSVFilewithDelimiter(char delimiter)CSVFilewithEscape(char escape)CSVFilewithFirstRecordAsHeader()CSVFilewithHeader(String... header)CSVFilewithQuoteAll()org.apache.commons.csv.CSVPrinterwrite(File out)org.apache.commons.csv.CSVPrinterwrite(File out, Charset charset)org.apache.commons.csv.CSVPrinterwrite(OutputStream out, Charset charset)org.apache.commons.csv.CSVPrinterwrite(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 ofCSVRecordby 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
-
-