ReversedLinesFileReader (Apache Commons IO 2.5 API)

org.apache.commons.io.input

## Class ReversedLinesFileReader

- java.lang.Object
- - org.apache.commons.io.input.ReversedLinesFileReader

- All Implemented Interfaces:
    Closeable, AutoCloseable

      public class ReversedLinesFileReader
      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.
  Since:
    2.2

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ReversedLinesFileReader(File file)` Deprecated. 2.5 use `ReversedLinesFileReader(File, Charset)` instead
    `ReversedLinesFileReader(File file, Charset charset)` Creates a ReversedLinesFileReader with default block size of 4KB and the specified encoding.
    `ReversedLinesFileReader(File file, int blockSize, Charset encoding)` Creates a ReversedLinesFileReader with the given block size and encoding.
    `ReversedLinesFileReader(File file, int blockSize, String encoding)` Creates a ReversedLinesFileReader with the given block size and encoding.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()` Closes underlying resources.
    `String` | `readLine()` Returns the lines of the file from bottom to top.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### ReversedLinesFileReader

          @Deprecated
          public ReversedLinesFileReader(File file)
                                  throws IOException

      Deprecated. 2.5 use `ReversedLinesFileReader(File, Charset)` instead
      Creates a ReversedLinesFileReader 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

    - #### ReversedLinesFileReader

          public ReversedLinesFileReader(File file,
                                 Charset charset)
                                  throws IOException

      Creates a ReversedLinesFileReader with default block size of 4KB and the specified encoding.
      Parameters:
        `file` - the file to be read
        `charset` - the encoding to use
      Throws:
        `IOException` - if an I/O error occurs
      Since:
        2.5

    - #### ReversedLinesFileReader

          public ReversedLinesFileReader(File file,
                                 int blockSize,
                                 Charset encoding)
                                  throws IOException

      Creates a ReversedLinesFileReader with the given block size and encoding.
      Parameters:
        `file` - the file to be read
        `blockSize` - 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 occurs
      Since:
        2.3

    - #### ReversedLinesFileReader

          public ReversedLinesFileReader(File file,
                                 int blockSize,
                                 String encoding)
                                  throws IOException

      Creates a ReversedLinesFileReader with the given block size and encoding.
      Parameters:
        `file` - the file to be read
        `blockSize` - 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 occurs
        `UnsupportedCharsetException` - thrown instead of `UnsupportedEncodingException` in 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 IOException

      Closes underlying resources.
      Specified by:
        `close` in interface `Closeable`
      Specified by:
        `close` in interface `AutoCloseable`
      Throws:
        `IOException` - if an I/O error occurs

Copyright © 2002–2016 The Apache Software Foundation. All rights reserved.