Class PageChannel
- java.lang.Object
-
- com.healthmarketscience.jackcess.impl.PageChannel
-
-
Field Summary
Fields Modifier and Type Field Description static ByteOrderDEFAULT_BYTE_ORDERdefault byte order of access mdb files
-
Constructor Summary
Constructors Constructor Description PageChannel(FileChannel channel, boolean closeChannel, JetFormat format, boolean autoSync)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intallocateNewPage()Allocates a new page in the database.voidclose()static ByteBuffercreateBuffer(int size)static ByteBuffercreateBuffer(int size, ByteOrder order)ByteBuffercreatePageBuffer()voiddeallocatePage(int pageNumber)Deallocate a previously used page in the database.voidfinishWrite()Completes a "logical" write operation.voidflush()JetFormatgetFormat()voidinitialize(DatabaseImpl database, CodecProvider codecProvider)Does second-stage initialization, must be called after construction.booleanisAutoSync()booleanisOpen()booleanisReuseFreePages()booleanisWriting()Returnstrueif a logical write operation is in progress,falseotherwise.static ByteBuffernarrowBuffer(ByteBuffer buffer, int position, int limit)voidreadPage(ByteBuffer buffer, int pageNumber)voidreadRootPage(ByteBuffer buffer)voidsetReuseFreePages(boolean reuseFreePages)voidstartExclusiveWrite()Begins an exclusive "logical" write operation (throws an exception if another write operation is outstanding).voidstartWrite()Begins a "logical" write operation.inttruncateFreeSpace()Shortens the file to drop the run of free pages at the end of it, and returns the number of pages it dropped.static ByteBufferwrap(byte[] bytes)Returns a ByteBuffer wrapping the given bytes and configured with the default byte order.voidwritePage(ByteBuffer page, int pageNumber)Write a page to diskvoidwritePage(ByteBuffer page, int pageNumber, int pageOffset)Write a page (or part of a page) to disk
-
-
-
Field Detail
-
DEFAULT_BYTE_ORDER
public static final ByteOrder DEFAULT_BYTE_ORDER
default byte order of access mdb files
-
-
Constructor Detail
-
PageChannel
public PageChannel(FileChannel channel, boolean closeChannel, JetFormat format, boolean autoSync)
- Parameters:
channel- Channel containing the databaseformat- Format of the database in the channel
-
-
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()
-
isReuseFreePages
public boolean isReuseFreePages()
-
setReuseFreePages
public void setReuseFreePages(boolean reuseFreePages)
-
startWrite
public void startWrite()
Begins a "logical" write operation. SeefinishWrite()for more details.
-
startExclusiveWrite
public void startExclusiveWrite()
Begins an exclusive "logical" write operation (throws an exception if another write operation is outstanding). SeefinishWrite()for more details.
-
finishWrite
public void finishWrite() throws IOExceptionCompletes a "logical" write operation. This method should be called in finally block which wraps a logical write operation (which is preceded by astartWrite()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()
Returnstrueif a logical write operation is in progress,falseotherwise.
-
readPage
public void readPage(ByteBuffer buffer, int pageNumber) throws IOException
- Parameters:
buffer- Buffer to read the page intopageNumber- Number of the page to read in (starting at 0)- Throws:
IOException
-
readRootPage
public void readRootPage(ByteBuffer buffer) throws IOException
- Parameters:
buffer- Buffer to read the root page into- Throws:
IOException
-
writePage
public void writePage(ByteBuffer page, int pageNumber) throws IOException
Write a page to disk- Parameters:
page- Page to writepageNumber- 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 writepageNumber- Page number to write the page topageOffset- offset within the page at which to start writing the page data- Throws:
IOException
-
allocateNewPage
public int allocateNewPage() throws IOExceptionAllocates a new page in the database. Data in the page is undefined until it is written in a call towritePage(ByteBuffer,int).- Throws:
IOException
-
truncateFreeSpace
public int truncateFreeSpace() throws IOExceptionShortens the file to drop the run of free pages at the end of it, and returns the number of pages it dropped. A file can be shortened only at its end, so this is the whole of what can be given back without rewriting the file.- Throws:
IOException
-
deallocatePage
public void deallocatePage(int pageNumber) throws IOExceptionDeallocate 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:
flushin interfaceFlushable- Throws:
IOException
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceChannel- Specified by:
closein interfaceCloseable- Throws:
IOException
-
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.
-
-