Class LogFileTail

java.lang.Object
eu.mrapik.minecraftservermcp.util.LogFileTail

public final class LogFileTail extends Object
Reads the tail of a UTF-8 text file without loading the whole file into memory.
  • Method Details

    • readTail

      public static String readTail(Path file, int maxBytes, int maxLines) throws IOException
      Reads at most maxBytes from the end of the file, then keeps at most maxLines lines (counting newlines). If the read starts mid-line, the first fragment is dropped.
      Parameters:
      file - path to a regular file
      maxBytes - maximum bytes read from the end of the file
      maxLines - maximum number of lines to return after splitting
      Returns:
      tail text, or "" if limits are non-positive, the path is not a file, or the file is empty
      Throws:
      IOException - if the file cannot be read