public class ReversedLinesFileReader
extends java.lang.Object
implements java.io.Closeable
Modifier and Type | Class and Description |
---|---|
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.
2.5 use
ReversedLinesFileReader(File, Charset) instead |
ReversedLinesFileReader(java.io.File file,
java.nio.charset.Charset charset)
Creates a ReversedLinesFileReader with default block size of 4KB and the
specified encoding.
|
ReversedLinesFileReader(java.io.File file,
int blockSize,
java.nio.charset.Charset charset)
Creates a ReversedLinesFileReader with the given block size and encoding.
|
ReversedLinesFileReader(java.io.File file,
int blockSize,
java.lang.String charsetName)
Creates a ReversedLinesFileReader with the given block size and encoding.
|
ReversedLinesFileReader(java.nio.file.Path file,
java.nio.charset.Charset charset)
Creates a ReversedLinesFileReader with default block size of 4KB and the
specified encoding.
|
ReversedLinesFileReader(java.nio.file.Path file,
int blockSize,
java.nio.charset.Charset charset)
Creates a ReversedLinesFileReader with the given block size and encoding.
|
ReversedLinesFileReader(java.nio.file.Path file,
int blockSize,
java.lang.String charsetName)
Creates a ReversedLinesFileReader with the given block size and encoding.
|
Modifier and Type | Method and Description |
---|---|
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
ReversedLinesFileReader(File, Charset)
insteadfile
- the file to be readjava.io.IOException
- if an I/O error occurs.public ReversedLinesFileReader(java.io.File file, java.nio.charset.Charset charset) throws java.io.IOException
file
- the file to be readcharset
- the charset to use, null uses the default Charset.java.io.IOException
- if an I/O error occurs.public ReversedLinesFileReader(java.io.File file, int blockSize, java.nio.charset.Charset charset) throws java.io.IOException
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.public ReversedLinesFileReader(java.io.File file, int blockSize, java.lang.String charsetName) throws java.io.IOException
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 ReversedLinesFileReader(java.nio.file.Path file, java.nio.charset.Charset charset) throws java.io.IOException
file
- the file to be readcharset
- the charset to use, null uses the default Charset.java.io.IOException
- if an I/O error occurs.public ReversedLinesFileReader(java.nio.file.Path file, int blockSize, java.nio.charset.Charset charset) throws java.io.IOException
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.public ReversedLinesFileReader(java.nio.file.Path file, int blockSize, java.lang.String charsetName) throws java.io.IOException
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 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.