public class CSVParser
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static char |
CR |
static CSVParser |
defaultParser |
static char |
LF |
Constructor and Description |
---|
CSVParser()
This is the default constructor which creates a CSVParser having a delimiter of ',' and a quote of '"'.
|
CSVParser(char delimiter)
Use this to specify a custom delimiter.
|
CSVParser(char delimiter,
char quote)
Use this to specify custom delimiter and quote symbols.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String[][] |
convertRecordsToRows(java.util.Map<java.lang.String,java.lang.String>[] records)
This function converts an Array of Map objects to an Array of Arrays compatible with other functions in this class.
|
java.lang.String[][] |
convertRecordsToRows(java.util.Map<java.lang.String,java.lang.String>[] records,
java.lang.String[] columnOrder)
This function converts an Array of Map objects to an Array of Arrays compatible with other functions in this class.
|
java.lang.String[][] |
convertRecordsToRows(java.util.Map<java.lang.String,java.lang.String>[] records,
java.lang.String[] columnOrder,
boolean allowBlankColumns)
This function converts an Array of Map objects to an Array of Arrays compatible with other functions in this class.
|
java.util.Map<java.lang.String,java.lang.String>[] |
convertRowsToRecords(java.lang.String[][] rows)
This function converts an Array of Arrays to an Array of Objects compatible with DataGrid.
|
void |
createCSV(java.lang.Object[][] rows,
boolean quoteEmptyStrings,
java.lang.Appendable output,
boolean endingLineFeed)
This function converts a table of Strings (or Objects) and encodes them as a single CSV String.
|
java.lang.String |
createCSV(java.lang.Object[][] rows,
boolean quoteEmptyStrings,
boolean endingLineFeed)
This function converts a table of Strings (or Objects) and encodes them as a single CSV String.
|
java.lang.String |
createCSVRow(java.lang.Object[] row,
boolean quoteEmptyStrings)
This function encodes an Array of objects into a CSV row.
|
java.lang.String |
createCSVToken(java.lang.String str,
boolean quoteEmptyStrings)
This function encodes a String as a CSV token, adding quotes around it and replacing " with "" if necessary.
|
java.lang.String[] |
getRecordFieldNames(java.util.Map<java.lang.String,java.lang.String>[] records)
This function returns a comprehensive list of all the field names defined by a list of record objects.
|
java.lang.String[] |
getRecordFieldNames(java.util.Map<java.lang.String,java.lang.String>[] records,
boolean includeNullFields)
This function returns a comprehensive list of all the field names defined by a list of record objects.
|
java.lang.String[][] |
parseCSV(java.io.File csvFile,
boolean parseTokens)
This function parses a String as a CSV-encoded table.
|
java.lang.String[][] |
parseCSV(java.io.InputStream csvInput,
boolean parseTokens)
This function parses a String as a CSV-encoded table.
|
java.lang.String[][] |
parseCSV(java.lang.String csvData,
boolean parseTokens)
This function parses a String as a CSV-encoded table.
|
java.lang.String[] |
parseCSVRow(java.lang.String csvData,
boolean parseTokens)
This function parses a String as a CSV-encoded row.
|
java.lang.String |
parseCSVToken(java.lang.String token)
This function will decode a CSV token, removing quotes and un-escaping quotes where applicable.
|
public static final CSVParser defaultParser
public static final char CR
public static final char LF
public CSVParser()
public CSVParser(char delimiter)
delimiter
- The character used to separate values in a single line.public CSVParser(char delimiter, char quote)
delimiter
- The character used to separate values in a single line.quote
- The character used to surround values so that they may contain the delimiter.public java.lang.String parseCSVToken(java.lang.String token)
token
- The CSV-encoded token to parse.public java.lang.String createCSVToken(java.lang.String str, boolean quoteEmptyStrings)
str
- The String to encode as a CSV token.public java.lang.String[] parseCSVRow(java.lang.String csvData, boolean parseTokens)
csvData
- The CSV string to parse.parseTokens
- If this is true, tokens surrounded in quotes will be unquoted and escaped characters will be unescaped.public java.lang.String[][] parseCSV(java.lang.String csvData, boolean parseTokens)
csvData
- The CSV string to parse.parseTokens
- If this is true, tokens surrounded in quotes will be unquoted and escaped characters will be unescaped.public java.lang.String[][] parseCSV(java.io.File csvFile, boolean parseTokens) throws java.io.IOException
csvFile
- The CSV file to parse.parseTokens
- If this is true, tokens surrounded in quotes will be unquoted and escaped characters will be unescaped.java.io.IOException
public java.lang.String[][] parseCSV(java.io.InputStream csvInput, boolean parseTokens) throws java.io.IOException
csvInput
- The CSV input to parse.parseTokens
- If this is true, tokens surrounded in quotes will be unquoted and escaped characters will be unescaped.java.io.IOException
public java.lang.String createCSVRow(java.lang.Object[] row, boolean quoteEmptyStrings)
row
- An array of values for a single row. If the row values are not Strings, toString() will be called on each value.public java.lang.String createCSV(java.lang.Object[][] rows, boolean quoteEmptyStrings, boolean endingLineFeed)
rows
- An array of rows. If the row values are not Strings, toString() will be called on each value.public void createCSV(java.lang.Object[][] rows, boolean quoteEmptyStrings, java.lang.Appendable output, boolean endingLineFeed) throws java.io.IOException
rows
- An array of rows. If the row values are not Strings, toString() will be called on each value.output
- Where the result will be directed.endingLineFeed
- Set to true to end the output with a line feed.java.io.IOException
public java.util.Map<java.lang.String,java.lang.String>[] convertRowsToRecords(java.lang.String[][] rows)
rows
- An Array of Arrays, the first being a header line containing property namespublic java.lang.String[] getRecordFieldNames(java.util.Map<java.lang.String,java.lang.String>[] records)
records
- An Array of record objects.public java.lang.String[] getRecordFieldNames(java.util.Map<java.lang.String,java.lang.String>[] records, boolean includeNullFields)
records
- An Array of record objects.includeNullFields
- If this is true, fields that have null values will be included.public java.lang.String[][] convertRecordsToRows(java.util.Map<java.lang.String,java.lang.String>[] records)
records
- An Array of Objects containing String properties.public java.lang.String[][] convertRecordsToRows(java.util.Map<java.lang.String,java.lang.String>[] records, java.lang.String[] columnOrder)
records
- An Array of Objects containing String properties.columnOrder
- An optional list of column names to use in order.public java.lang.String[][] convertRecordsToRows(java.util.Map<java.lang.String,java.lang.String>[] records, java.lang.String[] columnOrder, boolean allowBlankColumns)
records
- An Array of Objects containing String properties.columnOrder
- An optional list of column names to use in order.allowBlankColumns
- If this is set to true, then the function will include all columns even if they are blank.