public interface PageCursor extends AutoCloseable
PagedFile.io(long, int),
and is used to scan through pages and process them in a consistent and safe fashion.
A page must be processed in the following manner:
try ( PageCursor cursor = pagedFile.io( pageId, pf_flags ) )
{
// Use 'if' for processing a single page,
// use 'while' for scanning through pages:
if ( cursor.next() )
{
do
{
processPage( cursor );
} while ( cursor.shouldRetry() );
// Any finalising, non-repeatable post-processing
// goes here.
}
}
catch ( IOException e )
{
// handle the error, somehow
}
There are a couple of things to this pattern that are worth noting:
next(long) method, to navigate the
pages you need in a non-linear fashion.| Modifier and Type | Field and Description |
|---|---|
static long |
UNBOUND_PAGE_ID |
static int |
UNBOUND_PAGE_SIZE |
| Modifier and Type | Method and Description |
|---|---|
boolean |
checkAndClearBoundsFlag()
Discern whether an out-of-bounds access has occurred since the last call to
next() or
next(long), or since the last call to shouldRetry() that returned true, or since the
last call to this method. |
void |
close()
Relinquishes all resources associated with this cursor, including the
cursor itself, and any linked cursors opened through it.
|
int |
copyTo(int sourceOffset,
PageCursor targetCursor,
int targetOffset,
int lengthInBytes)
Copy the specified number of bytes from the given offset of this page, to the given offset of the target page.
|
byte |
getByte()
Get the signed byte at the current page offset, and then increment the offset by one.
|
byte |
getByte(int offset)
Get the signed byte at the given offset into the page.
|
void |
getBytes(byte[] data)
Fill the given array with bytes from the page, beginning at the current offset into the page,
and then increment the current offset by the length of the array.
|
void |
getBytes(byte[] data,
int arrayOffset,
int length)
Read the given length of bytes from the page into the given array, starting from the current offset into the
page, and writing from the given array offset, and then increment the current offset by the length argument.
|
File |
getCurrentFile()
Get the file the cursor is currently bound to, or
null if next() has not yet been called on this
cursor, or returned false. |
long |
getCurrentPageId()
Get the file page id that the cursor is currently positioned at, or
UNBOUND_PAGE_ID if next() has not yet been called on this cursor, or returned false.
|
int |
getCurrentPageSize()
Get the file page size of the page that the cursor is currently positioned at,
or UNBOUND_PAGE_SIZE if next() has not yet been called on this cursor, or returned false.
|
int |
getInt()
Get the signed int at the current page offset, and then increment the offset by one.
|
int |
getInt(int offset)
Get the signed int at the given offset into the page.
|
long |
getLong()
Get the signed long at the current page offset, and then increment the offset by one.
|
long |
getLong(int offset)
Get the signed long at the given offset into the page.
|
int |
getOffset()
Get the current offset into the page, which is the location on the page where the next interaction would take
place through the read and write methods that do not take a specific offset as an argument.
|
short |
getShort()
Get the signed short at the current page offset, and then increment the offset by one.
|
short |
getShort(int offset)
Get the signed short at the given offset into the page.
|
boolean |
next()
Moves the cursor to the next page, if any, and returns true when it is
ready to be processed.
|
boolean |
next(long pageId)
Moves the cursor to the page specified by the given pageId, if any,
and returns true when it is ready to be processed.
|
PageCursor |
openLinkedCursor(long pageId)
Open a new page cursor with the same pf_flags as this cursor, as if calling the
PagedFile.io(long, int)
on the relevant paged file. |
void |
putByte(byte value)
Set the signed byte at the current offset into the page, and then increment the offset by one.
|
void |
putByte(int offset,
byte value)
Set the signed byte at the given offset into the page.
|
void |
putBytes(byte[] data)
Write out all the bytes of the given array into the page, beginning at the current offset into the page,
and then increment the current offset by the length of the array.
|
void |
putBytes(byte[] data,
int arrayOffset,
int length)
Write out the given length of bytes from the given offset into the the given array of bytes, into the page,
beginning at the current offset into the page, and then increment the current offset by the length argument.
|
void |
putInt(int value)
Set the signed int at the current offset into the page, and then increment the offset by one.
|
void |
putInt(int offset,
int value)
Set the signed int at the given offset into the page.
|
void |
putLong(int offset,
long value)
Set the signed long at the given offset into the page.
|
void |
putLong(long value)
Set the signed long at the current offset into the page, and then increment the offset by one.
|
void |
putShort(int offset,
short value)
Set the signed short at the given offset into the page.
|
void |
putShort(short value)
Set the signed short at the current offset into the page, and then increment the offset by one.
|
void |
raiseOutOfBounds()
Explicitly raise the out-of-bounds flag.
|
void |
rewind()
Rewinds the cursor to its initial condition, as if freshly returned from
an equivalent io() call.
|
void |
setOffset(int offset)
Set the current offset into the page, for interacting with the page through the read and write methods that do
not take a specific offset as an argument.
|
boolean |
shouldRetry()
Returns true if the page has entered an inconsistent state since the
last call to next() or shouldRetry().
|
static final long UNBOUND_PAGE_ID
static final int UNBOUND_PAGE_SIZE
byte getByte()
byte getByte(int offset)
void putByte(byte value)
void putByte(int offset,
byte value)
long getLong()
long getLong(int offset)
void putLong(long value)
void putLong(int offset,
long value)
int getInt()
int getInt(int offset)
void putInt(int value)
void putInt(int offset,
int value)
void getBytes(byte[] data)
void getBytes(byte[] data,
int arrayOffset,
int length)
IndexOutOfBoundsException - if the current offset plus the length reaches beyond the end of the page.void putBytes(byte[] data)
IndexOutOfBoundsException - if the current offset plus the length of the array reaches beyond the end of the page.void putBytes(byte[] data,
int arrayOffset,
int length)
IndexOutOfBoundsException - if the current offset plus the length reaches beyond the end of the page.short getShort()
IndexOutOfBoundsException - if the current offset is not within the page bounds.short getShort(int offset)
IndexOutOfBoundsException - if the given offset is not within the page bounds.void putShort(short value)
IndexOutOfBoundsException - if the current offset is not within the page bounds.void putShort(int offset,
short value)
IndexOutOfBoundsException - if the given offset is not within the page bounds.void setOffset(int offset)
int getOffset()
long getCurrentPageId()
int getCurrentPageSize()
File getCurrentFile()
null if next() has not yet been called on this
cursor, or returned false.
A call to rewind() will make the cursor unbound as well, until next() is called.void rewind()
boolean next()
throws IOException
IOExceptionboolean next(long pageId)
throws IOException
IOExceptionvoid close()
close in interface AutoCloseableAutoCloseable.close()boolean shouldRetry()
throws IOException
IOException - If the page was evicted while doing IO, the cursor will have
to do a page fault to get the page back.
This may throw an IOException.int copyTo(int sourceOffset,
PageCursor targetCursor,
int targetOffset,
int lengthInBytes)
If the length reaches beyond the end of either cursor, then only as many bytes as are available in this cursor, or can fit in the target cursor, are actually copied.
sourceOffset - The offset into this page to copy from.targetCursor - The cursor the data will be copied to.targetOffset - The offset into the target cursor to copy to.lengthInBytes - The number of bytes to copy.boolean checkAndClearBoundsFlag()
next() or
next(long), or since the last call to shouldRetry() that returned true, or since the
last call to this method.true if an access was out of bounds, or the raiseOutOfBounds() method has been called.void raiseOutOfBounds()
checkAndClearBoundsFlag()PageCursor openLinkedCursor(long pageId)
PagedFile.io(long, int)
on the relevant paged file. This cursor will then also delegate to the linked cursor when checking
shouldRetry() and checkAndClearBoundsFlag().
Opening a linked cursor on a cursor that already has a linked cursor, will close the older linked cursor.
Closing a cursor also closes any linked cursor.pageId - The page id that the linked cursor will be placed at after its first call to next().Copyright © 2002–2016 The Neo4j Graph Database Project. All rights reserved.