ReversedLinesFileReader (Commons IO 2.5)
Date: 2016-12-01

org.apache.commons.io.input

## Class ReversedLinesFileReader

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

- All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

      public class ReversedLinesFileReader
      extends java.lang.Object
      implements java.io.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

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `private class` | `ReversedLinesFileReader.FilePart`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `private int` | `avoidNewlineSplitBufferSize`
    `private int` | `blockSize`
    `private int` | `byteDecrement`
    `private ReversedLinesFileReader.FilePart` | `currentFilePart`
    `private java.nio.charset.Charset` | `encoding`
    `private byte[][]` | `newLineSequences`
    `private java.io.RandomAccessFile` | `randomAccessFile`
    `private long` | `totalBlockCount`
    `private long` | `totalByteLength`
    `private boolean` | `trailingNewlineOfFileSkipped`

  - ### Constructor Summary

    Constructors
    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 encoding)` Creates a ReversedLinesFileReader with the given block size and encoding.
    `ReversedLinesFileReader(java.io.File file, int blockSize, java.lang.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.
    `java.lang.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`

- - ### Field Detail

    - #### blockSize

          private final int blockSize

    - #### encoding

          private final java.nio.charset.Charset encoding

    - #### randomAccessFile

          private final java.io.RandomAccessFile randomAccessFile

    - #### totalByteLength

          private final long totalByteLength

    - #### totalBlockCount

          private final long totalBlockCount

    - #### newLineSequences

          private final byte[][] newLineSequences

    - #### avoidNewlineSplitBufferSize

          private final int avoidNewlineSplitBufferSize

    - #### byteDecrement

          private final int byteDecrement

    - #### currentFilePart

          private ReversedLinesFileReader.FilePart currentFilePart

    - #### trailingNewlineOfFileSkipped

          private boolean trailingNewlineOfFileSkipped

  - ### Constructor Detail

    - #### ReversedLinesFileReader

          @Deprecated
          public ReversedLinesFileReader(java.io.File file)
                                  throws java.io.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:
        `java.io.IOException` - if an I/O error occurs

    - #### ReversedLinesFileReader

          public ReversedLinesFileReader(java.io.File file,
                                 java.nio.charset.Charset charset)
                                  throws java.io.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:
        `java.io.IOException` - if an I/O error occurs
      Since:
        2.5

    - #### ReversedLinesFileReader

          public ReversedLinesFileReader(java.io.File file,
                                 int blockSize,
                                 java.nio.charset.Charset encoding)
                                  throws java.io.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:
        `java.io.IOException` - if an I/O error occurs
      Since:
        2.3

    - #### ReversedLinesFileReader

          public ReversedLinesFileReader(java.io.File file,
                                 int blockSize,
                                 java.lang.String encoding)
                                  throws java.io.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:
        `java.io.IOException` - if an I/O error occurs
        `java.nio.charset.UnsupportedCharsetException` - thrown instead of `UnsupportedEncodingException` in version 2.2 if the encoding is not supported.

  - ### Method Detail

    - #### readLine

          public java.lang.String readLine()
                                    throws java.io.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:
        `java.io.IOException` - if an I/O error occurs

    - #### close

          public void close()
                     throws java.io.IOException

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

Copyright (c) 2002-2016 Apache Software Foundation