Package org.silverpeas.core.util.file
Class ReversedFileLineReader
- java.lang.Object
-
- org.apache.commons.io.input.ReversedLinesFileReader
-
- org.silverpeas.core.util.file.ReversedFileLineReader
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
public class ReversedFileLineReader extends org.apache.commons.io.input.ReversedLinesFileReader
This tool reads a file from its end to its start.- Author:
- Yohann Chastagnier
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static List<String>
readLastLines(Path path, int lastLines)
Reads a specified number of last lines of a file represented by aPath
instance.
The result will never contains more thanFULL_FILE_NB_LINE_LIMIT
lines.
Last lines are sorted from oldest to the most recent.
Empty line at end of file is skipped.static List<String>
readLastLines(Path path, int lastLines, boolean sortedFromOldestToMostRecent)
Reads a specified number of last lines of a file represented by aPath
instance.
The result will never contains more thanFULL_FILE_NB_LINE_LIMIT
lines.
Empty line at end of file is skipped.
-
-
-
Method Detail
-
readLastLines
public static List<String> readLastLines(Path path, int lastLines) throws IOException
Reads a specified number of last lines of a file represented by aPath
instance.
The result will never contains more thanFULL_FILE_NB_LINE_LIMIT
lines.
Last lines are sorted from oldest to the most recent.
Empty line at end of file is skipped.- Parameters:
path
- the path where the file data are located.lastLines
- the number of last lines to read. 0 or negative value to get all the lines of the file. However, the result contains at mostFULL_FILE_NB_LINE_LIMIT
lines in order to avoid memory problems.- Returns:
- a list containing the last requested lines. The result contains at most
FULL_FILE_NB_LINE_LIMIT
lines. - Throws:
IOException
- if an I/O error occurs.
-
readLastLines
public static List<String> readLastLines(Path path, int lastLines, boolean sortedFromOldestToMostRecent) throws IOException
Reads a specified number of last lines of a file represented by aPath
instance.
The result will never contains more thanFULL_FILE_NB_LINE_LIMIT
lines.
Empty line at end of file is skipped.- Parameters:
path
- the path where the file data are located.lastLines
- the number of last lines to read. 0 or negative value to get all the lines of the file. However, the result contains at mostFULL_FILE_NB_LINE_LIMIT
lines in order to avoid memory problems.sortedFromOldestToMostRecent
- true to sort the last lines from oldest to most recent, false to sort in the reverse way.- Returns:
- a list containing the last requested lines. The result contains at most
FULL_FILE_NB_LINE_LIMIT
lines. - Throws:
IOException
- if an I/O error occurs.
-
-