Class SeekableFromBlock
java.lang.Object
org.aksw.commons.util.closeable.AutoCloseableBase
org.aksw.commons.util.closeable.AutoCloseableWithLeakDetectionBase
org.aksw.commons.io.seekable.impl.SeekableFromBlock
- All Implemented Interfaces:
Closeable,AutoCloseable,Channel,ReadableByteChannel,Seekable
Segment could have predecessor / successor methods, but
how can we slice segments we request?
The use case is to scan backward until a condition is no longer satisfied,
maybe we don't need slicing then
- Author:
- raven
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected longprotected Blockprotected Seekableprotected longThe start position exposed - may be non-zero or even negative!protected longprotected longprotected intFields inherited from class org.aksw.commons.util.closeable.AutoCloseableWithLeakDetectionBase
instantiationStackTraceFields inherited from class org.aksw.commons.util.closeable.AutoCloseableBase
closeStackTrace, enableCloseStackTrace, isClosed -
Constructor Summary
ConstructorsConstructorDescriptionSeekableFromBlock(Ref<? extends Block> startBlockRef, int posInStartSegment, long exposedStartPos) SeekableFromBlock(Ref<? extends Block> startBlockRef, int posInStartSegment, long exposedStartPos, long minPos, long maxPos) The startBlockRef is considered to be owned by this object. -
Method Summary
Modifier and TypeMethodDescriptionintcheckNext(int len, boolean changePos) Attempt to advance the position by the given number of bytes.intcheckPrev(int len, boolean changePos) clone()voidintcompareToPrefix(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.byteget()Read a byte at the current positionlonggetPos()Optional operation.protected voidinit()booleanisOpen()booleanThe state of a seekable may be one unit beyond the end.booleanThe state of a seekable may be one unit before the start.protected booleanvoidposToEnd()Optional operation.intposToNext(byte delimiter, boolean changePos) positive: relative position issue: 0 means no position change, but it does not tell whether the current position is a match or not we could return a pair with +0 with current position matches and -0 current position does not match but no further bytes are availablevoidOptional operation.intread(ByteBuffer dst) intreadBroken(ByteBuffer dst) readString(int len) voidsetPos(long pos) Optional operation.Methods inherited from class org.aksw.commons.util.closeable.AutoCloseableWithLeakDetectionBase
finalize, getInstantiationStackTraceMethods inherited from class org.aksw.commons.util.closeable.AutoCloseableBase
close, ensureOpen, throwClosedExceptionMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.aksw.commons.io.seekable.api.Seekable
binarySearch, cloneObject, close, deltaPos, get, nextPos, peekNextBytes, posToNext, posToPrev, prevPos, size
-
Field Details
-
startBlockRef
-
startPosInStartSegment
protected int startPosInStartSegment -
exposedStartPos
protected long exposedStartPosThe start position exposed - may be non-zero or even negative! -
maxPos
protected long maxPos -
minPos
protected long minPos -
currentBlockRef
-
currentBlock
-
currentSeekable
-
actualPos
protected long actualPos
-
-
Constructor Details
-
SeekableFromBlock
-
SeekableFromBlock
public SeekableFromBlock(Ref<? extends Block> startBlockRef, int posInStartSegment, long exposedStartPos, long minPos, long maxPos) The startBlockRef is considered to be owned by this object. Closing this seekable also closes the reference.- Parameters:
startBlockRef-posInStartSegment-exposedStartPos-minPos-maxPos-
-
-
Method Details
-
init
protected void init() -
isOpen
public boolean isOpen() -
closeActual
- Overrides:
closeActualin classAutoCloseableBase- Throws:
Exception
-
clone
-
getPos
Description copied from interface:SeekableOptional operation. Get the position in this seekable- Specified by:
getPosin interfaceSeekable- Returns:
- Throws:
IOException
-
setPos
Description copied from interface:SeekableOptional operation. Get the position in this seekable- Specified by:
setPosin interfaceSeekable- Throws:
IOException
-
posToStart
Description copied from interface:SeekableOptional operation. Move one unit before the start of the seekable; raises an exception on infinite seekables- Specified by:
posToStartin interfaceSeekable- Throws:
IOException
-
posToEnd
Description copied from interface:SeekableOptional operation. Move to one unit beyond the end of the seekable; raises an exception on infinite seekables- Specified by:
posToEndin interfaceSeekable- Throws:
IOException
-
isPosBeforeStart
Description copied from interface:SeekableThe state of a seekable may be one unit before the start. In this state, if the seekable is non-empty, nextPos(1) must be a valid position- Specified by:
isPosBeforeStartin interfaceSeekable- Returns:
- Throws:
IOException
-
isPosAfterEnd
Description copied from interface:SeekableThe state of a seekable may be one unit beyond the end. In this state, if the seekable is non-empty, prevPos(1) must be a valid position- Specified by:
isPosAfterEndin interfaceSeekable- Returns:
- Throws:
IOException
-
loadNextBlock
- Throws:
IOException
-
posToNext
positive: relative position issue: 0 means no position change, but it does not tell whether the current position is a match or not we could return a pair with +0 with current position matches and -0 current position does not match but no further bytes are available- Specified by:
posToNextin interfaceSeekablechangePos- If no delimiter is found, move the pos to the end- Returns:
- Throws:
IOException
-
compareToPrefix
Description copied from interface:SeekableCompare 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. This default implementation uses read(ByteBuffer). Other implementations may override this behavior to compare the given prefix directly against their internal data structures without the intermediate buffer copy due to read.- Specified by:
compareToPrefixin interfaceSeekable- Returns:
- Throws:
IOException
-
checkNext
Description copied from interface:SeekableAttempt to advance the position by the given number of bytes. Return the number of bytes by which the position was changed. Returning less bytes than requested implies that a end position was reached which cannot be passed. This method cannot pass beyond the end - i.e. isPosAfterEnd cannot change from false to true by calling this method.- Specified by:
checkNextin interfaceSeekable- Returns:
- Throws:
IOException
-
checkPrev
- Specified by:
checkPrevin interfaceSeekable- Throws:
IOException
-
get
Description copied from interface:SeekableRead a byte at the current position- Specified by:
getin interfaceSeekable- Returns:
- The byte at the current position if the position is valid
- Throws:
IOException
-
read
- Specified by:
readin interfaceReadableByteChannel- Specified by:
readin interfaceSeekable- Throws:
IOException
-
readBroken
- Throws:
IOException
-
readString
- Specified by:
readStringin interfaceSeekable- Throws:
IOException
-