public class PageNavigator extends Object implements Seekable
| Modifier and Type | Field and Description |
|---|---|
protected int |
absMaxIndexInPage |
protected int |
absMinIndexInPage |
protected long |
bufferForPage |
protected int |
displacement |
protected int |
index
Index is relative to the the page's buffer.position()
|
protected int |
maxIndex |
protected long |
maxPage |
protected long |
maxPos |
protected int |
minIndex |
protected long |
minPage |
protected long |
minPos |
protected long |
page
Current page
|
protected ByteBuffer |
pageBuffer |
protected PageManager |
pageManager |
protected Reference<Page> |
pageObj |
protected int |
pageSize |
protected int |
relMaxIndexInPage |
protected int |
relMinIndexInPage |
| Constructor and Description |
|---|
PageNavigator(PageManager pageManager) |
PageNavigator(PageManager pageManager,
long minPos,
long maxPos) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
canNextPos() |
boolean |
canPrevPos() |
int |
checkNext(int len,
boolean changePos)
Attempt to advance the position by the given number of bytes.
|
int |
checkPrev(int len,
boolean changePos) |
PageNavigator |
clone()
Clone the state of the navigator, allowing independent positioning
|
void |
close() |
int |
compareToPrefix(byte[] prefix)
Compare the bytes at the current position to a given sequence of bytes
If there are fewer bytes available in the seekable than provide for comparison,
then only that many are compared.
|
byte |
get()
Get the byte at the current position
Does not change the position
Throws an exception if beyond end of data
|
ByteBuffer |
getBufferForPage(long page)
If a page with the given offset exists, the following fields are updated:
- displacement
- absMinIndexInPage
- absMaxIndexInPage
Note, that the relative caches are not updated
|
ByteBuffer |
getBufferForPos(long pos) |
int |
getIndexForPos(long pos) |
long |
getMaxPos() |
long |
getMinPos() |
long |
getNextPosFor(byte delimiter)
Returns the position of the next delimiter or the end of the stream
|
long |
getPageForPos(long pos) |
long |
getPos()
Optional operation.
|
long |
getPrevPosFor(byte delimiter) |
int |
getRelMaxIndex(long page) |
int |
getRelMinIndex(long page) |
boolean |
isOpen() |
boolean |
isPosAfterEnd()
The state of a seekable may be one unit beyond the end.
|
boolean |
isPosBeforeStart()
The state of a seekable may be one unit before the start.
|
PageNavigator |
limitNext(long length)
Limit the
|
PageNavigator |
limitPrev(long length)
Limit the
|
boolean |
nextPos(int delta)
Attempts to advance the position by delta bytes
and returns true if this succeeded.
|
int |
peekNextBytes(byte[] dst,
int offset,
int len)
Reads bytes at the current position; does not advance pos
|
void |
posToEnd()
Optional operation.
|
boolean |
posToNext(byte delimiter)
Advances the position to the next matching delimiter or
one byte past the end of the stream.
|
boolean |
posToPrev(byte delimiter)
Move the position to the previous delimiter if it exists,
or one element past the end of data such that isPosBeforeStart() yields true.
|
void |
posToStart()
Optional operation.
|
boolean |
prevPos(int delta)
Attempt to step back the position by the given number of bytes.
|
int |
read(ByteBuffer dst) |
String |
readLine() |
static int |
readRemaining(ByteBuffer dst,
ByteBuffer src) |
String |
readString(int n) |
void |
setPos(long pos)
Optional operation.
|
void |
setPos(long page,
int index) |
void |
updateRelCache(long page)
Update relative min and max index for the given page,
taking one byte before and after the selected range into account
|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitbinarySearch, cloneObject, compareArrays, deltaPos, get, posToNext, sizeprotected PageManager pageManager
protected int pageSize
protected long page
protected int index
protected ByteBuffer pageBuffer
protected int displacement
protected long bufferForPage
protected int absMaxIndexInPage
protected int absMinIndexInPage
protected int relMinIndexInPage
protected int relMaxIndexInPage
protected long minPos
protected long minPage
protected int minIndex
protected long maxPos
protected long maxPage
protected int maxIndex
public PageNavigator(PageManager pageManager)
public PageNavigator(PageManager pageManager, long minPos, long maxPos)
pageManager - minPos - inclusivemaxPos - exclusivepublic PageNavigator clone()
public PageNavigator limitNext(long length)
length - public PageNavigator limitPrev(long length)
length - public long getPos()
Seekablepublic boolean isPosAfterEnd()
SeekableisPosAfterEnd in interface Seekablepublic boolean isPosBeforeStart()
SeekableisPosBeforeStart in interface Seekablepublic ByteBuffer getBufferForPage(long page) throws IOException
page - IOExceptionpublic void updateRelCache(long page)
page - public int getRelMaxIndex(long page)
public int getRelMinIndex(long page)
public ByteBuffer getBufferForPos(long pos) throws IOException
IOExceptionpublic long getPageForPos(long pos)
public int getIndexForPos(long pos)
public void posToStart()
SeekableposToStart in interface Seekablepublic void posToEnd()
Seekablepublic void setPos(long page,
int index)
public void setPos(long pos)
Seekablepublic long getMinPos()
public long getMaxPos()
public byte get()
throws IOException
get in interface SeekableIOExceptionpublic boolean canNextPos()
public boolean canPrevPos()
public int checkNext(int len,
boolean changePos)
throws IOException
SeekablecheckNext in interface SeekableIOExceptionpublic int checkPrev(int len,
boolean changePos)
throws IOException
checkPrev in interface SeekableIOExceptionpublic boolean nextPos(int delta)
throws IOException
nextPos in interface SeekableIOExceptionpublic boolean prevPos(int delta)
throws IOException
SeekableprevPos in interface SeekableIOExceptionpublic boolean posToNext(byte delimiter)
throws IOException
posToNext in interface Seekabledelimiter - IOExceptionpublic boolean posToPrev(byte delimiter)
throws IOException
SeekableposToPrev in interface SeekableIOExceptionpublic long getNextPosFor(byte delimiter)
throws IOException
delimiter - IOExceptionpublic long getPrevPosFor(byte delimiter)
throws IOException
IOExceptionpublic int compareToPrefix(byte[] prefix)
throws IOException
SeekablecompareToPrefix in interface SeekableIOExceptionpublic int peekNextBytes(byte[] dst,
int offset,
int len)
throws IOException
peekNextBytes in interface Seekablen - IOExceptionpublic String readLine() throws IOException
IOExceptionpublic String readString(int n) throws IOException
readString in interface SeekableIOExceptionpublic int read(ByteBuffer dst) throws IOException
read in interface ReadableByteChannelread in interface SeekableIOExceptionpublic static int readRemaining(ByteBuffer dst, ByteBuffer src)
public void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in interface Channelclose in interface SeekableIOExceptionCopyright © 2020. All rights reserved.