public class JRCsvDataSource extends JRAbstractTextDataSource
Since CSV does not specify column names, the default naming convention is to name report fields COLUMN_x and map each column with the field found at index x in each row (these indices start with 0). To avoid this situation, users can either specify a collection of column names or set a flag to read the column names from the first row of the CSV file.
Modifier and Type | Field and Description |
---|---|
protected static Log |
log |
Constructor and Description |
---|
JRCsvDataSource(java.io.File file)
Creates a datasource instance from a CSV file, using the default encoding.
|
JRCsvDataSource(java.io.File file,
java.lang.String charsetName)
Creates a datasource instance from a CSV file, using the specified encoding.
|
JRCsvDataSource(java.io.InputStream stream)
Creates a datasource instance from a CSV data input stream, using the default encoding.
|
JRCsvDataSource(java.io.InputStream stream,
java.lang.String charsetName)
Creates a datasource instance from a CSV data input stream, using the specified encoding.
|
JRCsvDataSource(java.io.Reader reader)
Creates a datasource instance from a CSV data reader.
|
JRCsvDataSource(java.lang.String location)
Creates a datasource instance that reads CSV data from a given location, using the default encoding.
|
JRCsvDataSource(java.lang.String location,
java.lang.String charsetName)
Creates a datasource instance that reads CSV data from a given location, using the specified encoding.
|
JRCsvDataSource(java.net.URL url)
Creates a datasource instance that reads CSV data from a given URL, using the default encoding.
|
JRCsvDataSource(java.net.URL url,
java.lang.String charsetName)
Creates a datasource instance that reads CSV data from a given URL, using the specified encoding.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the reader.
|
java.util.Map<java.lang.String,java.lang.Integer> |
getColumnNames() |
java.text.DateFormat |
getDateFormat()
Gets the date format that will be used to parse date fields
|
char |
getFieldDelimiter()
Returns the field delimiter character.
|
java.lang.Object |
getFieldValue(JRField jrField)
Gets the field value for the current position.
|
java.text.NumberFormat |
getNumberFormat() |
java.lang.String |
getRecordDelimiter()
Returns the record delimiter string.
|
boolean |
next()
Tries to position the cursor on the next element in the data source.
|
void |
setColumnNames(java.lang.String[] columnNames)
Specifies an array of strings representing column names matching field names in the report template
|
void |
setDateFormat(java.text.DateFormat dateFormat)
Sets the desired date format to be used for parsing date fields
|
void |
setFieldDelimiter(char fieldDelimiter)
Sets the field delimiter character.
|
void |
setNumberFormat(java.text.NumberFormat numberFormat) |
void |
setRecordDelimiter(java.lang.String recordDelimiter)
Sets the record delimiter string.
|
void |
setUseFirstRowAsHeader(boolean useFirstRowAsHeader)
Specifies whether the first line of the CSV file should be considered a table
header, containing column names matching field names in the report template
|
convertNumber, convertStringValue, getConvertBean, getDatePattern, getFormattedDate, getFormattedNumber, getLocale, getNumberPattern, getTimeZone, setDatePattern, setLocale, setLocale, setNumberPattern, setTextAttributes, setTimeZone, setTimeZone
public JRCsvDataSource(java.io.InputStream stream)
stream
- an input stream containing CSV datapublic JRCsvDataSource(java.io.InputStream stream, java.lang.String charsetName) throws java.io.UnsupportedEncodingException
stream
- an input stream containing CSV datacharsetName
- the encoding to usejava.io.UnsupportedEncodingException
public JRCsvDataSource(java.net.URL url) throws java.io.IOException
url
- an URL from where to read CSV datajava.io.IOException
public JRCsvDataSource(java.net.URL url, java.lang.String charsetName) throws java.io.IOException
url
- an URL from where to read CSV datajava.io.IOException
public JRCsvDataSource(java.io.File file) throws java.io.FileNotFoundException
file
- a file containing CSV datajava.io.FileNotFoundException
public JRCsvDataSource(java.io.File file, java.lang.String charsetName) throws java.io.FileNotFoundException, java.io.UnsupportedEncodingException
file
- a file containing CSV datacharsetName
- the encoding to usejava.io.FileNotFoundException
java.io.UnsupportedEncodingException
public JRCsvDataSource(java.lang.String location) throws JRException
location
- a String representing CSV data sourceJRException
public JRCsvDataSource(java.lang.String location, java.lang.String charsetName) throws JRException, java.io.UnsupportedEncodingException
location
- a String representing CSV data sourceJRException
java.io.UnsupportedEncodingException
public JRCsvDataSource(java.io.Reader reader)
reader
- a Reader instance, for reading the streampublic boolean next() throws JRException
JRDataSource
JRException
- if any error occurs while trying to move to the next elementpublic java.lang.Object getFieldValue(JRField jrField) throws JRException
JRDataSource
JRException
public java.text.DateFormat getDateFormat()
public void setDateFormat(java.text.DateFormat dateFormat)
public char getFieldDelimiter()
public void setFieldDelimiter(char fieldDelimiter)
fieldDelimiter
- public java.lang.String getRecordDelimiter()
public void setRecordDelimiter(java.lang.String recordDelimiter)
recordDelimiter
- public void setColumnNames(java.lang.String[] columnNames)
public void setUseFirstRowAsHeader(boolean useFirstRowAsHeader)
public void close()
public java.text.NumberFormat getNumberFormat()
public void setNumberFormat(java.text.NumberFormat numberFormat)
public java.util.Map<java.lang.String,java.lang.Integer> getColumnNames()
© 2001-2010 Jaspersoft Corporation www.jaspersoft.com