java.lang.Object
org.cojen.tupl.io.PageArray
org.cojen.tupl.io.MappedPageArray
- All Implemented Interfaces:
Closeable,AutoCloseable,CauseCloseable
PageArray implementation which accesses a fixed sized file, fully mapped to memory.-
Method Summary
Modifier and TypeMethodDescriptionfinal voidlongcopyPage(long srcIndex, long dstIndex) longcopyPageFromPointer(long srcPointer, long dstIndex) longdirectPagePointer(long index) voidexpandPageCount(long count) Attempt to expand the total count of pages.booleanisEmpty()final booleanfinal booleanstatic booleanopen()Attempt to open or reopen the page array.static MappedPageArrayopen(int pageSize, long pageCount, File file, EnumSet<OpenOption> options) longReturns the total count of pages in the array, or Long.MAX_VALUE if not applicable.longReturn maximum allowed page count, or -1 if not applicable.voidreadPage(long index, byte[] dst, int offset, int length) voidreadPage(long index, byte[] dst, int offset, int length, ByteBuffer tail) voidreadPage(long index, long dstPtr, int offset, int length) voidreadPage(long index, long dstPtr, int offset, int length, ByteBuffer tail) voidsync(boolean metadata) Durably flushes all writes to the underlying device.voidsyncPage(long index) Durably flushes the page at the given index, but implementation might flush more pages.voidtruncatePageCount(long count) Attempt to truncate the total count of pages.voidwritePage(long index, byte[] src, int offset) Writes a page, which is lazily flushed.voidwritePage(long index, byte[] src, int offset, ByteBuffer tail) voidwritePage(long index, long srcPtr, int offset) Writes a page, which is lazily flushed.voidwritePage(long index, long srcPtr, int offset, ByteBuffer tail)
-
Method Details
-
isSupported
public static boolean isSupported() -
open
public static MappedPageArray open(int pageSize, long pageCount, File file, EnumSet<OpenOption> options) throws IOException - Parameters:
file- file to store pages, or null if anonymous- Throws:
UnsupportedOperationException- if not running on a 64-bit platformIOException
-
isFullyMapped
public final boolean isFullyMapped()- Overrides:
isFullyMappedin classPageArray
-
isReadOnly
public final boolean isReadOnly()- Specified by:
isReadOnlyin classPageArray
-
isEmpty
public boolean isEmpty() -
pageCount
public long pageCount()Description copied from class:PageArrayReturns the total count of pages in the array, or Long.MAX_VALUE if not applicable. -
truncatePageCount
public void truncatePageCount(long count) Description copied from class:PageArrayAttempt to truncate the total count of pages. Array implementation might not support truncating the page count, in which case this method does nothing.- Specified by:
truncatePageCountin classPageArray
-
expandPageCount
public void expandPageCount(long count) Description copied from class:PageArrayAttempt to expand the total count of pages. Array implementation might not support expanding the page count, in which case this method does nothing.- Specified by:
expandPageCountin classPageArray
-
pageCountLimit
public long pageCountLimit()Description copied from class:PageArrayReturn maximum allowed page count, or -1 if not applicable.- Overrides:
pageCountLimitin classPageArray
-
readPage
- Specified by:
readPagein classPageArray- Parameters:
index- zero-based page index to readdst- receives read dataoffset- offset into data buffer- Throws:
IOException- if index is greater than or equal to page count
-
readPage
public void readPage(long index, byte[] dst, int offset, int length, ByteBuffer tail) throws IOException - Overrides:
readPagein classPageArray- Throws:
IOException
-
readPage
- Overrides:
readPagein classPageArray- Parameters:
index- zero-based page index to readdstPtr- receives read dataoffset- offset into data buffer- Throws:
IOException- if index is greater than or equal to page count
-
readPage
public void readPage(long index, long dstPtr, int offset, int length, ByteBuffer tail) throws IOException - Overrides:
readPagein classPageArray- Throws:
IOException
-
writePage
Description copied from class:PageArrayWrites a page, which is lazily flushed. The array grows automatically if the index is greater than or equal to the current page count. If array supports caching, page must be immediately copied into it.- Specified by:
writePagein classPageArray- Parameters:
index- zero-based page index to writesrc- data to writeoffset- offset into data buffer- Throws:
IOException
-
writePage
- Specified by:
writePagein classPageArray- Throws:
IOException
-
writePage
Description copied from class:PageArrayWrites a page, which is lazily flushed. The array grows automatically if the index is greater than or equal to the current page count. If array supports caching, page must be immediately copied into it.- Overrides:
writePagein classPageArray- Parameters:
index- zero-based page index to writesrcPtr- data to writeoffset- offset into data buffer- Throws:
IOException
-
writePage
- Overrides:
writePagein classPageArray- Throws:
IOException
-
directPagePointer
- Overrides:
directPagePointerin classPageArray- Throws:
IOException
-
copyPage
- Overrides:
copyPagein classPageArray- Returns:
- direct pointer to destination
- Throws:
IOException
-
copyPageFromPointer
- Overrides:
copyPageFromPointerin classPageArray- Returns:
- direct pointer to destination
- Throws:
IOException
-
sync
Description copied from class:PageArrayDurably flushes all writes to the underlying device.- Specified by:
syncin classPageArray- Parameters:
metadata- pass true to flush all file metadata- Throws:
IOException
-
syncPage
Description copied from class:PageArrayDurably flushes the page at the given index, but implementation might flush more pages. File metadata is not flushed.- Overrides:
syncPagein classPageArray- Throws:
IOException
-
close
- Specified by:
closein interfaceCauseCloseable- Specified by:
closein classPageArray- Parameters:
cause- null if close is not caused by a failure- Throws:
IOException
-
open
Description copied from class:PageArrayAttempt to open or reopen the page array.- Overrides:
openin classPageArray- Returns:
- existing or new page array
- Throws:
IOException
-