javatools.filehandlers
Class CSVLines

java.lang.Object
  extended by javatools.datatypes.PeekIterator<java.util.List<java.lang.String>>
      extended by javatools.filehandlers.CSVLines
All Implemented Interfaces:
java.io.Closeable, java.lang.Iterable<java.util.List<java.lang.String>>, java.util.Iterator<java.util.List<java.lang.String>>

public class CSVLines
extends PeekIterator<java.util.List<java.lang.String>>

This class is part of the Java Tools (see http://mpii.de/yago-naga/javatools). It is licensed under the Creative Commons Attribution License (see http://creativecommons.org/licenses/by/3.0) by the YAGO-NAGA team (see http://mpii.de/yago-naga). The class provides an iterator over the lines in a comma-separated file
Example:

      for(List columns : new CSVFile("c:\\autoexec.csv")) {
         System.out.println(columns);
      }
  
Recognizes column headers if introduced by '#'. Recognizes all types of encodings (see Char.decode()).


Nested Class Summary
 
Nested classes/interfaces inherited from class javatools.datatypes.PeekIterator
PeekIterator.ElementaryPeekIterator<T>, PeekIterator.SimplePeekIterator<T>
 
Field Summary
 
Fields inherited from class javatools.datatypes.PeekIterator
closed, initialized, next
 
Constructor Summary
CSVLines(java.io.File f)
          Constructs a CSVReader
CSVLines(java.io.Reader reader)
          Constructs a CSVReader
CSVLines(java.lang.String file)
          Constructs a CSVReader
 
Method Summary
 void close()
          Closes the underlying resource
 java.util.List<java.lang.String> columnNames()
          returns the column names (or NULL)
static void main(java.lang.String[] args)
          Test method
 java.lang.Integer numColumns()
          returns the number of columns (or NULL)
 void setSeparator(char s)
          Sets the separator (comma by default)
 
Methods inherited from class javatools.datatypes.PeekIterator
asList, asList, asSet, asSet, asSet, emptyIterator, hasNext, iterator, list, list, next, nextOrNull, numElements, numElements, peek, remove, toString, toString, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CSVLines

public CSVLines(java.io.File f)
         throws java.io.IOException
Constructs a CSVReader

Throws:
java.io.IOException

CSVLines

public CSVLines(java.io.Reader reader)
         throws java.io.IOException
Constructs a CSVReader

Throws:
java.io.IOException

CSVLines

public CSVLines(java.lang.String file)
         throws java.io.IOException
Constructs a CSVReader

Throws:
java.io.IOException
Method Detail

setSeparator

public void setSeparator(char s)
Sets the separator (comma by default)


columnNames

public java.util.List<java.lang.String> columnNames()
returns the column names (or NULL)


numColumns

public java.lang.Integer numColumns()
returns the number of columns (or NULL)


close

public void close()
Description copied from class: PeekIterator
Closes the underlying resource

Specified by:
close in interface java.io.Closeable
Overrides:
close in class PeekIterator<java.util.List<java.lang.String>>

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Test method

Throws:
java.lang.Exception