Github user markobean commented on a diff in the pull request: https://github.com/apache/nifi/pull/135#discussion_r50449323 --- Diff: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/SplitText.java --- @@ -198,23 +208,53 @@ private long countBytesToSplitPoint(final InputStream in, final OutputStream out return includeLineDelimiter ? bytesRead : bytesRead - 1; } - // keep track of what the last byte was that we read so that we can detect \r followed by some other + // keep track of what the last byte was that we read so that we can + // detect \r followed by some other // character. lastByte = nextByte; } } - private SplitInfo countBytesToSplitPoint(final InputStream in, final int numLines, final boolean keepAllNewLines) throws IOException { + private SplitInfo readHeader(final int numHeaderLines, + final String headerMarker, final InputStream in, + final OutputStream out, final boolean keepAllNewLines) + throws IOException { SplitInfo info = new SplitInfo(); - - while (info.lengthLines < numLines) { - final long bytesTillNext = countBytesToSplitPoint(in, null, keepAllNewLines || (info.lengthLines != numLines - 1)); - if (bytesTillNext <= 0L) { - break; + boolean isHeaderLine = true; + + // Read numHeaderLines from file, if specificed; a non-zero value takes precedence + // over headerMarker character string + if (numHeaderLines > 0) { + for (int i = 0; i < numHeaderLines; i++) { + int bytesRead = readLine(in, out, keepAllNewLines); + if (bytesRead == 0) { + break; + } + info.lengthBytes += bytesRead; + info.lengthLines++; + } + // Else, keep reading all lines that begin with headerMarker character string + } else if (headerMarker != null) { + while (true) { + in.mark(0); --- End diff -- This section of code is reading header lines a character at a time to determine if the line begins with the headerMarker character(s). After the line has been determined to be a header (or non-header), the buffer is reset so that a subsequent call to readLine() will capture all characters of the line. The maximum number of characters readHeader() will read before calling readLine() is the number of characters in the headerMarker String. Therefore, the in.mark(0) should be changed to in.mark(headerMarker.length).
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---