Package org.jfree.data.io
Class CSV
- java.lang.Object
-
- org.jfree.data.io.CSV
-
public class CSV extends java.lang.Object
A utility class for readingCategoryDataset
data from a CSV file. This initial version is very basic, and won't handle errors in the data file very gracefully.
-
-
Field Summary
Fields Modifier and Type Field Description private char
fieldDelimiter
The field delimiter.private char
textDelimiter
The text delimiter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.util.List
extractColumnKeys(java.lang.String line)
Extracts the column keys from a string.private void
extractRowKeyAndData(java.lang.String line, DefaultCategoryDataset dataset, java.util.List columnKeys)
Extracts the row key and data for a single line from the input source.CategoryDataset
readCategoryDataset(java.io.Reader in)
Reads aCategoryDataset
from a CSV file or input source.private java.lang.String
removeStringDelimiters(java.lang.String key)
Removes the string delimiters from a key (as well as any white space outside the delimiters).
-
-
-
Constructor Detail
-
CSV
public CSV()
Creates a new CSV reader where the field delimiter is a comma, and the text delimiter is a double-quote.
-
CSV
public CSV(char fieldDelimiter, char textDelimiter)
Creates a new reader with the specified field and text delimiters.- Parameters:
fieldDelimiter
- the field delimiter (usually a comma, semi-colon, colon, tab or space).textDelimiter
- the text delimiter (usually a single or double quote).
-
-
Method Detail
-
readCategoryDataset
public CategoryDataset readCategoryDataset(java.io.Reader in) throws java.io.IOException
Reads aCategoryDataset
from a CSV file or input source.- Parameters:
in
- the input source.- Returns:
- A category dataset.
- Throws:
java.io.IOException
- if there is an I/O problem.
-
extractColumnKeys
private java.util.List extractColumnKeys(java.lang.String line)
Extracts the column keys from a string.- Parameters:
line
- a line from the input file.- Returns:
- A list of column keys.
-
extractRowKeyAndData
private void extractRowKeyAndData(java.lang.String line, DefaultCategoryDataset dataset, java.util.List columnKeys)
Extracts the row key and data for a single line from the input source.- Parameters:
line
- the line from the input source.dataset
- the dataset to be populated.columnKeys
- the column keys.
-
removeStringDelimiters
private java.lang.String removeStringDelimiters(java.lang.String key)
Removes the string delimiters from a key (as well as any white space outside the delimiters).- Parameters:
key
- the key (including delimiters).- Returns:
- The key without delimiters.
-
-