Class DefaultPageHeader

  • All Implemented Interfaces:
    PageHeader
    Direct Known Subclasses:
    TreeIndexHeader

    public class DefaultPageHeader
    extends java.lang.Object
    implements PageHeader
    Default implementation of a page header.
    Since:
    0.1
    Author:
    Elke Achtert
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static int FILE_VERSION
      Version number of this header (magic number).
      private int pageSize
      The size of a page in bytes.
      private static int SIZE
      The size of this header in Bytes, which is 8 Bytes ( 4 Bytes for FILE_VERSION and 4 Bytes for pageSize).
    • Constructor Summary

      Constructors 
      Constructor Description
      DefaultPageHeader()
      Empty constructor for serialization.
      DefaultPageHeader​(int pageSize)
      Creates a new header with the specified parameters.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int getPageSize()
      Returns the size of a page in Bytes.
      int getReservedPages()
      Returns the number of pages necessary for the header
      void readHeader​(java.nio.ByteBuffer data)
      Initializes this header from the given Byte array.
      int size()
      Returns the size of this header in Bytes.
      void writeHeader​(java.nio.ByteBuffer buffer)
      Writes this header to the specified file.
      • Methods inherited from class java.lang.Object

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

      • FILE_VERSION

        private static final int FILE_VERSION
        Version number of this header (magic number).
        See Also:
        Constant Field Values
      • pageSize

        private int pageSize
        The size of a page in bytes.
    • Constructor Detail

      • DefaultPageHeader

        public DefaultPageHeader()
        Empty constructor for serialization.
      • DefaultPageHeader

        public DefaultPageHeader​(int pageSize)
        Creates a new header with the specified parameters.
        Parameters:
        pageSize - the size of a page in bytes
    • Method Detail

      • size

        public int size()
        Description copied from interface: PageHeader
        Returns the size of this header in Bytes.
        Specified by:
        size in interface PageHeader
        Returns:
        the size of this header in Bytes
      • readHeader

        public void readHeader​(java.nio.ByteBuffer data)
        Initializes this header from the given Byte array. Looks for the right version and reads the integer value of pageSize from the file.
        Specified by:
        readHeader in interface PageHeader
        Parameters:
        data - byte array with the page data.
      • writeHeader

        public void writeHeader​(java.nio.ByteBuffer buffer)
        Writes this header to the specified file. Writes the version of this header and the integer value of pageSize to the file.
        Specified by:
        writeHeader in interface PageHeader
        Parameters:
        buffer - Buffer to write to
      • getPageSize

        public int getPageSize()
        Returns the size of a page in Bytes.
        Specified by:
        getPageSize in interface PageHeader
        Returns:
        the size of a page in Bytes
      • getReservedPages

        public int getReservedPages()
        Returns the number of pages necessary for the header
        Specified by:
        getReservedPages in interface PageHeader
        Returns:
        the number of pages