Elexis API documentation
Version 2.1.6 as of December 11 2011

com.healthmarketscience.jackcess
Class PageChannel

java.lang.Object
  extended by com.healthmarketscience.jackcess.PageChannel
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable, java.nio.channels.Channel

public class PageChannel
extends java.lang.Object
implements java.nio.channels.Channel, java.io.Flushable

Reads and writes individual pages in a database file

Author:
Tim McCune

Constructor Summary
PageChannel(java.nio.channels.FileChannel channel, JetFormat format, boolean autoSync)
           
 
Method Summary
 int allocateNewPage()
          Allocates a new page in the database.
 void close()
           
 java.nio.ByteBuffer createBuffer(int size)
           
 java.nio.ByteBuffer createBuffer(int size, java.nio.ByteOrder order)
           
 java.nio.ByteBuffer createPageBuffer()
           
 void deallocatePage(int pageNumber)
          Deallocate a previously used page in the database.
 void flush()
           
 JetFormat getFormat()
           
 void initialize(Database database)
          Does second-stage initialization, must be called after construction.
 boolean isOpen()
           
static java.nio.ByteBuffer narrowBuffer(java.nio.ByteBuffer buffer, int position, int limit)
           
 void readPage(java.nio.ByteBuffer buffer, int pageNumber)
           
 int writeNewPage(java.nio.ByteBuffer page)
          Write a page to disk as a new page, appending it to the database
 void writePage(java.nio.ByteBuffer page, int pageNumber)
          Write a page to disk
 void writePage(java.nio.ByteBuffer page, int pageNumber, int pageOffset)
          Write a page (or part of a page) to disk
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PageChannel

public PageChannel(java.nio.channels.FileChannel channel,
                   JetFormat format,
                   boolean autoSync)
            throws java.io.IOException
Parameters:
channel - Channel containing the database
format - Format of the database in the channel
Throws:
java.io.IOException
Method Detail

initialize

public void initialize(Database database)
                throws java.io.IOException
Does second-stage initialization, must be called after construction.

Throws:
java.io.IOException

getFormat

public JetFormat getFormat()

readPage

public void readPage(java.nio.ByteBuffer buffer,
                     int pageNumber)
              throws java.io.IOException
Parameters:
buffer - Buffer to read the page into
pageNumber - Number of the page to read in (starting at 0)
Throws:
java.io.IOException

writePage

public void writePage(java.nio.ByteBuffer page,
                      int pageNumber)
               throws java.io.IOException
Write a page to disk

Parameters:
page - Page to write
pageNumber - Page number to write the page to
Throws:
java.io.IOException

writePage

public void writePage(java.nio.ByteBuffer page,
                      int pageNumber,
                      int pageOffset)
               throws java.io.IOException
Write a page (or part of a page) to disk

Parameters:
page - Page to write
pageNumber - Page number to write the page to
pageOffset - offset within the page at which to start writing the page data
Throws:
java.io.IOException

writeNewPage

public int writeNewPage(java.nio.ByteBuffer page)
                 throws java.io.IOException
Write a page to disk as a new page, appending it to the database

Parameters:
page - Page to write
Returns:
Page number at which the page was written
Throws:
java.io.IOException

allocateNewPage

public int allocateNewPage()
                    throws java.io.IOException
Allocates a new page in the database. Data in the page is undefined until it is written in a call to writePage(ByteBuffer,int).

Throws:
java.io.IOException

deallocatePage

public void deallocatePage(int pageNumber)
                    throws java.io.IOException
Deallocate a previously used page in the database.

Throws:
java.io.IOException

createPageBuffer

public java.nio.ByteBuffer createPageBuffer()
Returns:
A newly-allocated buffer that can be passed to readPage

createBuffer

public java.nio.ByteBuffer createBuffer(int size)
Returns:
A newly-allocated buffer of the given size and LITTLE_ENDIAN byte order

createBuffer

public java.nio.ByteBuffer createBuffer(int size,
                                        java.nio.ByteOrder order)
Returns:
A newly-allocated buffer of the given size and byte order

flush

public void flush()
           throws java.io.IOException
Specified by:
flush in interface java.io.Flushable
Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Specified by:
close in interface java.io.Closeable
Specified by:
close in interface java.nio.channels.Channel
Throws:
java.io.IOException

isOpen

public boolean isOpen()
Specified by:
isOpen in interface java.nio.channels.Channel

narrowBuffer

public static java.nio.ByteBuffer narrowBuffer(java.nio.ByteBuffer buffer,
                                               int position,
                                               int limit)
Returns:
a duplicate of the current buffer narrowed to the given position and limit. mark will be set at the current position.

Elexis API documentation
Version 2.1.6 as of December 11 2011

Copyright 2005-2011 by Gerry Weirich, Elexis