Package blbutil

Class InputIt

java.lang.Object
blbutil.InputIt
All Implemented Interfaces:
FileIt<String>, Closeable, AutoCloseable, Iterator<String>

public class InputIt extends Object implements FileIt<String>

Class InputIt is a buffered iterator whose next() method returns lines of a text input stream.

If an IOException is thrown when an InputIt instance reads from the text input stream, the IOException is trapped, an error message is written to standard out, and the Java Virtual Machine is terminated.

Instances of class InputIt are not thread-safe.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Stops reading data elements and releases any system resources that are held by this object.
    Returns the file from which the data are read, or null if the data are read from standard input or if the data source is unknown.
    static InputIt
    Constructs and returns an InputIt instance with the default buffer size that iterates through lines of the specified compressed or uncompressed text file.
    static InputIt
    fromGzipFile(File file, int bufferSize)
    Constructs and returns an InputIt instance with the specified buffer size that iterates through lines of the specified compressed or uncompressed text file.
    static InputIt
    Constructs and returns an InputIt instance with the default buffer size that iterates through lines of text read from standard input.
    static InputIt
    fromStdIn(int bufferSize)
    Constructs and returns an InputIt instance with the specified buffer size that iterates through lines of text read from standard input.
    static InputIt
    Constructs and returns an InputIt instance with the default buffer size that iterates through lines of the specified text file.
    static InputIt
    fromTextFile(File file, int bufferSize)
    Constructs and returns an InputIt instance with the specified buffer size that iterates through lines of the specified text file.
    boolean
    Returns true if the iteration has more elements.
    Returns the next element in the iteration.
    void
    The remove method is not supported by this iterator.
    Returns a string representation of this iterator.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface java.util.Iterator

    forEachRemaining
  • Method Details

    • file

      public File file()
      Description copied from interface: FileIt
      Returns the file from which the data are read, or null if the data are read from standard input or if the data source is unknown.
      Specified by:
      file in interface FileIt<String>
      Returns:
      the file from which the data are read, or null if the data are read from standard input or if the data source is unknown
    • hasNext

      public boolean hasNext()
      Returns true if the iteration has more elements.
      Specified by:
      hasNext in interface Iterator<String>
      Returns:
      true if the iteration has more elements
    • next

      public String next()
      Returns the next element in the iteration.
      Specified by:
      next in interface Iterator<String>
      Returns:
      the next element in the iteration
      Throws:
      NoSuchElementException - if the iteration has no more elements
    • remove

      public void remove()
      The remove method is not supported by this iterator.
      Specified by:
      remove in interface Iterator<String>
      Throws:
      UnsupportedOperationException - if this method is invoked
    • close

      public void close()
      Description copied from interface: FileIt
      Stops reading data elements and releases any system resources that are held by this object. Buffered data elements may remain accessible via the hasNext() and next() methods after invoking close(). After invoking close(), further invocations of close() have no effect.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface FileIt<String>
    • toString

      public String toString()
      Returns a string representation of this iterator. The exact details of the representation are unspecified and subject to change.
      Specified by:
      toString in interface FileIt<String>
      Overrides:
      toString in class Object
      Returns:
      a string representation of this iterator
    • fromStdIn

      public static InputIt fromStdIn()
      Constructs and returns an InputIt instance with the default buffer size that iterates through lines of text read from standard input.
      Returns:
      a new InputIt instance that iterates through lines of text read from standard input
    • fromStdIn

      public static InputIt fromStdIn(int bufferSize)
      Constructs and returns an InputIt instance with the specified buffer size that iterates through lines of text read from standard input.
      Parameters:
      bufferSize - the buffer size in bytes
      Returns:
      a new InputIt instance that iterates through lines of text read from standard input
      Throws:
      IllegalArgumentException - if bufferSize < 0
    • fromGzipFile

      public static InputIt fromGzipFile(File file)
      Constructs and returns an InputIt instance with the default buffer size that iterates through lines of the specified compressed or uncompressed text file. If the filename ends in ".gz", the file must be either BGZIP-compressed or GZIP-compressed.
      Parameters:
      file - a compressed or uncompressed text file
      Returns:
      a new InputIt instance that iterates through lines of the specified text file
      Throws:
      NullPointerException - if file == null
    • fromGzipFile

      public static InputIt fromGzipFile(File file, int bufferSize)
      Constructs and returns an InputIt instance with the specified buffer size that iterates through lines of the specified compressed or uncompressed text file. If the filename ends in ".gz", the file must be either BGZIP-compressed or GZIP-compressed.
      Parameters:
      file - a compressed or uncompressed text file
      bufferSize - the buffer size in bytes
      Returns:
      a new InputIt instance that iterates through lines of the specified text file
      Throws:
      IllegalArgumentException - if bufferSize < 0
      NullPointerException - if file == null
    • fromTextFile

      public static InputIt fromTextFile(File file)
      Constructs and returns an InputIt instance with the default buffer size that iterates through lines of the specified text file.
      Parameters:
      file - a text file
      Returns:
      a new InputIt instance that iterates through lines of the specified text file
      Throws:
      NullPointerException - if filename == null
    • fromTextFile

      public static InputIt fromTextFile(File file, int bufferSize)
      Constructs and returns an InputIt instance with the specified buffer size that iterates through lines of the specified text file.
      Parameters:
      file - a text file
      bufferSize - the buffer size in bytes
      Returns:
      a new InputIt instance that iterates through lines of the specified text file
      Throws:
      IllegalArgumentException - if bufferSize < 0
      NullPointerException - if filename == null