public class ReversedLinesFileReader extends Object implements Closeable, IOIterable<String>
To build an instance, use ReversedLinesFileReader.Builder.
For example:
try (ReversedLinesFileReader reader = ReversedLinesFileReader.builder()
.setPath(path)
.setBufferSize(4096)
.setCharset(StandardCharsets.UTF_8)
.get()) {
reader.forEach(line -> System.out.println(line));
}
ReversedLinesFileReader.Builder| Modifier and Type | Class and Description |
|---|---|
static class |
ReversedLinesFileReader.Builder
Builds a new
ReversedLinesFileReader. |
| Modifier and Type | Method and Description |
|---|---|
static ReversedLinesFileReader.Builder |
builder()
Constructs a new
ReversedLinesFileReader.Builder. |
void |
close()
Closes underlying resources.
|
IOIterator<String> |
iterator()
Like
Iterable.iterator(). |
String |
readLine()
Returns the lines of the file from bottom to top.
|
List<String> |
readLines(int lineCount)
Returns
lineCount lines of the file from bottom to top. |
String |
toString(int lineCount)
Returns the last
lineCount lines of the file. |
Iterable<String> |
unwrap()
Unwraps this instance and returns the underlying
Iterable. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitforEach, spliteratorpublic static ReversedLinesFileReader.Builder builder()
ReversedLinesFileReader.Builder.ReversedLinesFileReader.Builder.public void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOException - if an I/O error occurs.public IOIterator<String> iterator()
IOIterableIterable.iterator().iterator in interface IOIterable<String>delegate.Iterable.iterator()public String readLine() throws IOException
IOException - if an I/O error occurs.public List<String> readLines(int lineCount) throws IOException
lineCount lines of the file from bottom to top.
If there are less than lineCount lines in the file, then that's what
you get.
Note: You can easily flip the result with Collections.reverse(List).
lineCount - How many lines to read.IOException - if an I/O error occurs.public String toString(int lineCount) throws IOException
lineCount lines of the file.
If there are less than lineCount lines in the file, then that's what
you get.
lineCount - How many lines to read.IOException - if an I/O error occurs.public Iterable<String> unwrap()
IOIterableIterable.
Implementations may not have anything to unwrap and that behavior is undefined for now.
unwrap in interface IOIterable<String>