de.lmu.ifi.dbs.elki.persistent
Class DefaultPageHeader

java.lang.Object
  extended by de.lmu.ifi.dbs.elki.persistent.DefaultPageHeader
All Implemented Interfaces:
PageHeader
Direct Known Subclasses:
TreeIndexHeader

public class DefaultPageHeader
extends Object
implements PageHeader

Default implementation of a page header.


Field Summary
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
DefaultPageHeader()
          Empty constructor for serialization.
DefaultPageHeader(int pageSize)
          Creates a new header with the specified parameters.
 
Method Summary
 byte[] asByteArray()
          Return the header as byte array
 int getPageSize()
          Returns the size of a page in Bytes.
 int getReservedPages()
          Returns the number of pages necessary for the header
 void readHeader(byte[] data)
          Initializes this header from the given Byte array.
 void readHeader(RandomAccessFile file)
          Initializes this header from the specified file.
 int size()
          Returns the value of SIZE).
 void writeHeader(RandomAccessFile file)
          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

SIZE

private static final int SIZE
The size of this header in Bytes, which is 8 Bytes ( 4 Bytes for FILE_VERSION and 4 Bytes for pageSize).

See Also:
Constant Field Values

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()
Returns the value of SIZE).

Specified by:
size in interface PageHeader
Returns:
the size of this header in Bytes

readHeader

public void readHeader(RandomAccessFile file)
                throws IOException
Initializes this header from the specified file. Looks for the right version and reads the integer value of pageSize from the file.

Specified by:
readHeader in interface PageHeader
Parameters:
file - the file to which this header belongs
Throws:
IOException - if an I/O-error occurs during reading

readHeader

public void readHeader(byte[] 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(RandomAccessFile file)
                 throws IOException
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:
file - the file to which this header belongs
Throws:
IOException - IOException if an I/O-error occurs during writing

asByteArray

public byte[] asByteArray()
Description copied from interface: PageHeader
Return the header as byte array

Specified by:
asByteArray in interface PageHeader
Returns:
header as byte array

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

Release 0.4.0 (2011-09-20_1324)