Class LineByteStream

  • All Implemented Interfaces:
    Closeable, AutoCloseable

    public class LineByteStream
    extends Object
    implements Closeable
    This class wraps a RandomAccessFile and returns byte arrays separated by lines. In addition it also maintains a count of the bytes read. We expect the file channel to be positioned correctly for the initial read. After each read, the channel is positioned just after the newline.
    Author:
    mshankar
    • Field Detail

      • MAX_LINE_SIZE

        public static int MAX_LINE_SIZE
      • MAX_ITERATIONS_TO_DETERMINE_LINE

        public static int MAX_ITERATIONS_TO_DETERMINE_LINE
    • Method Detail

      • readLine

        public ByteArray readLine​(ByteArray bar)
                           throws IOException
        Optimize the readline by offering the abilty to reuse the same memory allocation. This does not escape the bytes as it is reading the line. While this is optimal to do, it means for raw responses, we'll be redoing some of the work and raw responses are 90% of the requests. If in future, we determine that unescaping here is more optimal, this method has an unescape version in version control history. Returns the same byte array as the input.
        Parameters:
        bar - ByteArray
        Returns:
        bar ByteArray
        Throws:
        IOException -  
      • seekToFirstNewLine

        public void seekToFirstNewLine()
                                throws IOException
        Seeks to the first new line after the current position in the rndAccFile. The file pointer is located just after the first newline.
        Throws:
        IOException -  
      • seekToBeforeLastLine

        public void seekToBeforeLastLine()
                                  throws IOException
        Seeks and positions the pointer to to the last line in the file. The file pointer is located just before the last line so that readLine gets a valid line. About the only thing once can do after this is to read a line and stop...
        Throws:
        IOException -  
      • seekToBeforePreviousLine

        public void seekToBeforePreviousLine​(long posn)
                                      throws IOException
        Seeks and positions the pointer to line previous to the specified position. The file pointer is located just so that one can do a readline. Note that this method is not efficient at all; so use with care.
        Parameters:
        posn -  
        Throws:
        IOException -  
      • safeClose

        public void safeClose()
      • getAbsolutePath

        public String getAbsolutePath()