Class GridReversedLinesFileReader
- java.lang.Object
-
- org.apache.ignite.internal.util.io.GridReversedLinesFileReader
-
- All Implemented Interfaces:
Closeable,AutoCloseable
public class GridReversedLinesFileReader extends Object implements Closeable
Reads lines in a file reversely (similar to a BufferedReader, but starting at the last line). Useful for e.g. searching in log files.
-
-
Constructor Summary
Constructors Constructor Description GridReversedLinesFileReader(File file)Creates a ReverseLineReader with default block size of 4KB and the platform's default encoding.GridReversedLinesFileReader(File file, int blockSize, String encoding)Creates a ReverseLineReader with the given block size and encoding.GridReversedLinesFileReader(File file, int blockSize, Charset charset)Creates a ReverseLineReader with the given block size and encoding.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes underlying resources.StringreadLine()Returns the lines of the file from bottom to top.
-
-
-
Constructor Detail
-
GridReversedLinesFileReader
public GridReversedLinesFileReader(File file) throws IOException
Creates a ReverseLineReader with default block size of 4KB and the platform's default encoding.- Parameters:
file- the file to be read- Throws:
IOException- if an I/O error occurs
-
GridReversedLinesFileReader
public GridReversedLinesFileReader(File file, int blockSize, Charset charset) throws IOException
Creates a ReverseLineReader with the given block size and encoding.- Parameters:
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- Throws:
IOException- if an I/O error occurs- Since:
- 2.3
-
GridReversedLinesFileReader
public GridReversedLinesFileReader(File file, int blockSize, String encoding) throws IOException
Creates a ReverseLineReader with the given block size and encoding.- Parameters:
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).encoding- the encoding of the file- Throws:
IOException- if an I/O error occursUnsupportedCharsetException- thrown instead ofUnsupportedEncodingExceptionin version 2.2 if the encoding is not supported.
-
-
Method Detail
-
readLine
public String readLine() throws IOException
Returns the lines of the file from bottom to top.- Returns:
- the next line or null if the start of the file is reached
- Throws:
IOException- if an I/O error occurs
-
close
public void close() throws IOExceptionCloses underlying resources.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException- if an I/O error occurs
-
-