Class ReadableChannelWithLimitByDelimiter<A, X extends ReadableChannel<A>>
java.lang.Object
org.aksw.commons.util.closeable.AutoCloseableWrapperBase<X>
org.aksw.commons.io.shared.ChannelDecoratorBase<X>
org.aksw.commons.io.input.ReadableChannelDecoratorBase<A,X>
org.aksw.commons.io.input.ReadableChannelWithLimitByDelimiter<A,X>
- Type Parameters:
A-X-
- All Implemented Interfaces:
Closeable, AutoCloseable, Channel, HasArrayOps<A>, ReadableChannel<A>, ReadableSource<A>
public class ReadableChannelWithLimitByDelimiter<A, X extends ReadableChannel<A>>
extends ReadableChannelDecoratorBase<A,X>
Wrap a stream such that reading is cut off at the first delimiter (including it) after a certain position.
Typically used to limit the stream to the first newline after a split.
If the underlying channel's read method returns -2 it is interpreted as an end-of-block (EOB) marker.
This class limits the stream on the first delimiter after EOB.
This class hides any encountered block markers: Its read method either returns a positive non-zero integer for the number of bytes read
or -1 if either the final delimiter has been reached or the underlying channel has been consumed.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected longprotected byteprotected Aprotected GetPositionprotected booleanprotected booleanprotected longFields inherited from class AutoCloseableWrapperBase
delegate -
Constructor Summary
ConstructorsConstructorDescriptionReadableChannelWithLimitByDelimiter(X delegate, GetPosition getPosition, boolean isBlockMode, byte delimiter, long nextSplitOffset) -
Method Summary
Modifier and TypeMethodDescriptionlongintRead method following the usual InputStream protocol.Methods inherited from class ReadableChannelDecoratorBase
getArrayOpsMethods inherited from class ChannelDecoratorBase
close, isOpenMethods inherited from class AutoCloseableWrapperBase
close, getDelegateMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ReadableSource
readRaw
-
Field Details
-
nextSplitOffset
protected long nextSplitOffset -
delimiter
protected byte delimiter -
isInEofState
protected boolean isInEofState -
bytesRead
protected long bytesRead -
excessBuffer
-
getPosition
-
isBlockMode
protected boolean isBlockMode
-
-
Constructor Details
-
ReadableChannelWithLimitByDelimiter
public ReadableChannelWithLimitByDelimiter(X delegate, GetPosition getPosition, boolean isBlockMode, byte delimiter, long nextSplitOffset) - Parameters:
delegate-getPosition-isBlockMode- If true then expect block boundaries to be advertised with -2 results of reads.delimiter-nextSplitOffset-
-
-
Method Details
-
read
Description copied from interface:ReadableSourceRead method following the usual InputStream protocol.- Specified by:
readin interfaceReadableSource<A>- Overrides:
readin classReadableChannelDecoratorBase<A, X extends ReadableChannel<A>>- Parameters:
array- The array into which to put the read dataposition- Offset into array where to start writinglength- Maximum number of items to read.- Returns:
- The number of items read. Return -1 if end of data was reached, and 0 iff length was 0.
- Throws:
IOException
-
getBytesRead
public long getBytesRead()
-