org.esa.beam.util.io
Class CsvReader
java.lang.Object
java.io.Reader
java.io.BufferedReader
java.io.LineNumberReader
org.esa.beam.util.io.CsvReader
- All Implemented Interfaces:
- Closeable, Readable
public class CsvReader
- extends LineNumberReader
A CsvReader instance is used read text files with CSV (comma separated values) format.
This reader interprets each line of a text file as record (also empty lines). The fields of the record are
delimited by a single separator character which must not necessarily be a comma.
- Version:
- 1.1
- Author:
- Norman Fomferra
|
Constructor Summary |
CsvReader(Reader reader,
char[] separators)
Constructs a CSV reader using the given column separator characters. |
CsvReader(Reader reader,
char[] separators,
boolean ignoreEmptyLines,
String commentPrefix)
Constructs a CSV reader using the given column separator characters and the format properties. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
CsvReader
public CsvReader(Reader reader,
char[] separators)
- Constructs a CSV reader using the given column separator characters. The new reader will not ignore empty lines
and does not recognize comment lines.
- Parameters:
reader - the underlying reader to be wrappedseparators - the column separator characters
CsvReader
public CsvReader(Reader reader,
char[] separators,
boolean ignoreEmptyLines,
String commentPrefix)
- Constructs a CSV reader using the given column separator characters and the format properties.
- Parameters:
reader - the underlying reader to be wrappedseparators - the column separator charactersignoreEmptyLines - if true, empty lines are ignoredcommentPrefix - if not null, the prefix string for comment lines
getSeparators
public final char[] getSeparators()
- Returns:
- The column separator characters.
ignoresEmptyLines
public final boolean ignoresEmptyLines()
- Returns:
- Are empty lines ignored?
getCommentPrefix
public final String getCommentPrefix()
- Gets the comment prefix string (if any).
- Returns:
- The comment prefix string, if any.
null otherwise.
readRecord
public String[] readRecord()
throws IOException
- Reads a record info from the database. A record is represented by a complete line in the CSV formatted text
file.
Leading and trailing whitespaces removed from each column value. For empty lines, the method returns an
array of the length zero. The method returns
null if the end of file has been reached.
- Returns:
- a record containing the tokens delimited by the separator character passed to the constructor
- Throws:
IOException - if an I/O error occurs
readDoubleRecord
public double[] readDoubleRecord()
throws IOException
- Throws:
IOException
readStringRecords
public List<String[]> readStringRecords()
throws IOException
- Reads the complete file from the current position on. If the
readLineRecord has not previously been
called the method reads all records from the beginning of the file. For empty files, the method returns an vector
having a zero size.
- Returns:
- an vector of
String[] records containing the tokens delimitted by the separator character
passed to the constructor
- Throws:
IOException - if an I/O error occurs
readDoubleRecords
public List<double[]> readDoubleRecords()
throws IOException
- Throws:
IOException
Copyright © 2002-2012 Brockmann Consult GmbH. All Rights Reserved.