com.google.visualization.datasource.util
Class CsvDataSourceHelper

java.lang.Object
  extended by com.google.visualization.datasource.util.CsvDataSourceHelper

public class CsvDataSourceHelper
extends java.lang.Object

Helper class with static utility methods that are specific for building a data source based on CSV (Comma Separated Values) files. The main functionality is taking a CSV and generating a data table.

Author:
Nimrod T.

Method Summary
static java.io.Reader getCsvFileReader(java.lang.String file)
          Returns a Reader for the file.
static java.io.Reader getCsvUrlReader(java.lang.String url)
          Returns a Reader for the url.
static DataTable read(java.io.Reader reader, java.util.List<ColumnDescription> columnDescriptions, java.lang.Boolean headerRow)
           
static DataTable read(java.io.Reader reader, java.util.List<ColumnDescription> columnDescriptions, java.lang.Boolean headerRow, com.ibm.icu.util.ULocale locale)
          Translates a CSV formatted input into a data table representation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

read

public static DataTable read(java.io.Reader reader,
                             java.util.List<ColumnDescription> columnDescriptions,
                             java.lang.Boolean headerRow)
                      throws java.io.IOException,
                             CsvDataSourceException
Throws:
java.io.IOException
CsvDataSourceException
See Also:
read(java.io.Reader, java.util.List, Boolean, ULocale)

read

public static DataTable read(java.io.Reader reader,
                             java.util.List<ColumnDescription> columnDescriptions,
                             java.lang.Boolean headerRow,
                             com.ibm.icu.util.ULocale locale)
                      throws java.io.IOException,
                             CsvDataSourceException
Translates a CSV formatted input into a data table representation. The reader parameter should point to a CSV file.

Parameters:
reader - The CSV input Reader from which to read.
columnDescriptions - The column descriptions. If columnDescriptions is null, then it is assumed that all values are strings, and the number of the columns is equal to the number of the columns in the first line of the reader. If headerRow is set to true, and the columnDescriptions does not contain the labels of the columns, then the headerRow values are used as the column labels.
headerRow - True if there is an header row. In that case, the first line of the csv is taken as the header row.
locale - An optional locale in which to parse the input csv file. If null, uses the default from LocaleUtil#getDefaultLocale.
Returns:
A data table with the values populated from the CSV file.
Throws:
java.io.IOException - In case of error reading from the reader.
CsvDataSourceException - In case of specific csv error.

getCsvUrlReader

public static java.io.Reader getCsvUrlReader(java.lang.String url)
                                      throws DataSourceException
Returns a Reader for the url. Given a specific url, returns a Reader for that url, so that the CSV data source will be able to read the CSV file from that url.

Parameters:
url - The url to get a Reader for.
Returns:
A Reader for the given url.
Throws:
DataSourceException - In case of a problem reading from the url.

getCsvFileReader

public static java.io.Reader getCsvFileReader(java.lang.String file)
                                       throws DataSourceException
Returns a Reader for the file. Given a specific file, returns a Reader to that file, so that the CSV data source will be able to read the CSV file from that file.

Parameters:
file - The file to get a Reader for.
Returns:
A Reader for the given file.
Throws:
DataSourceException - In case of a problem reading from the file.


Copyright © 2009 Google. All Rights Reserved.