public class ReversedLinesFileReader
extends java.lang.Object
implements java.io.Closeable
To build an instance, see ReversedLinesFileReader.Builder
.
Modifier and Type | Class and Description |
---|---|
static class |
ReversedLinesFileReader.Builder
Builds a new
ReversedLinesFileReader instance. |
private class |
ReversedLinesFileReader.FilePart |
Modifier and Type | Field and Description |
---|---|
private int |
avoidNewlineSplitBufferSize |
private int |
blockSize |
private int |
byteDecrement |
private java.nio.channels.SeekableByteChannel |
channel |
private java.nio.charset.Charset |
charset |
private ReversedLinesFileReader.FilePart |
currentFilePart |
private static int |
DEFAULT_BLOCK_SIZE |
private static java.lang.String |
EMPTY_STRING |
private byte[][] |
newLineSequences |
private long |
totalBlockCount |
private long |
totalByteLength |
private boolean |
trailingNewlineOfFileSkipped |
Constructor and Description |
---|
ReversedLinesFileReader(java.io.File file)
Deprecated.
|
ReversedLinesFileReader(java.io.File file,
java.nio.charset.Charset charset)
Deprecated.
|
ReversedLinesFileReader(java.io.File file,
int blockSize,
java.nio.charset.Charset charset)
Deprecated.
|
ReversedLinesFileReader(java.io.File file,
int blockSize,
java.lang.String charsetName)
Deprecated.
|
ReversedLinesFileReader(java.nio.file.Path file,
java.nio.charset.Charset charset)
Deprecated.
|
ReversedLinesFileReader(java.nio.file.Path file,
int blockSize,
java.nio.charset.Charset charset)
Deprecated.
|
ReversedLinesFileReader(java.nio.file.Path file,
int blockSize,
java.lang.String charsetName)
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
static ReversedLinesFileReader.Builder |
builder()
Constructs a new
ReversedLinesFileReader.Builder . |
void |
close()
Closes underlying resources.
|
java.lang.String |
readLine()
Returns the lines of the file from bottom to top.
|
java.util.List<java.lang.String> |
readLines(int lineCount)
Returns
lineCount lines of the file from bottom to top. |
java.lang.String |
toString(int lineCount)
Returns the last
lineCount lines of the file. |
private static final java.lang.String EMPTY_STRING
private static final int DEFAULT_BLOCK_SIZE
private final int blockSize
private final java.nio.charset.Charset charset
private final java.nio.channels.SeekableByteChannel channel
private final long totalByteLength
private final long totalBlockCount
private final byte[][] newLineSequences
private final int avoidNewlineSplitBufferSize
private final int byteDecrement
private ReversedLinesFileReader.FilePart currentFilePart
private boolean trailingNewlineOfFileSkipped
@Deprecated public ReversedLinesFileReader(java.io.File file) throws java.io.IOException
builder()
, ReversedLinesFileReader.Builder
, and ReversedLinesFileReader.Builder.get()
file
- the file to be readjava.io.IOException
- if an I/O error occurs.@Deprecated public ReversedLinesFileReader(java.io.File file, java.nio.charset.Charset charset) throws java.io.IOException
builder()
, ReversedLinesFileReader.Builder
, and ReversedLinesFileReader.Builder.get()
file
- the file to be readcharset
- the charset to use, null uses the default Charset.java.io.IOException
- if an I/O error occurs.@Deprecated public ReversedLinesFileReader(java.io.File file, int blockSize, java.nio.charset.Charset charset) throws java.io.IOException
builder()
, ReversedLinesFileReader.Builder
, and ReversedLinesFileReader.Builder.get()
file
- the file to be readblockSize
- size of the internal buffer (for ideal performance this
should match with the block size of the underlying file
system).charset
- the encoding of the file, null uses the default Charset.java.io.IOException
- if an I/O error occurs.@Deprecated public ReversedLinesFileReader(java.io.File file, int blockSize, java.lang.String charsetName) throws java.io.IOException
builder()
, ReversedLinesFileReader.Builder
, and ReversedLinesFileReader.Builder.get()
file
- the file to be readblockSize
- size of the internal buffer (for ideal performance this
should match with the block size of the underlying file
system).charsetName
- the encoding of the file, null uses the default Charset.java.io.IOException
- if an I/O error occursjava.nio.charset.UnsupportedCharsetException
- thrown instead of
UnsupportedEncodingException
in version 2.2 if the
encoding is not
supported.@Deprecated public ReversedLinesFileReader(java.nio.file.Path file, java.nio.charset.Charset charset) throws java.io.IOException
builder()
, ReversedLinesFileReader.Builder
, and ReversedLinesFileReader.Builder.get()
file
- the file to be readcharset
- the charset to use, null uses the default Charset.java.io.IOException
- if an I/O error occurs.@Deprecated public ReversedLinesFileReader(java.nio.file.Path file, int blockSize, java.nio.charset.Charset charset) throws java.io.IOException
builder()
, ReversedLinesFileReader.Builder
, and ReversedLinesFileReader.Builder.get()
file
- the file to be readblockSize
- size of the internal buffer (for ideal performance this
should match with the block size of the underlying file
system).charset
- the encoding of the file, null uses the default Charset.java.io.IOException
- if an I/O error occurs.@Deprecated public ReversedLinesFileReader(java.nio.file.Path file, int blockSize, java.lang.String charsetName) throws java.io.IOException
builder()
, ReversedLinesFileReader.Builder
, and ReversedLinesFileReader.Builder.get()
file
- the file to be readblockSize
- size of the internal buffer (for ideal performance this
should match with the block size of the underlying file
system).charsetName
- the encoding of the file, null uses the default Charset.java.io.IOException
- if an I/O error occursjava.nio.charset.UnsupportedCharsetException
- thrown instead of
UnsupportedEncodingException
in version 2.2 if the
encoding is not
supported.public static ReversedLinesFileReader.Builder builder()
ReversedLinesFileReader.Builder
.ReversedLinesFileReader.Builder
.public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
java.io.IOException
- if an I/O error occurs.public java.lang.String readLine() throws java.io.IOException
java.io.IOException
- if an I/O error occurs.public java.util.List<java.lang.String> readLines(int lineCount) throws java.io.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.java.io.IOException
- if an I/O error occurs.public java.lang.String toString(int lineCount) throws java.io.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.java.io.IOException
- if an I/O error occurs.