public class FileLines extends PeekIterator<java.lang.String> implements java.lang.Iterable<java.lang.String>, java.util.Iterator<java.lang.String>, java.io.Closeable
for (String s : new FileLines("c:\\autoexec.bat")) {
System.out.println(s);
}
If desired, the iterator can make a nice progress bar by calling
Announce.progressStart/At/Done automatically in the right order. If there are
no more lines, the file is closed. If you do not use all lines of the
iterator, close the iterator manually.PeekIterator.ElementaryPeekIterator<T>, PeekIterator.SimplePeekIterator<T>| Modifier and Type | Field and Description |
|---|---|
protected long |
announceChars
number of chars for announce (or -1)
|
protected java.io.BufferedReader |
br
Containes the Reader
|
static long |
maxChars
Maximum chars to read by readTo (or -1)
|
closed, EMPTY, initialized, next| Modifier | Constructor and Description |
|---|---|
protected |
FileLines()
For subclasses
|
|
FileLines(java.io.BufferedReader r)
Constructs FileLines from a BufferedReader (main constructor 3)
|
|
FileLines(java.io.File f)
Constructs FileLines from a file
|
|
FileLines(java.io.File f,
java.lang.String announceMsg)
Constructs FileLines from a file, shows progress bar (main constructor 2)
|
|
FileLines(java.io.File f,
java.lang.String encoding,
java.lang.String announceMsg)
Constructs FileLines from a file with an encoding, shows progress bar
(main constructor 1)
|
|
FileLines(java.io.Reader f)
Constructs FileLines from a Reader
|
|
FileLines(java.lang.String f)
Constructs FileLines from a filename
|
|
FileLines(java.lang.String f,
java.lang.String announceMsg)
Constructs FileLines from a filename, shows progress bar
|
|
FileLines(java.lang.String f,
java.lang.String encoding,
java.lang.String announceMsg)
Constructs FileLines from a filename with a given encoding, shows
progress bar
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes the reader
|
void |
finalize()
Closes the reader
|
static int |
find(java.io.Reader in,
java.lang.String... findMe)
Reads until one of the strings is found, returns its index or -1.
|
static int |
findIgnoreCase(java.io.Reader in,
java.lang.String... findMe)
Reads until one of the strings is found, returns its index or -1.
|
static int |
firstCharAfterSpace(java.io.Reader in)
Skips space
|
java.lang.String |
internalNext()
Returns next line.
|
java.util.Iterator<java.lang.String> |
iterator()
Returns this
|
static int |
numAllFileLines(java.io.File f,
java.lang.String ext)
returns number of lines in file
|
static int |
numFileLines(java.io.File f)
returns number of lines in file
|
static java.lang.String |
readBetween(java.io.Reader in,
java.lang.String start,
java.lang.String end)
Reads the string between the delimiters
|
static java.lang.String |
readBetween(java.lang.String in,
java.lang.String start,
java.lang.String end)
Reads the string between the delimiters
|
static java.lang.CharSequence |
readTo(java.io.Reader in,
char... limit)
Reads to a specific character, returns the text in between
|
static java.lang.CharSequence |
readTo(java.io.Reader in,
char limit)
Reads to a specific character, returns the text in between
|
static java.lang.CharSequence |
readTo(java.io.Reader in,
java.lang.String limit)
Reads to a specific String, returns the text up to there, including the
limit
|
static java.lang.CharSequence |
readTo(java.io.Reader in,
java.lang.String limit,
java.util.List<java.lang.Integer> results)
Reads to a specific String, returns the text up to there, including the
limit
|
static java.lang.String |
readToBoundary(java.io.Reader in,
java.lang.String limit)
Reads to a specific string, returns text up to there, without boundary or returns NULL
|
static java.lang.CharSequence |
readToSpace(java.io.Reader in)
Reads to a whitespace
|
void |
remove()
Unsupported, throws an UnsupportedOperationException
|
static boolean |
scrollTo(java.io.Reader in,
char... delimiters)
Scrolls to one of the characters
|
static boolean |
scrollTo(java.io.Reader in,
char delimiter)
Reads to a specific character
|
static boolean |
scrollTo(java.io.Reader in,
java.lang.String limit)
Scrolls to a specific limit and beyond
|
java.lang.String |
toString()
Returns a simple identifier
|
asList, asList, asSet, asSet, asSet, emptyIterator, hasNext, internalSilentNext, list, list, main, next, nextOrNull, numElements, numElements, peek, toString, toStringprotected long announceChars
protected java.io.BufferedReader br
public static long maxChars
public FileLines(java.lang.String f)
throws java.io.IOException
java.io.IOExceptionpublic FileLines(java.io.File f)
throws java.io.IOException
java.io.IOExceptionpublic FileLines(java.lang.String f,
java.lang.String announceMsg)
throws java.io.IOException
java.io.IOExceptionpublic FileLines(java.lang.String f,
java.lang.String encoding,
java.lang.String announceMsg)
throws java.io.IOException
java.io.IOExceptionpublic FileLines(java.io.File f,
java.lang.String encoding,
java.lang.String announceMsg)
throws java.io.IOException
java.io.IOExceptionpublic FileLines(java.io.File f,
java.lang.String announceMsg)
throws java.io.IOException
java.io.IOExceptionpublic FileLines(java.io.Reader f)
public FileLines(java.io.BufferedReader r)
protected FileLines()
public void remove()
throws java.lang.UnsupportedOperationException
remove in interface java.util.Iterator<java.lang.String>remove in class PeekIterator<java.lang.String>java.lang.UnsupportedOperationExceptionpublic java.lang.String internalNext()
internalNext in class PeekIterator<java.lang.String>public java.lang.String toString()
toString in class PeekIterator<java.lang.String>public java.util.Iterator<java.lang.String> iterator()
iterator in interface java.lang.Iterable<java.lang.String>iterator in class PeekIterator<java.lang.String>public void close()
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class PeekIterator<java.lang.String>public void finalize()
finalize in class java.lang.Objectpublic static int find(java.io.Reader in,
java.lang.String... findMe)
throws java.io.IOException
java.io.IOExceptionpublic static int findIgnoreCase(java.io.Reader in,
java.lang.String... findMe)
throws java.io.IOException
java.io.IOExceptionpublic static java.lang.CharSequence readTo(java.io.Reader in,
char... limit)
throws java.io.IOException
java.io.IOExceptionpublic static java.lang.CharSequence readToSpace(java.io.Reader in)
throws java.io.IOException
java.io.IOExceptionpublic static int firstCharAfterSpace(java.io.Reader in)
throws java.io.IOException
java.io.IOExceptionpublic static java.lang.CharSequence readTo(java.io.Reader in,
char limit)
throws java.io.IOException
java.io.IOExceptionpublic static java.lang.CharSequence readTo(java.io.Reader in,
java.lang.String limit)
throws java.io.IOException
java.io.IOExceptionpublic static java.lang.String readToBoundary(java.io.Reader in,
java.lang.String limit)
throws java.io.IOException
java.io.IOExceptionpublic static boolean scrollTo(java.io.Reader in,
char... delimiters)
throws java.io.IOException
java.io.IOExceptionpublic static boolean scrollTo(java.io.Reader in,
char delimiter)
throws java.io.IOException
java.io.IOExceptionpublic static boolean scrollTo(java.io.Reader in,
java.lang.String limit)
throws java.io.IOException
java.io.IOExceptionpublic static java.lang.String readBetween(java.io.Reader in,
java.lang.String start,
java.lang.String end)
throws java.io.IOException
java.io.IOExceptionpublic static java.lang.String readBetween(java.lang.String in,
java.lang.String start,
java.lang.String end)
java.io.IOExceptionpublic static java.lang.CharSequence readTo(java.io.Reader in,
java.lang.String limit,
java.util.List<java.lang.Integer> results)
throws java.io.IOException
java.io.IOExceptionpublic static int numFileLines(java.io.File f)
throws java.io.IOException
java.io.IOExceptionpublic static int numAllFileLines(java.io.File f,
java.lang.String ext)
throws java.io.IOException
java.io.IOException