Package org.apache.nifi.stream.io.util
Class TextLineDemarcator
java.lang.Object
org.apache.nifi.stream.io.util.AbstractDemarcator
org.apache.nifi.stream.io.util.TextLineDemarcator
- All Implemented Interfaces:
Closeable
,AutoCloseable
Implementation of demarcator of text lines in the provided
InputStream
. It works similar to the BufferedReader
and its
BufferedReader.readLine()
methods except that it does not create a
String representing the text line and instead returns the offset info for the
computed text line. See nextOffsetInfo()
and
nextOffsetInfo(byte[])
for more details.
NOTE: Not intended for multi-thread usage hence not Thread-safe.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Container to hold offset and meta info for a computed text line. -
Field Summary
Fields inherited from class org.apache.nifi.stream.io.util.AbstractDemarcator
availableBytesLength, buffer, index, INIT_BUFFER_SIZE, mark, offset
-
Constructor Summary
ConstructorDescriptionConstructs an instance of demarcator with providedInputStream
and default buffer size.TextLineDemarcator
(InputStream is, int initialBufferSize) Constructs an instance of demarcator with providedInputStream
and initial buffer size. -
Method Summary
Modifier and TypeMethodDescriptionWill compute the next offset info for a text line (line terminated by either '\r', '\n' or '\r\n').nextOffsetInfo
(byte[] startsWith) Will compute the next offset info for a text line (line terminated by either '\r', '\n' or '\r\n').Methods inherited from class org.apache.nifi.stream.io.util.AbstractDemarcator
close, extractDataToken, fill
-
Field Details
-
CR
private static int CR -
LF
private static int LF
-
-
Constructor Details
-
TextLineDemarcator
Constructs an instance of demarcator with providedInputStream
and default buffer size. -
TextLineDemarcator
Constructs an instance of demarcator with providedInputStream
and initial buffer size.
-
-
Method Details
-
nextOffsetInfo
Will compute the next offset info for a text line (line terminated by either '\r', '\n' or '\r\n').
The offset info computed and returned asTextLineDemarcator.OffsetInfo
whereTextLineDemarcator.OffsetInfo.isStartsWithMatch()
will always return true.- Returns:
- offset info
- Throws:
IOException
-
nextOffsetInfo
Will compute the next offset info for a text line (line terminated by either '\r', '\n' or '\r\n').
The offset info computed and returned asTextLineDemarcator.OffsetInfo
whereTextLineDemarcator.OffsetInfo.isStartsWithMatch()
will return true ifstartsWith
was successfully matched with the starting bytes of the text line. NOTE: The reason for 2 'nextOffsetInfo(..)' operations is that the 'startsWith' argument will force the actual token to be extracted and then matched introducing the overhead for System.arrayCopy and matching logic which is an optional scenario and is avoided all together if 'startsWith' is not provided (i.e., null).- Returns:
- offset info
- Throws:
IOException
-