public class TextTableInput extends AbstractTableInput implements ColumnMetadataHolder
Report input implementation for streams (files, urls, etc) backed by a
java.io.BufferedReader
By default this implementation expects a comma (,) as data separator but you
can use the #setSeparator(String) method to specify whatever separator you
want
DEFAULT_COLUMN_HEADER| Constructor and Description |
|---|
TextTableInput()
empty text imput constructor.
|
TextTableInput(InputStream is)
creates a report input for the given input stream using the utf-8
encoding and comma as data-separator
|
TextTableInput(InputStream is,
String separator)
creates a report input for the given InputStream using the utf-8 encoding
and the specified data-separator
|
TextTableInput(InputStream is,
String separator,
String encoding)
creates a report input for the given InputStream using the specified
encoding and data-separator
|
TextTableInput(InputStream is,
String separator,
String encoding,
boolean firstLineIsHeader)
creates a report input for the given InputStream using the specified
encoding and data-separator
|
TextTableInput(Reader inReader)
creates a report-input based on the provided reader using comma as
data-separator
|
TextTableInput(Reader reader,
String separator)
creates a report-input based on the provided reader and using separator
to distinguish between data/columns
|
TextTableInput(Reader inReader,
String separator,
boolean firstLineIsHeaderFlag)
creates a report-input based on the provided reader and using separator
to distinguish between data/columns
|
TextTableInput(String filePath)
creates a report input for the given file with comma as separator in the
default encoding
|
TextTableInput(String filePath,
String separator)
Creates a report input from the given fileName (in the default encoding)
using the separator
|
TextTableInput(String filePath,
String separator,
String encoding)
Creates an input for the given fileName using the provided separator.
|
TextTableInput(String filePath,
String separator,
String encoding,
boolean firstLineIsHeader)
Creates an input for the given fileName using the provided separator.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
closes the input and releases all resources
|
List<ColumnMetadata> |
getColumnMetadata()
getter for columns metadata (column label/header, horizontal alignment, etc.)
|
Reader |
getInputReader()
returns the input reader
|
String |
getSeparator()
getter for separator
|
boolean |
hasMoreRows()
returns true if there are more rows to read otherwise false
|
boolean |
isFirstLineHeader() |
List<Object> |
nextRow()
returns the next row of data if any row available otherwise returns null
You should combine this method with #hasMoreRows() or you can iterate through the rows until null is returned Example: while (input.hasMoreRows()) { Object[] dataRow = input.nextRow(); // do something with data } |
void |
open()
prepares the reader for further usaga.
|
void |
setFilePath(String filePath) |
void |
setFirstLineHeader(boolean flag) |
void |
setInputReader(Reader reader)
registers the provided input reader
|
void |
setSeparator(String separator)
registers the data-separator which is used to differentiate among
colums-data
|
getStatuspublic TextTableInput()
setInputReader(Reader)public TextTableInput(String filePath)
filePath - the path name of the file containing dataFileNotFoundExceptionpublic TextTableInput(String filePath, String separator)
filePath - path and filenameseparator - data-separatorpublic TextTableInput(String filePath, String separator, String encoding)
filePath - the path of the file containing dataseparator - the separator used to identify data/columnencoding - the encoding used when reading the fileFileNotFoundExceptionpublic TextTableInput(String filePath, String separator, String encoding, boolean firstLineIsHeader)
filePath - the path of the file containing dataseparator - the separator used to identify data/columnencoding - the encoding used when reading the filefirstLineIsHeader - specifies whether the first line contains the column headers
or notpublic TextTableInput(InputStream is)
is - the input streampublic TextTableInput(InputStream is, String separator)
is - the input streamseparator - data-separatorUnsupportedEncodingExceptionpublic TextTableInput(InputStream is, String separator, String encoding)
is - the input streamseparator - data separatorencoding - the encodingUnsupportedEncodingExceptionpublic TextTableInput(InputStream is, String separator, String encoding, boolean firstLineIsHeader)
is - the input streamseparator - data separatorencoding - the encodingencoding - this flag specifies whether or not the first line contains the
column headersUnsupportedEncodingExceptionpublic TextTableInput(Reader inReader)
inReader - the readerpublic TextTableInput(Reader reader, String separator)
inReader - the readerseparator - the separator used to identify data/columnspublic TextTableInput(Reader inReader, String separator, boolean firstLineIsHeaderFlag)
inReader - the readerseparator - the separator used to identify data/columnsfirstLineIsHeaderFlag - this flag specifies if the first line contains the column
headerspublic void open()
open in interface TableInputopen in class AbstractTableInputpublic void close()
close in interface TableInputclose in class AbstractTableInputpublic List<Object> nextRow()
while (input.hasMoreRows()) {
Object[] dataRow = input.nextRow();
// do something with data
}
nextRow in interface TableInputpublic boolean hasMoreRows()
hasMoreRows in interface TableInputpublic String getSeparator()
public void setSeparator(String separator)
separator - the data/column separatorpublic void setInputReader(Reader reader)
reader - public Reader getInputReader()
public void setFirstLineHeader(boolean flag)
flag - public boolean isFirstLineHeader()
public void setFilePath(String filePath)
filePath - the filePath to setpublic List<ColumnMetadata> getColumnMetadata()
ColumnMetadataHoldergetter for columns metadata (column label/header, horizontal alignment, etc.)
This is an optional method. If your input doesn't contain any meta data then return an empty array.getColumnMetadata in interface ColumnMetadataHolderCopyright © 2006–2015. All rights reserved.