de.lmu.ifi.dbs.elki.persistent
Class OnDiskArrayPageFile<P extends Page>

java.lang.Object
  extended by de.lmu.ifi.dbs.elki.persistent.AbstractPageFile<P>
      extended by de.lmu.ifi.dbs.elki.persistent.AbstractStoringPageFile<P>
          extended by de.lmu.ifi.dbs.elki.persistent.OnDiskArrayPageFile<P>
Type Parameters:
P - Page type
All Implemented Interfaces:
PageFile<P>, PageFileStatistics

public class OnDiskArrayPageFile<P extends Page>
extends AbstractStoringPageFile<P>

A OnDiskArrayPageFile stores objects persistently that implement the Page interface. For convenience each page is represented by a single file. All pages are stored in a specified directory.


Field Summary
private static int EMPTY_PAGE
          Indicates an empty page.
private  boolean existed
          Whether or not the file originally existed
private  OnDiskArray file
          The file storing the pages.
private  File filename
          The file name to use
private static int FILLED_PAGE
          Indicates a filled page.
protected  PageHeader header
          The header of this page file.
 
Fields inherited from class de.lmu.ifi.dbs.elki.persistent.AbstractStoringPageFile
emptyPages, nextPageID, pageSize
 
Fields inherited from class de.lmu.ifi.dbs.elki.persistent.AbstractPageFile
readAccess, writeAccess
 
Constructor Summary
OnDiskArrayPageFile(int pageSize, String fileName)
          Creates a new OnDiskArrayPageFile from an existing file.
 
Method Summary
private  P byteBufferToPage(ByteBuffer buffer)
          Reconstruct a serialized object from the specified byte array.
 void clear()
          Clears this PageFile.
 void close()
          Closes this file.
 void deletePage(int pageID)
          Deletes the node with the specified id from this file.
 boolean initialize(PageHeader header)
          Initialize the page file with the given header - return "true" if the file already existed.
private  byte[] pageToByteArray(P page)
          Serializes an object into a byte array.
 P readPage(int pageID)
          Reads the page with the given id from this file.
 void writePage(Integer pageID, P page)
          Write page to disk.
 
Methods inherited from class de.lmu.ifi.dbs.elki.persistent.AbstractStoringPageFile
getInnerStatistics, getNextPageID, getPageSize, setNextPageID, setPageID
 
Methods inherited from class de.lmu.ifi.dbs.elki.persistent.AbstractPageFile
getReadOperations, getWriteOperations, resetPageAccess, writePage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_PAGE

private static final int EMPTY_PAGE
Indicates an empty page.

See Also:
Constant Field Values

FILLED_PAGE

private static final int FILLED_PAGE
Indicates a filled page.

See Also:
Constant Field Values

filename

private File filename
The file name to use


file

private OnDiskArray file
The file storing the pages.


header

protected PageHeader header
The header of this page file.


existed

private final boolean existed
Whether or not the file originally existed

Constructor Detail

OnDiskArrayPageFile

public OnDiskArrayPageFile(int pageSize,
                           String fileName)
Creates a new OnDiskArrayPageFile from an existing file.

Parameters:
pageSize - page size
fileName - the name of the file
Method Detail

readPage

public P readPage(int pageID)
Reads the page with the given id from this file.

Parameters:
pageID - the id of the page to be returned
Returns:
the page with the given pageId

deletePage

public void deletePage(int pageID)
Deletes the node with the specified id from this file.

Specified by:
deletePage in interface PageFile<P extends Page>
Overrides:
deletePage in class AbstractStoringPageFile<P extends Page>
Parameters:
pageID - the id of the node to be deleted

writePage

public void writePage(Integer pageID,
                      P page)
Write page to disk.

Specified by:
writePage in class AbstractPageFile<P extends Page>
Parameters:
pageID - page id
page - the page which has to be written to disk

close

public void close()
Closes this file.

Specified by:
close in interface PageFile<P extends Page>
Overrides:
close in class AbstractPageFile<P extends Page>

clear

public void clear()
Clears this PageFile.


byteBufferToPage

private P byteBufferToPage(ByteBuffer buffer)
Reconstruct a serialized object from the specified byte array.

Parameters:
buffer - the buffer from which the object should be reconstructed
Returns:
a serialized object from the specified byte array

pageToByteArray

private byte[] pageToByteArray(P page)
Serializes an object into a byte array.

Parameters:
page - the object to be serialized
Returns:
the byte array

initialize

public boolean initialize(PageHeader header)
Description copied from class: AbstractStoringPageFile
Initialize the page file with the given header - return "true" if the file already existed.

Specified by:
initialize in interface PageFile<P extends Page>
Overrides:
initialize in class AbstractStoringPageFile<P extends Page>
Parameters:
header - Header
Returns:
true when the file already existed.

Release 0.4.0 (2011-09-20_1324)