com.healthmarketscience.jackcess
Class PageChannel

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

public class PageChannel
extends Object
implements Channel, Flushable

Reads and writes individual pages in a database file

Author:
Tim McCune

Constructor Summary
PageChannel(FileChannel channel, boolean closeChannel, JetFormat format, boolean autoSync)
           
 
Method Summary
 int allocateNewPage()
          Allocates a new page in the database.
 void close()
           
 ByteBuffer createBuffer(int size)
           
 ByteBuffer createBuffer(int size, ByteOrder order)
           
 ByteBuffer createPageBuffer()
           
 void deallocatePage(int pageNumber)
          Deallocate a previously used page in the database.
 void flush()
           
 JetFormat getFormat()
           
 void initialize(Database database, CodecProvider codecProvider)
          Does second-stage initialization, must be called after construction.
 boolean isAutoSync()
           
 boolean isOpen()
           
static ByteBuffer narrowBuffer(ByteBuffer buffer, int position, int limit)
           
 void readPage(ByteBuffer buffer, int pageNumber)
           
static ByteBuffer wrap(byte[] bytes)
          Returns a ByteBuffer wrapping the given bytes and configured with the default byte order.
 void writePage(ByteBuffer page, int pageNumber)
          Write a page to disk
 void writePage(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(FileChannel channel,
                   boolean closeChannel,
                   JetFormat format,
                   boolean autoSync)
            throws IOException
Parameters:
channel - Channel containing the database
format - Format of the database in the channel
Throws:
IOException
Method Detail

initialize

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

Throws:
IOException

getFormat

public JetFormat getFormat()

isAutoSync

public boolean isAutoSync()

readPage

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

writePage

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

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

writePage

public void writePage(ByteBuffer page,
                      int pageNumber,
                      int pageOffset)
               throws 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:
IOException

allocateNewPage

public int allocateNewPage()
                    throws 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:
IOException

deallocatePage

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

Throws:
IOException

createPageBuffer

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

createBuffer

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

createBuffer

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

flush

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

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Specified by:
close in interface Channel
Throws:
IOException

isOpen

public boolean isOpen()
Specified by:
isOpen in interface Channel

narrowBuffer

public static ByteBuffer narrowBuffer(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.

wrap

public static ByteBuffer wrap(byte[] bytes)
Returns a ByteBuffer wrapping the given bytes and configured with the default byte order.



Copyright © 2005-2013 Health Market Science. All Rights Reserved.