Package org.esa.snap.core.util.io
Class CsvReader
java.lang.Object
java.io.Reader
java.io.BufferedReader
java.io.LineNumberReader
org.esa.snap.core.util.io.CsvReader
- All Implemented Interfaces:
Closeable,AutoCloseable,Readable
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
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a CSV reader using the given column separator characters.Constructs a CSV reader using the given column separator characters and the format properties. -
Method Summary
Methods inherited from class java.io.LineNumberReader
getLineNumber, mark, read, read, readLine, reset, setLineNumber, skipMethods inherited from class java.io.BufferedReader
close, lines, markSupported, readyMethods inherited from class java.io.Reader
nullReader, read, read, transferTo
-
Constructor Details
-
CsvReader
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
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- iftrue, empty lines are ignoredcommentPrefix- if notnull, the prefix string for comment lines
-
-
Method Details
-
getSeparators
public final char[] getSeparators()- Returns:
- The column separator characters.
-
ignoresEmptyLines
public final boolean ignoresEmptyLines()- Returns:
- Are empty lines ignored?
-
getCommentPrefix
Gets the comment prefix string (if any).- Returns:
- The comment prefix string, if any.
nullotherwise.
-
readRecord
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
nullif 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
- Throws:
IOException
-
readStringRecords
Reads the complete file from the current position on. If thereadLineRecordhas 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
- Throws:
IOException
-