public class FileLines extends PeekIterator<String> implements Iterable<String>, Iterator<String>, 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 BufferedReader |
br
Containes the Reader
|
static long |
maxChars
Maximum chars to read by readTo (or -1)
|
closed, EMPTY, fetchedNextValue, next| Modifier | Constructor and Description |
|---|---|
protected |
FileLines()
For subclasses
|
|
FileLines(BufferedReader r)
Constructs FileLines from a BufferedReader (main constructor 3)
|
|
FileLines(File f)
Constructs FileLines from a file
|
|
FileLines(File f,
String announceMsg)
Constructs FileLines from a file, shows progress bar (main constructor 2)
|
|
FileLines(File f,
String encoding,
String announceMsg)
Constructs FileLines from a file with an encoding, shows progress bar
(main constructor 1)
|
|
FileLines(Reader f)
Constructs FileLines from a Reader
|
|
FileLines(String f)
Constructs FileLines from a filename
|
|
FileLines(String f,
String announceMsg)
Constructs FileLines from a filename, shows progress bar
|
|
FileLines(String f,
String encoding,
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(Reader in,
String... findMe)
Reads until one of the strings is found, returns its index or -1.
|
static int |
find(Reader in,
StringBuilder b,
String... findMe)
Reads until one of the strings is found, returns its index or -1.
|
static int |
findIgnoreCase(Reader in,
String... findMe)
Reads until one of the strings is found, returns its index or -1.
|
static int |
firstCharAfterSpace(Reader in)
Skips space
|
String |
internalNext()
Returns next line.
|
Iterator<String> |
iterator()
Returns this
|
static int |
numAllFileLines(File f,
String ext)
returns number of lines in file
|
static int |
numFileLines(File f)
returns number of lines in file
|
static String |
readBetween(Reader in,
String start,
String end)
Reads the string between the delimiters
|
static String |
readBetween(String in,
String start,
String end)
Reads the string between the delimiters
|
static CharSequence |
readTo(Reader in,
char... limit)
Reads to a specific character, returns the text in between
|
static CharSequence |
readTo(Reader in,
char limit)
Reads to a specific character, returns the text in between
|
static String |
readTo(Reader in,
CharSequence... findMe)
Reads until one of the strings is found, returns the string
|
static CharSequence |
readTo(Reader in,
String limit)
Reads to a specific String, returns the text up to there, including the
limit
|
static CharSequence |
readTo(Reader in,
String limit,
List<Integer> results)
Reads to a specific String, returns the text up to there, including the
limit
|
static String |
readToBoundary(Reader in,
String limit)
Reads to a specific string, returns text up to there, without boundary or
returns NULL
|
static CharSequence |
readToSpace(Reader in)
Reads to a whitespace
|
void |
remove()
Unsupported, throws an UnsupportedOperationException
|
static boolean |
scrollTo(Reader in,
char... delimiters)
Scrolls to one of the characters
|
static boolean |
scrollTo(Reader in,
char delimiter)
Reads to a specific character
|
static boolean |
scrollTo(Reader in,
String limit)
Scrolls to a specific limit and beyond
|
String |
toString()
Returns a simple identifier
|
asList, asList, asSet, asSet, asSet, emptyIterator, hasNext, internalSilentNext, list, list, main, next, nextOrNull, numElements, numElements, peek, toString, toStringclone, equals, getClass, hashCode, notify, notifyAll, wait, wait, waitforEach, spliteratorforEachRemaining, hasNext, nextprotected long announceChars
protected BufferedReader br
public static long maxChars
public FileLines(String f) throws IOException
IOExceptionpublic FileLines(File f) throws IOException
IOExceptionpublic FileLines(String f, String announceMsg) throws IOException
IOExceptionpublic FileLines(String f, String encoding, String announceMsg) throws IOException
IOExceptionpublic FileLines(File f, String encoding, String announceMsg) throws IOException
IOExceptionpublic FileLines(File f, String announceMsg) throws IOException
IOExceptionpublic FileLines(Reader f)
public FileLines(BufferedReader r)
protected FileLines()
public void remove()
throws UnsupportedOperationException
remove in interface Iterator<String>remove in class PeekIterator<String>UnsupportedOperationExceptionpublic String internalNext()
internalNext in class PeekIterator<String>public String toString()
toString in class PeekIterator<String>public void close()
close in interface Closeableclose in interface AutoCloseableclose in class PeekIterator<String>public static String readTo(Reader in, CharSequence... findMe) throws IOException
IOExceptionpublic static int find(Reader in, String... findMe) throws IOException
IOExceptionpublic static int find(Reader in, StringBuilder b, String... findMe) throws IOException
IOExceptionpublic static int findIgnoreCase(Reader in, String... findMe) throws IOException
IOExceptionpublic static CharSequence readTo(Reader in, char... limit) throws IOException
IOExceptionpublic static CharSequence readToSpace(Reader in) throws IOException
IOExceptionpublic static int firstCharAfterSpace(Reader in) throws IOException
IOExceptionpublic static CharSequence readTo(Reader in, char limit) throws IOException
IOExceptionpublic static CharSequence readTo(Reader in, String limit) throws IOException
IOExceptionpublic static String readToBoundary(Reader in, String limit) throws IOException
IOExceptionpublic static boolean scrollTo(Reader in, char... delimiters) throws IOException
IOExceptionpublic static boolean scrollTo(Reader in, char delimiter) throws IOException
IOExceptionpublic static boolean scrollTo(Reader in, String limit) throws IOException
IOExceptionpublic static String readBetween(Reader in, String start, String end) throws IOException
IOExceptionpublic static String readBetween(String in, String start, String end)
public static CharSequence readTo(Reader in, String limit, List<Integer> results) throws IOException
IOExceptionpublic static int numFileLines(File f) throws IOException
IOExceptionpublic static int numAllFileLines(File f, String ext) throws IOException
IOExceptionCopyright © 2018. All rights reserved.