Class AbstractPagedInputView

  • All Implemented Interfaces:
    DataInput, org.apache.flink.core.memory.DataInputView
    Direct Known Subclasses:
    AbstractChannelReaderInputView, FileChannelInputView, HashPartition, RandomAccessInputView, SeekableFileChannelInputView

    public abstract class AbstractPagedInputView
    extends Object
    implements org.apache.flink.core.memory.DataInputView
    The base class for all input views that are backed by multiple memory pages. This base class contains all decoding methods to read data from a page and detect page boundary crossing. The concrete sub classes must implement the methods to provide the next memory page once the boundary is crossed.
    • Field Detail

      • headerLength

        protected final int headerLength
    • Constructor Detail

      • AbstractPagedInputView

        protected AbstractPagedInputView​(org.apache.flink.core.memory.MemorySegment initialSegment,
                                         int initialLimit,
                                         int headerLength)
        Creates a new view that starts with the given segment. The input starts directly after the header of the given page. If the header size is zero, it starts at the beginning. The specified initial limit describes up to which position data may be read from the current segment, before the view must advance to the next segment.
        Parameters:
        initialSegment - The memory segment to start reading from.
        initialLimit - The position one after the last valid byte in the initial segment.
        headerLength - The number of bytes to skip at the beginning of each segment for the header. This length must be the same for all memory segments.
      • AbstractPagedInputView

        protected AbstractPagedInputView​(int headerLength)
        Creates a new view that is initially not bound to a memory segment. This constructor is typically for views that always seek first.

        WARNING: The view is not readable until the first call to either advance(), or to seekInput(MemorySegment, int, int).

        Parameters:
        headerLength - The number of bytes to skip at the beginning of each segment for the header.
    • Method Detail

      • getCurrentSegment

        public org.apache.flink.core.memory.MemorySegment getCurrentSegment()
        Gets the memory segment that will be used to read the next bytes from. If the segment is exactly exhausted, meaning that the last byte read was the last byte available in the segment, then this segment will not serve the next bytes. The segment to serve the next bytes will be obtained through the nextSegment(MemorySegment) method.
        Returns:
        The current memory segment.
      • getCurrentPositionInSegment

        public int getCurrentPositionInSegment()
        Gets the position from which the next byte will be read. If that position is equal to the current limit, then the next byte will be read from next segment.
        Returns:
        The position from which the next byte will be read.
        See Also:
        getCurrentSegmentLimit()
      • getCurrentSegmentLimit

        public int getCurrentSegmentLimit()
        Gets the current limit in the memory segment. This value points to the byte one after the last valid byte in the memory segment.
        Returns:
        The current limit in the memory segment.
        See Also:
        getCurrentPositionInSegment()
      • nextSegment

        protected abstract org.apache.flink.core.memory.MemorySegment nextSegment​(org.apache.flink.core.memory.MemorySegment current)
                                                                           throws EOFException,
                                                                                  IOException
        The method by which concrete subclasses realize page crossing. This method is invoked when the current page is exhausted and a new page is required to continue the reading. If no further page is available, this method must throw an EOFException.
        Parameters:
        current - The current page that was read to its limit. May be null, if this method is invoked for the first time.
        Returns:
        The next page from which the reading should continue. May not be null. If the input is exhausted, an EOFException must be thrown instead.
        Throws:
        EOFException - Thrown, if no further segment is available.
        IOException - Thrown, if the method cannot provide the next page due to an I/O related problem.
      • getLimitForSegment

        protected abstract int getLimitForSegment​(org.apache.flink.core.memory.MemorySegment segment)
        Gets the limit for reading bytes from the given memory segment. This method must return the position of the byte after the last valid byte in the given memory segment. When the position returned by this method is reached, the view will attempt to switch to the next memory segment.
        Parameters:
        segment - The segment to determine the limit for.
        Returns:
        The limit for the given memory segment.
      • getHeaderLength

        public int getHeaderLength()
        Returns:
        header length.
      • seekInput

        protected void seekInput​(org.apache.flink.core.memory.MemorySegment segment,
                                 int positionInSegment,
                                 int limitInSegment)
        Sets the internal state of the view such that the next bytes will be read from the given memory segment, starting at the given position. The memory segment will provide bytes up to the given limit position.
        Parameters:
        segment - The segment to read the next bytes from.
        positionInSegment - The position in the segment to start reading from.
        limitInSegment - The limit in the segment. When reached, the view will attempt to switch to the next segment.
      • read

        public int read​(byte[] b)
                 throws IOException
        Specified by:
        read in interface org.apache.flink.core.memory.DataInputView
        Throws:
        IOException
      • read

        public int read​(byte[] b,
                        int off,
                        int len)
                 throws IOException
        Specified by:
        read in interface org.apache.flink.core.memory.DataInputView
        Throws:
        IOException
      • skipBytesToRead

        public void skipBytesToRead​(int numBytes)
                             throws IOException
        Specified by:
        skipBytesToRead in interface org.apache.flink.core.memory.DataInputView
        Throws:
        IOException