jhplot.io.csv
Class CSVReader
- java.lang.Object
-
- jhplot.io.csv.CSVReader
-
- All Implemented Interfaces:
- java.io.Closeable, java.lang.AutoCloseable
public class CSVReader extends java.lang.Object implements java.io.Closeable
A very simple CSV reader released under a commercial-friendly license.
-
-
Field Summary
Fields Modifier and Type Field and Description static int
DEFAULT_SKIP_LINES
The default line to start reading.
-
Constructor Summary
Constructors Constructor and Description CSVReader(java.io.BufferedReader reader, char separator)
Constructs CSVReader with supplied separator.CSVReader(java.io.BufferedReader reader, char separator, char quotechar, char escape, int line, boolean strictQuotes, boolean ignoreLeadingWhiteSpace)
Constructs CSVReader with supplied separator and quote char.CSVReader(java.io.File file, char separator)
Constructs CSVReader with supplied separator.CSVReader(java.io.Reader reader)
Constructs CSVReader using a comma for the separator.CSVReader(java.io.Reader reader, char separator)
Constructs CSVReader with supplied separator.CSVReader(java.io.Reader reader, char separator, char quotechar)
Constructs CSVReader with supplied separator and quote char.CSVReader(java.io.Reader reader, char separator, char quotechar, boolean strictQuotes)
Constructs CSVReader with supplied separator, quote char and quote handling behavior.CSVReader(java.io.Reader reader, char separator, char quotechar, char escape)
Constructs CSVReader with supplied separator and quote char.CSVReader(java.io.Reader reader, char separator, char quotechar, char escape, int line)
Constructs CSVReader with supplied separator and quote char.CSVReader(java.io.Reader reader, char separator, char quotechar, char escape, int line, boolean strictQuotes)
Constructs CSVReader with supplied separator and quote char.CSVReader(java.io.Reader reader, char separator, char quotechar, char escape, int line, boolean strictQuotes, boolean ignoreLeadingWhiteSpace)
Constructs CSVReader with supplied separator and quote char.CSVReader(java.io.Reader reader, char separator, char quotechar, int line)
Constructs CSVReader with supplied separator and quote char.CSVReader(java.lang.String file, char separator)
Constructs CSVReader with supplied separator.CSVReader(java.lang.String file, char separator, char quotechar)
Constructs CSVReader with supplied separator and quote char.CSVReader(java.net.URL url, char separator)
Constructs CSVReader with supplied separator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description void
close()
Closes the underlying reader.java.lang.String[]
next()
Reads the next line from the buffer and converts to a string array.java.util.List<java.lang.String[]>
readAll()
Reads the entire file into a List with each element being a String[] of tokens.java.lang.String[]
readNext()
Reads the next line from the buffer and converts to a string array.
-
-
-
Field Detail
-
DEFAULT_SKIP_LINES
public static final int DEFAULT_SKIP_LINES
The default line to start reading.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CSVReader
public CSVReader(java.io.Reader reader)
Constructs CSVReader using a comma for the separator.- Parameters:
reader
- the reader to an underlying CSV source.
-
CSVReader
public CSVReader(java.io.Reader reader, char separator)
Constructs CSVReader with supplied separator.- Parameters:
reader
- the reader to an underlying CSV source.separator
- the delimiter to use for separating entries.
-
CSVReader
public CSVReader(java.lang.String file, char separator) throws java.lang.Exception
Constructs CSVReader with supplied separator.- Parameters:
file
- fileseparator
- the delimiter to use for separating entries.- Throws:
java.lang.Exception
-
CSVReader
public CSVReader(java.io.File file, char separator) throws java.lang.Exception
Constructs CSVReader with supplied separator.- Parameters:
file
- URL file URLseparator
- the delimiter to use for separating entries.- Throws:
java.lang.Exception
-
CSVReader
public CSVReader(java.net.URL url, char separator) throws java.lang.Exception
Constructs CSVReader with supplied separator.- Parameters:
file
- URL file URLseparator
- the delimiter to use for separating entries.- Throws:
java.lang.Exception
-
CSVReader
public CSVReader(java.io.BufferedReader reader, char separator)
Constructs CSVReader with supplied separator.- Parameters:
reader
- the reader to an underlying CSV source.separator
- the delimiter to use for separating entries.
-
CSVReader
public CSVReader(java.io.Reader reader, char separator, char quotechar)
Constructs CSVReader with supplied separator and quote char.- Parameters:
reader
- the reader to an underlying CSV source.separator
- the delimiter to use for separating entriesquotechar
- the character to use for quoted elements
-
CSVReader
public CSVReader(java.lang.String file, char separator, char quotechar) throws java.lang.Exception
Constructs CSVReader with supplied separator and quote char.- Parameters:
reader
- the reader to an underlying CSV source.separator
- the delimiter to use for separating entriesquotechar
- the character to use for quoted elements- Throws:
java.lang.Exception
-
CSVReader
public CSVReader(java.io.Reader reader, char separator, char quotechar, boolean strictQuotes)
Constructs CSVReader with supplied separator, quote char and quote handling behavior.- Parameters:
reader
- the reader to an underlying CSV source.separator
- the delimiter to use for separating entriesquotechar
- the character to use for quoted elementsstrictQuotes
- sets if characters outside the quotes are ignored
-
CSVReader
public CSVReader(java.io.Reader reader, char separator, char quotechar, char escape)
Constructs CSVReader with supplied separator and quote char.- Parameters:
reader
- the reader to an underlying CSV source.separator
- the delimiter to use for separating entriesquotechar
- the character to use for quoted elementsescape
- the character to use for escaping a separator or quote
-
CSVReader
public CSVReader(java.io.Reader reader, char separator, char quotechar, int line)
Constructs CSVReader with supplied separator and quote char.- Parameters:
reader
- the reader to an underlying CSV source.separator
- the delimiter to use for separating entriesquotechar
- the character to use for quoted elementsline
- the line number to skip for start reading
-
CSVReader
public CSVReader(java.io.Reader reader, char separator, char quotechar, char escape, int line)
Constructs CSVReader with supplied separator and quote char.- Parameters:
reader
- the reader to an underlying CSV source.separator
- the delimiter to use for separating entriesquotechar
- the character to use for quoted elementsescape
- the character to use for escaping a separator or quoteline
- the line number to skip for start reading
-
CSVReader
public CSVReader(java.io.Reader reader, char separator, char quotechar, char escape, int line, boolean strictQuotes)
Constructs CSVReader with supplied separator and quote char.- Parameters:
reader
- the reader to an underlying CSV source.separator
- the delimiter to use for separating entriesquotechar
- the character to use for quoted elementsescape
- the character to use for escaping a separator or quoteline
- the line number to skip for start readingstrictQuotes
- sets if characters outside the quotes are ignored
-
CSVReader
public CSVReader(java.io.Reader reader, char separator, char quotechar, char escape, int line, boolean strictQuotes, boolean ignoreLeadingWhiteSpace)
Constructs CSVReader with supplied separator and quote char.- Parameters:
reader
- the reader to an underlying CSV source.separator
- the delimiter to use for separating entriesquotechar
- the character to use for quoted elementsescape
- the character to use for escaping a separator or quoteline
- the line number to skip for start readingstrictQuotes
- sets if characters outside the quotes are ignoredignoreLeadingWhiteSpace
- it true, parser should ignore white space before a quote in a field
-
CSVReader
public CSVReader(java.io.BufferedReader reader, char separator, char quotechar, char escape, int line, boolean strictQuotes, boolean ignoreLeadingWhiteSpace)
Constructs CSVReader with supplied separator and quote char.- Parameters:
reader
- the reader to an underlying CSV source.separator
- the delimiter to use for separating entriesquotechar
- the character to use for quoted elementsescape
- the character to use for escaping a separator or quoteline
- the line number to skip for start readingstrictQuotes
- sets if characters outside the quotes are ignoredignoreLeadingWhiteSpace
- it true, parser should ignore white space before a quote in a field
-
-
Method Detail
-
readAll
public java.util.List<java.lang.String[]> readAll() throws java.io.IOException
Reads the entire file into a List with each element being a String[] of tokens.- Returns:
- a List of String[], with each String[] representing a line of the file.
- Throws:
java.io.IOException
- if bad things happen during the read
-
readNext
public java.lang.String[] readNext() throws java.io.IOException
Reads the next line from the buffer and converts to a string array.- Returns:
- a string array with each comma-separated element as a separate entry.
- Throws:
java.io.IOException
- if bad things happen during the read
-
next
public java.lang.String[] next() throws java.io.IOException
Reads the next line from the buffer and converts to a string array. Same as getNextLine().- Returns:
- a string array with each comma-separated element as a separate entry.
- Throws:
java.io.IOException
- if bad things happen during the read
-
close
public void close() throws java.io.IOException
Closes the underlying reader.- Specified by:
close
in interfacejava.io.Closeable
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Throws:
java.io.IOException
- if the close fails
-
-
DMelt 3.0 © DataMelt by jWork.ORG