Class AbstractPagedInputView

java.lang.Object
org.apache.flink.runtime.memory.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 Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final int
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    AbstractPagedInputView(int headerLength)
    Creates a new view that is initially not bound to a memory segment.
    protected
    AbstractPagedInputView(org.apache.flink.core.memory.MemorySegment initialSegment, int initialLimit, int headerLength)
    Creates a new view that starts with the given segment.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Advances the view to the next memory segment.
    protected void
    Clears the internal state of the view.
    protected void
     
    int
    Gets the position from which the next byte will be read.
    org.apache.flink.core.memory.MemorySegment
    Gets the memory segment that will be used to read the next bytes from.
    int
    Gets the current limit in the memory segment.
    int
     
    protected abstract int
    getLimitForSegment(org.apache.flink.core.memory.MemorySegment segment)
    Gets the limit for reading bytes from the given memory segment.
    protected abstract org.apache.flink.core.memory.MemorySegment
    nextSegment(org.apache.flink.core.memory.MemorySegment current)
    The method by which concrete subclasses realize page crossing.
    int
    read(byte[] b)
     
    int
    read(byte[] b, int off, int len)
     
    boolean
     
    byte
     
    char
     
    double
     
    float
     
    void
    readFully(byte[] b)
     
    void
    readFully(byte[] b, int off, int len)
     
    int
     
     
    long
     
    short
     
    int
     
    int
     
     
    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.
    int
    skipBytes(int n)
     
    void
    skipBytesToRead(int numBytes)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • headerLength

      protected final int headerLength
  • Constructor Details

    • 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 Details

    • 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

      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:
    • 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.
    • advance

      public void advance() throws IOException
      Advances the view to the next memory segment. The reading will continue after the header of the next segment. This method uses nextSegment(MemorySegment) and getLimitForSegment(MemorySegment) to get the next segment and set its limit.
      Throws:
      IOException - Thrown, if the next segment could not be obtained.
      See Also:
    • doAdvance

      protected void doAdvance() throws IOException
      Throws:
      IOException
    • 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.
    • clear

      protected void clear()
      Clears the internal state of the view. After this call, all read attempts will fail, until the advance() or seekInput(MemorySegment, int, int) method have been invoked.
    • 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
    • readFully

      public void readFully(byte[] b) throws IOException
      Specified by:
      readFully in interface DataInput
      Throws:
      IOException
    • readFully

      public void readFully(byte[] b, int off, int len) throws IOException
      Specified by:
      readFully in interface DataInput
      Throws:
      IOException
    • readBoolean

      public boolean readBoolean() throws IOException
      Specified by:
      readBoolean in interface DataInput
      Throws:
      IOException
    • readByte

      public byte readByte() throws IOException
      Specified by:
      readByte in interface DataInput
      Throws:
      IOException
    • readUnsignedByte

      public int readUnsignedByte() throws IOException
      Specified by:
      readUnsignedByte in interface DataInput
      Throws:
      IOException
    • readShort

      public short readShort() throws IOException
      Specified by:
      readShort in interface DataInput
      Throws:
      IOException
    • readUnsignedShort

      public int readUnsignedShort() throws IOException
      Specified by:
      readUnsignedShort in interface DataInput
      Throws:
      IOException
    • readChar

      public char readChar() throws IOException
      Specified by:
      readChar in interface DataInput
      Throws:
      IOException
    • readInt

      public int readInt() throws IOException
      Specified by:
      readInt in interface DataInput
      Throws:
      IOException
    • readLong

      public long readLong() throws IOException
      Specified by:
      readLong in interface DataInput
      Throws:
      IOException
    • readFloat

      public float readFloat() throws IOException
      Specified by:
      readFloat in interface DataInput
      Throws:
      IOException
    • readDouble

      public double readDouble() throws IOException
      Specified by:
      readDouble in interface DataInput
      Throws:
      IOException
    • readLine

      public String readLine() throws IOException
      Specified by:
      readLine in interface DataInput
      Throws:
      IOException
    • readUTF

      public String readUTF() throws IOException
      Specified by:
      readUTF in interface DataInput
      Throws:
      IOException
    • skipBytes

      public int skipBytes(int n) throws IOException
      Specified by:
      skipBytes in interface DataInput
      Throws:
      IOException
    • skipBytesToRead

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