org.apache.mahout.common
Class FileLineIterator

java.lang.Object
  extended by org.apache.mahout.common.FileLineIterator
All Implemented Interfaces:
java.io.Closeable, java.util.Iterator<java.lang.String>, SkippingIterator<java.lang.String>

public final class FileLineIterator
extends java.lang.Object
implements SkippingIterator<java.lang.String>, java.io.Closeable

Iterates over the lines of a text file. This assumes the text file's lines are delimited in a manner consistent with how BufferedReader defines lines. This class will uncompress files that end in .zip or .gz accordingly, too.


Constructor Summary
FileLineIterator(java.io.File file)
          Creates a over a given file, assuming a UTF-8 encoding.
FileLineIterator(java.io.File file, boolean skipFirstLine)
          Creates a over a given file, assuming a UTF-8 encoding.
FileLineIterator(java.io.File file, java.nio.charset.Charset encoding, boolean skipFirstLine)
          Creates a over a given file, using the given encoding.
FileLineIterator(java.io.InputStream is)
           
FileLineIterator(java.io.InputStream is, boolean skipFirstLine)
           
FileLineIterator(java.io.InputStream is, java.nio.charset.Charset encoding, boolean skipFirstLine)
           
 
Method Summary
 void close()
           
 boolean hasNext()
           
 java.lang.String next()
           
 java.lang.String peek()
           
 void remove()
           
 void skip(int n)
          Skip the next n elements supplied by this Iterator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileLineIterator

public FileLineIterator(java.io.File file)
                 throws java.io.IOException
Creates a over a given file, assuming a UTF-8 encoding.

Throws:
java.io.FileNotFoundException - if the file does not exist
java.io.IOException - if the file cannot be read

FileLineIterator

public FileLineIterator(java.io.File file,
                        boolean skipFirstLine)
                 throws java.io.IOException
Creates a over a given file, assuming a UTF-8 encoding.

Throws:
java.io.FileNotFoundException - if the file does not exist
java.io.IOException - if the file cannot be read

FileLineIterator

public FileLineIterator(java.io.File file,
                        java.nio.charset.Charset encoding,
                        boolean skipFirstLine)
                 throws java.io.IOException
Creates a over a given file, using the given encoding.

Throws:
java.io.FileNotFoundException - if the file does not exist
java.io.IOException - if the file cannot be read

FileLineIterator

public FileLineIterator(java.io.InputStream is)
                 throws java.io.IOException
Throws:
java.io.IOException

FileLineIterator

public FileLineIterator(java.io.InputStream is,
                        boolean skipFirstLine)
                 throws java.io.IOException
Throws:
java.io.IOException

FileLineIterator

public FileLineIterator(java.io.InputStream is,
                        java.nio.charset.Charset encoding,
                        boolean skipFirstLine)
                 throws java.io.IOException
Throws:
java.io.IOException
Method Detail

peek

public java.lang.String peek()

hasNext

public boolean hasNext()
Specified by:
hasNext in interface java.util.Iterator<java.lang.String>

next

public java.lang.String next()
Specified by:
next in interface java.util.Iterator<java.lang.String>

remove

public void remove()
Specified by:
remove in interface java.util.Iterator<java.lang.String>
Throws:
java.lang.UnsupportedOperationException

skip

public void skip(int n)
Description copied from interface: SkippingIterator
Skip the next n elements supplied by this Iterator. If there are less than n elements remaining, this skips all remaining elements in the Iterator. This method has the same effect as calling Iterator.next() n times, except that it will never throw NoSuchElementException.

Specified by:
skip in interface SkippingIterator<java.lang.String>

close

public void close()
Specified by:
close in interface java.io.Closeable


Copyright © 2008-2010 The Apache Software Foundation. All Rights Reserved.