com.healthmarketscience.jackcess.impl
Class PageChannel

java.lang.Object
  extended by com.healthmarketscience.jackcess.impl.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()
           
static ByteBuffer createBuffer(int size)
           
static ByteBuffer createBuffer(int size, ByteOrder order)
           
 ByteBuffer createPageBuffer()
           
 void deallocatePage(int pageNumber)
          Deallocate a previously used page in the database.
 void finishWrite()
          Completes a "logical" write operation.
 void flush()
           
 JetFormat getFormat()
           
 void initialize(DatabaseImpl database, CodecProvider codecProvider)
          Does second-stage initialization, must be called after construction.
 boolean isAutoSync()
           
 boolean isOpen()
           
 boolean isWriting()
          Returns true if a logical write operation is in progress, false otherwise.
static ByteBuffer narrowBuffer(ByteBuffer buffer, int position, int limit)
           
 void readPage(ByteBuffer buffer, int pageNumber)
           
 void startWrite()
          Begins a "logical" write operation.
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(DatabaseImpl database,
                       CodecProvider codecProvider)
                throws IOException
Does second-stage initialization, must be called after construction.

Throws:
IOException

getFormat

public JetFormat getFormat()

isAutoSync

public boolean isAutoSync()

startWrite

public void startWrite()
Begins a "logical" write operation. See finishWrite() for more details.


finishWrite

public void finishWrite()
                 throws IOException
Completes a "logical" write operation. This method should be called in finally block which wraps a logical write operation (which is preceded by a startWrite() call). Logical write operations may be nested. If the database is configured for "auto-sync", the channel will be flushed when the outermost operation is complete,

Throws:
IOException

isWriting

public boolean isWriting()
Returns true if a logical write operation is in progress, false otherwise.


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 static ByteBuffer createBuffer(int size)
Returns:
A newly-allocated buffer of the given size and DEFAULT_BYTE_ORDER byte order

createBuffer

public static 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-2015 Health Market Science. All Rights Reserved.