public class RecordIterator
extends java.lang.Object
implements java.util.Iterator<java.util.List<java.lang.String>>
next()
, you get back the
next record as a list of strings. You can specify the field delimiter (as a
regular expression), how many fields to expect, and whether to filter lines
containing the wrong number of fields.
The iterator may be empty, if the file is empty. If there is an
IOException
when next()
is called, it is
caught silently, and null
is returned (!).Constructor and Description |
---|
RecordIterator(java.io.InputStream in)
Returns an
Iterator over records (lists of strings)
corresponding to lines in the specified InputStream . |
RecordIterator(java.io.InputStream in,
int fields,
boolean filter,
java.lang.String delim)
Returns an
Iterator over records (lists of strings)
corresponding to lines in the specified InputStream . |
RecordIterator(java.io.Reader reader,
int fields,
boolean filter,
java.lang.String delim)
Returns an
Iterator over records (lists of strings)
corresponding to lines in the specified Reader . |
RecordIterator(java.lang.String filename)
Returns an
Iterator over records (lists of strings)
corresponding to lines in the specified file. |
RecordIterator(java.lang.String filename,
boolean filter)
Returns an
Iterator over records (lists of strings)
corresponding to lines in the specified file. |
RecordIterator(java.lang.String filename,
int fields)
Returns an
Iterator over records (lists of strings)
corresponding to lines in the specified file. |
RecordIterator(java.lang.String filename,
int fields,
boolean filter)
Returns an
Iterator over records (lists of strings)
corresponding to lines in the specified file. |
RecordIterator(java.lang.String filename,
int fields,
boolean filter,
java.lang.String delim)
Returns an
Iterator over records (lists of strings)
corresponding to lines in the specified file. |
RecordIterator(java.lang.String filename,
java.lang.String delim)
Returns an
Iterator over records (lists of strings)
corresponding to lines in the specified file. |
Modifier and Type | Method and Description |
---|---|
static int |
determineNumFields(java.lang.String filename)
A static convenience method that tells you how many fields are in the
first line of the specified file, using the default whitespace
delimiter.
|
static int |
determineNumFields(java.lang.String filename,
java.lang.String delim)
A static convenience method that tells you how many fields are in the
first line of the specified file, using the specified regexp as
delimiter.
|
static java.util.List<java.lang.String> |
firstRecord(java.lang.String filename)
A static convenience method that returns the first line of the
specified file as list of strings, using the default whitespace
delimiter.
|
static java.util.List<java.lang.String> |
firstRecord(java.lang.String filename,
java.lang.String delim)
A static convenience method that returns the first line of the
specified file as list of strings, using the specified regexp as
delimiter.
|
boolean |
hasNext() |
static void |
main(java.lang.String[] args)
Just for testing.
|
java.util.List<java.lang.String> |
next() |
void |
remove() |
public RecordIterator(java.io.Reader reader, int fields, boolean filter, java.lang.String delim)
Iterator
over records (lists of strings)
corresponding to lines in the specified Reader
.reader
- the reader to read fromfields
- how many fields to expect in each recordfilter
- whether to filter lines containing wrong number of fieldsdelim
- a regexp on which to split lines into fields (default whitespace)public RecordIterator(java.lang.String filename, int fields, boolean filter, java.lang.String delim) throws java.io.FileNotFoundException
Iterator
over records (lists of strings)
corresponding to lines in the specified file.filename
- the file to read fromfields
- how many fields to expect in each recordfilter
- whether to filter lines containing wrong number of fieldsdelim
- a regexp on which to split lines into fields (default whitespace)java.io.FileNotFoundException
public RecordIterator(java.io.InputStream in, int fields, boolean filter, java.lang.String delim)
Iterator
over records (lists of strings)
corresponding to lines in the specified InputStream
.in
- the InputStream
to read fromfields
- how many fields to expect in each recordfilter
- whether to filter lines containing wrong number of fieldsdelim
- a regexp on which to split lines into fields (default whitespace)public RecordIterator(java.lang.String filename, int fields, boolean filter) throws java.io.FileNotFoundException
Iterator
over records (lists of strings)
corresponding to lines in the specified file. The default whitespace
delimiter is used.filename
- the file to read fromfields
- how many fields to expect in each recordfilter
- whether to filter lines containing wrong number of fieldsjava.io.FileNotFoundException
public RecordIterator(java.lang.String filename, boolean filter) throws java.io.FileNotFoundException
Iterator
over records (lists of strings)
corresponding to lines in the specified file. The default whitespace
delimiter is used. The first line is used to determine how many
fields per record to expect.filename
- the file to read fromfilter
- whether to filter lines containing wrong number of fieldsjava.io.FileNotFoundException
public RecordIterator(java.lang.String filename, int fields) throws java.io.FileNotFoundException
Iterator
over records (lists of strings)
corresponding to lines in the specified file. The default whitespace
delimiter is used. Lines which contain other than fields
fields are filtered.filename
- the file to read fromfields
- how many fields to expect in each recordjava.io.FileNotFoundException
public RecordIterator(java.lang.String filename, java.lang.String delim) throws java.io.FileNotFoundException
Iterator
over records (lists of strings)
corresponding to lines in the specified file. No lines are filtered.filename
- the file to read fromdelim
- a regexp on which to split lines into fields (default whitespace)java.io.FileNotFoundException
public RecordIterator(java.lang.String filename) throws java.io.FileNotFoundException
Iterator
over records (lists of strings)
corresponding to lines in the specified file. The default whitespace
delimiter is used. No lines are filtered.filename
- the file to read fromjava.io.FileNotFoundException
public RecordIterator(java.io.InputStream in)
Iterator
over records (lists of strings)
corresponding to lines in the specified InputStream
. The
default whitespace delimiter is used. No lines are filtered.in
- the stream to read frompublic boolean hasNext()
hasNext
in interface java.util.Iterator<java.util.List<java.lang.String>>
public java.util.List<java.lang.String> next()
next
in interface java.util.Iterator<java.util.List<java.lang.String>>
public void remove()
remove
in interface java.util.Iterator<java.util.List<java.lang.String>>
public static java.util.List<java.lang.String> firstRecord(java.lang.String filename, java.lang.String delim) throws java.io.FileNotFoundException
filename
- the file to read fromdelim
- a regexp on which to split lines into fields (default whitespace)java.io.FileNotFoundException
public static java.util.List<java.lang.String> firstRecord(java.lang.String filename) throws java.io.FileNotFoundException
filename
- the file to read fromjava.io.FileNotFoundException
public static int determineNumFields(java.lang.String filename, java.lang.String delim) throws java.io.FileNotFoundException
filename
- the file to read fromdelim
- a regexp on which to split lines into fields (default whitespace)java.io.FileNotFoundException
public static int determineNumFields(java.lang.String filename) throws java.io.FileNotFoundException
filename
- the file to read fromjava.io.FileNotFoundException
public static void main(java.lang.String[] args) throws java.io.FileNotFoundException
java.io.FileNotFoundException