Package blbutil
Class InputIt
- java.lang.Object
-
- blbutil.InputIt
-
- All Implemented Interfaces:
FileIt<java.lang.String>,java.io.Closeable,java.lang.AutoCloseable,java.util.Iterator<java.lang.String>
public class InputIt extends java.lang.Object implements FileIt<java.lang.String>
Class
InputItis a buffered iterator whosenext()method returns lines of a text input stream.If an
Instances of classIOExceptionis thrown when anInputItinstance reads from the text input stream, theIOExceptionis trapped, an error message is written to standard out, and the Java Virtual Machine is terminated.InputItare not thread-safe.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Stops reading data elements and releases any system resources that are held by this object.java.io.Filefile()Returns the file from which the data are read, ornullif the data are read from standard input or if the data source is unknown.static InputItfromGzipFile(java.io.File file)Constructs and returns anInputItinstance with the default buffer size that iterates through lines of the specified compressed or uncompressed text file.static InputItfromGzipFile(java.io.File file, int bufferSize)Constructs and returns anInputItinstance with the specified buffer size that iterates through lines of the specified compressed or uncompressed text file.static InputItfromStdIn()Constructs and returns anInputItinstance with the default buffer size that iterates through lines of text read from standard input.static InputItfromStdIn(int bufferSize)Constructs and returns anInputItinstance with the specified buffer size that iterates through lines of text read from standard input.static InputItfromTextFile(java.io.File file)Constructs and returns anInputItinstance with the default buffer size that iterates through lines of the specified text file.static InputItfromTextFile(java.io.File file, int bufferSize)Constructs and returns anInputItinstance with the specified buffer size that iterates through lines of the specified text file.booleanhasNext()Returnstrueif the iteration has more elements.java.lang.Stringnext()Returns the next element in the iteration.voidremove()Theremovemethod is not supported by this iterator.java.lang.StringtoString()Returns a string representation of this iterator.
-
-
-
Method Detail
-
file
public java.io.File file()
Description copied from interface:FileItReturns the file from which the data are read, ornullif the data are read from standard input or if the data source is unknown.
-
hasNext
public boolean hasNext()
Returnstrueif the iteration has more elements.- Specified by:
hasNextin interfacejava.util.Iterator<java.lang.String>- Returns:
trueif the iteration has more elements
-
next
public java.lang.String next()
Returns the next element in the iteration.- Specified by:
nextin interfacejava.util.Iterator<java.lang.String>- Returns:
- the next element in the iteration
- Throws:
java.util.NoSuchElementException- if the iteration has no more elements
-
remove
public void remove()
Theremovemethod is not supported by this iterator.- Specified by:
removein interfacejava.util.Iterator<java.lang.String>- Throws:
java.lang.UnsupportedOperationException- if this method is invoked
-
close
public void close()
Description copied from interface:FileItStops reading data elements and releases any system resources that are held by this object. Buffered data elements may remain accessible via thehasNext()andnext()methods after invokingclose(). After invokingclose(), further invocations ofclose()have no effect.
-
toString
public java.lang.String toString()
Returns a string representation of this iterator. The exact details of the representation are unspecified and subject to change.
-
fromStdIn
public static InputIt fromStdIn()
Constructs and returns anInputItinstance with the default buffer size that iterates through lines of text read from standard input.- Returns:
- a new
InputItinstance that iterates through lines of text read from standard input
-
fromStdIn
public static InputIt fromStdIn(int bufferSize)
Constructs and returns anInputItinstance 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
InputItinstance that iterates through lines of text read from standard input - Throws:
java.lang.IllegalArgumentException- ifbufferSize < 0
-
fromGzipFile
public static InputIt fromGzipFile(java.io.File file)
Constructs and returns anInputItinstance 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
InputItinstance that iterates through lines of the specified text file - Throws:
java.lang.NullPointerException- iffile == null
-
fromGzipFile
public static InputIt fromGzipFile(java.io.File file, int bufferSize)
Constructs and returns anInputItinstance 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 filebufferSize- the buffer size in bytes- Returns:
- a new
InputItinstance that iterates through lines of the specified text file - Throws:
java.lang.IllegalArgumentException- ifbufferSize < 0java.lang.NullPointerException- iffile == null
-
fromTextFile
public static InputIt fromTextFile(java.io.File file)
Constructs and returns anInputItinstance with the default buffer size that iterates through lines of the specified text file.- Parameters:
file- a text file- Returns:
- a new
InputItinstance that iterates through lines of the specified text file - Throws:
java.lang.NullPointerException- iffilename == null
-
fromTextFile
public static InputIt fromTextFile(java.io.File file, int bufferSize)
Constructs and returns anInputItinstance with the specified buffer size that iterates through lines of the specified text file.- Parameters:
file- a text filebufferSize- the buffer size in bytes- Returns:
- a new
InputItinstance that iterates through lines of the specified text file - Throws:
java.lang.IllegalArgumentException- ifbufferSize < 0java.lang.NullPointerException- iffilename == null
-
-