Class PageReader

  • Direct Known Subclasses:
    PageWriter

    public class PageReader
    extends java.lang.Object
    This class facilitates sequences of read operations against a single DBPage object, by providing "position" state that is also updated after each read is performed. All read operations call through to the DBPage's interface.
    See Also:
    PageWriter, DataInput
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected DBPage dbPage
      The page that the reader will read from.
      protected int position
      The current position in the page where reads will occur from.
    • Constructor Summary

      Constructors 
      Constructor Description
      PageReader​(DBPage dbPage)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      DBPage getDBPage()  
      int getPosition()
      Returns the current location in the page where the next operation will start from.
      void movePosition​(int n)
      Move the current position by n bytes.
      void read​(byte[] b)
      Read a sequence of bytes into the provided byte-array.
      void read​(byte[] b, int off, int len)
      Read a sequence of bytes into the provided byte-array, starting with the specified offset, and reading the specified number of bytes.
      boolean readBoolean()
      Reads and returns a Boolean value from the current position.
      byte readByte()
      Reads and returns a signed byte from the current position.
      char readChar()
      Reads and returns a two-byte char value from the current position.
      java.time.LocalDate readDate()  
      java.time.LocalDateTime readDateTime()  
      double readDouble()  
      java.lang.String readFixedSizeString​(int len)
      This method reads and returns a string whose length is fixed at a consant size.
      float readFloat()  
      int readInt()
      Reads and returns a four-byte integer value from the current position.
      long readLong()
      Reads and returns an eight-byte long integer value from the current position.
      java.math.BigDecimal readNumeric()  
      java.lang.Object readObject​(ColumnType colType)  
      short readShort()
      Reads and returns a signed short from the current position.
      java.time.LocalTime readTime()  
      int readUnsignedByte()
      Reads and returns an unsigned byte from the current position.
      long readUnsignedInt()
      Reads and returns a four-byte unsigned integer value from the current position.
      int readUnsignedShort()
      Reads and returns an unsigned short from the current position.
      java.lang.String readVarString255()
      This method reads and returns a variable-length string whose maximum length is 255 bytes.
      java.lang.String readVarString65535()
      This method reads and returns a variable-length string whose maximum length is 65535 bytes.
      void setPosition​(int position)
      Sets the location in the page where the next operation will start from.
      • Methods inherited from class java.lang.Object

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

      • dbPage

        protected DBPage dbPage
        The page that the reader will read from.
      • position

        protected int position
        The current position in the page where reads will occur from.
    • Constructor Detail

      • PageReader

        public PageReader​(DBPage dbPage)
    • Method Detail

      • getDBPage

        public DBPage getDBPage()
      • getPosition

        public int getPosition()
        Returns the current location in the page where the next operation will start from.
        Returns:
        the current location in the page
      • setPosition

        public void setPosition​(int position)
        Sets the location in the page where the next operation will start from.
        Parameters:
        position - the new location in the page
      • movePosition

        public void movePosition​(int n)
        Move the current position by n bytes. A negative value of n will move the position backward.
        Parameters:
        n - the delta to apply to the current position
      • read

        public void read​(byte[] b,
                         int off,
                         int len)
        Read a sequence of bytes into the provided byte-array, starting with the specified offset, and reading the specified number of bytes.
        Parameters:
        b - the byte-array to read bytes into
        off - the offset to read the bytes into the array
        len - the number of bytes to read into the array
      • read

        public void read​(byte[] b)
        Read a sequence of bytes into the provided byte-array. The entire array is filled from start to end.
        Parameters:
        b - the byte-array to read bytes into
      • readBoolean

        public boolean readBoolean()
        Reads and returns a Boolean value from the current position. A zero value is interpreted as false, and a nonzero value is interpreted as true.
      • readByte

        public byte readByte()
        Reads and returns a signed byte from the current position.
      • readUnsignedByte

        public int readUnsignedByte()
        Reads and returns an unsigned byte from the current position. The value is returned as an int whose value will be between 0 and 255, inclusive.
      • readUnsignedShort

        public int readUnsignedShort()
        Reads and returns an unsigned short from the current position. The value is returned as an int whose value will be between 0 and 65535, inclusive.
      • readShort

        public short readShort()
        Reads and returns a signed short from the current position.
      • readChar

        public char readChar()
        Reads and returns a two-byte char value from the current position.
      • readUnsignedInt

        public long readUnsignedInt()
        Reads and returns a four-byte unsigned integer value from the current position.
      • readInt

        public int readInt()
        Reads and returns a four-byte integer value from the current position.
      • readLong

        public long readLong()
        Reads and returns an eight-byte long integer value from the current position.
      • readFloat

        public float readFloat()
      • readDouble

        public double readDouble()
      • readNumeric

        public java.math.BigDecimal readNumeric()
      • readVarString255

        public java.lang.String readVarString255()
        This method reads and returns a variable-length string whose maximum length is 255 bytes. The string is expected to be in US-ASCII encoding, so multibyte characters are not supported.

        The string's data format is expected to be a single unsigned byte b specifying the string's length, followed by b more bytes consisting of the string value itself.

      • readVarString65535

        public java.lang.String readVarString65535()
        This method reads and returns a variable-length string whose maximum length is 65535 bytes. The string is expected to be in US-ASCII encoding, so multibyte characters are not supported.

        The string's data format is expected to be a single unsigned short (two bytes) s specifying the string's length, followed by s more bytes consisting of the string value itself.

      • readFixedSizeString

        public java.lang.String readFixedSizeString​(int len)
        This method reads and returns a string whose length is fixed at a consant size. The string is expected to be in US-ASCII encoding, so multibyte characters are not supported.

        Shorter strings are padded with 0 bytes at the end of the string, and this padding is removed when the string is read. Thus, the actual string read may be shorter than the specified length, but the number of bytes the string's value takes in the page is exactly the specified length.

      • readDate

        public java.time.LocalDate readDate()
      • readTime

        public java.time.LocalTime readTime()
      • readDateTime

        public java.time.LocalDateTime readDateTime()
      • readObject

        public java.lang.Object readObject​(ColumnType colType)