Class DirectReader

  • All Implemented Interfaces:
    java.lang.AutoCloseable, LogReader

    class DirectReader
    extends java.lang.Object
    implements LogReader
    • Constructor Summary

      Constructors 
      Constructor Description
      DirectReader​(int logId, java.lang.String filename, io.netty.buffer.ByteBufAllocator allocator, NativeIO nativeIO, int bufferSize, int maxSaneEntrySize, OpStatsLogger readBlockStats)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      boolean isClosed()  
      int logId()  
      long maxOffset()  
      (package private) void readBlock​(long offset)  
      io.netty.buffer.ByteBuf readBufferAt​(long offset, int size)
      Read a buffer from the file.
      io.netty.buffer.ByteBuf readEntryAt​(int offset)
      Read an entry at a given offset.
      int readIntAt​(long offset)
      Read an integer at a given offset.
      void readIntoBufferAt​(io.netty.buffer.ByteBuf buffer, long offset, int size)  
      long readLongAt​(long offset)
      Read an long at a given offset.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DirectReader

        DirectReader​(int logId,
                     java.lang.String filename,
                     io.netty.buffer.ByteBufAllocator allocator,
                     NativeIO nativeIO,
                     int bufferSize,
                     int maxSaneEntrySize,
                     OpStatsLogger readBlockStats)
              throws java.io.IOException
        Throws:
        java.io.IOException
    • Method Detail

      • logId

        public int logId()
        Specified by:
        logId in interface LogReader
        Returns:
        the id of the log being read from.
      • readBufferAt

        public io.netty.buffer.ByteBuf readBufferAt​(long offset,
                                                    int size)
                                             throws java.io.IOException,
                                                    java.io.EOFException
        Description copied from interface: LogReader
        Read a buffer from the file. It is the responsibility of the caller to release the returned buffer.
        Specified by:
        readBufferAt in interface LogReader
        Parameters:
        offset - the offset to read at
        size - the number of bytes to read
        Returns:
        a bytebuf. The caller must release.
        Throws:
        java.io.IOException
        java.io.EOFException
      • readIntoBufferAt

        public void readIntoBufferAt​(io.netty.buffer.ByteBuf buffer,
                                     long offset,
                                     int size)
                              throws java.io.IOException,
                                     java.io.EOFException
        Specified by:
        readIntoBufferAt in interface LogReader
        Throws:
        java.io.IOException
        java.io.EOFException
      • readIntAt

        public int readIntAt​(long offset)
                      throws java.io.IOException,
                             java.io.EOFException
        Description copied from interface: LogReader
        Read an integer at a given offset.
        Specified by:
        readIntAt in interface LogReader
        Parameters:
        offset - the offset to read from.
        Returns:
        the integer at that offset.
        Throws:
        java.io.IOException
        java.io.EOFException
      • readLongAt

        public long readLongAt​(long offset)
                        throws java.io.IOException,
                               java.io.EOFException
        Description copied from interface: LogReader
        Read an long at a given offset.
        Specified by:
        readLongAt in interface LogReader
        Parameters:
        offset - the offset to read from.
        Returns:
        the long at that offset.
        Throws:
        java.io.IOException
        java.io.EOFException
      • readEntryAt

        public io.netty.buffer.ByteBuf readEntryAt​(int offset)
                                            throws java.io.IOException,
                                                   java.io.EOFException
        Description copied from interface: LogReader
        Read an entry at a given offset. The size of the entry must be at (offset - Integer.BYTES). The payload of the entry starts at offset. It is the responsibility of the caller to release the returned buffer.
        Specified by:
        readEntryAt in interface LogReader
        Parameters:
        offset - the offset at which to read the entry.
        Returns:
        a bytebuf. The caller must release.
        Throws:
        java.io.IOException
        java.io.EOFException
      • readBlock

        void readBlock​(long offset)
                throws java.io.IOException
        Throws:
        java.io.IOException
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface LogReader
        Throws:
        java.io.IOException
      • isClosed

        public boolean isClosed()
        Specified by:
        isClosed in interface LogReader
      • maxOffset

        public long maxOffset()
        Specified by:
        maxOffset in interface LogReader
        Returns:
        the maximum offset in the file that can be read from.