You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by sz...@apache.org on 2024/01/16 12:33:26 UTC

(nifi-minifi-cpp) 01/05: MINIFICPP-62 Add SplitText processor

This is an automated email from the ASF dual-hosted git repository.

szaszm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi-minifi-cpp.git

commit 0c50cdad8207de4ed87bdc8bd2cf7a225ae23619
Author: Gabor Gyimesi <ga...@gmail.com>
AuthorDate: Tue Jan 16 13:21:03 2024 +0100

    MINIFICPP-62 Add SplitText processor
    
    Closes #1682
    
    Signed-off-by: Marton Szasz <sz...@apache.org>
---
 PROCESSORS.md                                      |  39 +
 README.md                                          |   2 +-
 docker/test/integration/features/splittext.feature |  42 +
 .../integration/minifi/processors/SplitText.py     |  24 +
 .../standard-processors/processors/SplitText.cpp   | 443 +++++++++++
 .../standard-processors/processors/SplitText.h     | 181 +++++
 .../tests/unit/SplitTextTests.cpp                  | 862 +++++++++++++++++++++
 libminifi/test/TestBase.cpp                        |   2 +-
 8 files changed, 1593 insertions(+), 2 deletions(-)

diff --git a/PROCESSORS.md b/PROCESSORS.md
index 41d927cdf..9f298a448 100644
--- a/PROCESSORS.md
+++ b/PROCESSORS.md
@@ -97,6 +97,7 @@ limitations under the License.
 - [RouteOnAttribute](#RouteOnAttribute)
 - [RouteText](#RouteText)
 - [SourceInitiatedSubscriptionListener](#SourceInitiatedSubscriptionListener)
+- [SplitText](#SplitText)
 - [TailEventLog](#TailEventLog)
 - [TailFile](#TailFile)
 - [UnfocusArchiveEntry](#UnfocusArchiveEntry)
@@ -2901,6 +2902,44 @@ In the list below, the names of required properties appear in bold. Any other pr
 | success | All files, containing log events, are routed to success |
 
 
+## SplitText
+
+### Description
+
+Splits a text file into multiple smaller text files on line boundaries limited by maximum number of lines or total size of fragment. Each output split file will contain no more than the configured number of lines or bytes. If both Line Split Count and Maximum Fragment Size are specified, the split occurs at whichever limit is reached first. If the first line of a fragment exceeds the Maximum Fragment Size, that line will be output in a single split file which exceeds the configured maxim [...]
+
+### Properties
+
+In the list below, the names of required properties appear in bold. Any other properties (not in bold) are considered optional. The table also indicates any default values, and whether a property supports the NiFi Expression Language.
+
+| Name                          | Default Value | Allowable Values | Description                                                                                                                                                                                                                                                                                                                                                                                                                             [...]
+|-------------------------------|---------------|------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- [...]
+| **Line Split Count**          |               |                  | The number of lines that will be added to each split file, excluding header lines. A value of zero requires Maximum Fragment Size to be set, and line count will not be considered in determining splits.                                                                                                                                                                                                                               [...]
+| Maximum Fragment Size         |               |                  | The maximum size of each split file, including header lines. NOTE: in the case where a single line exceeds this property (including headers, if applicable), that line will be output in a split of its own which exceeds this Maximum Fragment Size setting.                                                                                                                                                                           [...]
+| **Header Line Count**         | 0             |                  | The number of lines that should be considered part of the header; the header lines will be duplicated to all split files.                                                                                                                                                                                                                                                                                                               [...]
+| Header Line Marker Characters |               |                  | The first character(s) on the line of the datafile which signifies a header line. This value is ignored when Header Line Count is non-zero. The first line not containing the Header Line Marker Characters and all subsequent lines are considered non-header                                                                                                                                                                          [...]
+| **Remove Trailing Newlines**  | true          | true<br/>false   | Whether to remove newlines at the end of each split file. This should be false if you intend to merge the split files later. If this is set to 'true' and a FlowFile is generated that contains only 'empty lines' (i.e., consists only of \r and \n characters), the FlowFile will not be emitted. Note, however, that if header lines are specified, the resultant FlowFile will never be empty as it will consist of the header line [...]
+
+### Relationships
+
+| Name     | Description                                                                                                                          |
+|----------|--------------------------------------------------------------------------------------------------------------------------------------|
+| failure  | If a file cannot be split for some reason, the original file will be routed to this destination and nothing will be routed elsewhere |
+| original | The original input file will be routed to this destination when it has been successfully split into 1 or more files                  |
+| splits   | The split files will be routed to this destination when an input file is successfully split into 1 or more split files               |
+
+### Output Attributes
+
+| Attribute                 | Relationship | Description                                                                                                                                                   |
+|---------------------------|--------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------|
+| text.line.count           |              | The number of lines of text from the original FlowFile that were copied to this FlowFile (does not count empty lines)                                         |
+| fragment.size             |              | The number of bytes from the original FlowFile that were copied to this FlowFile, including header, if applicable, which is duplicated in each split FlowFile |
+| fragment.identifier       |              | All split FlowFiles produced from the same parent FlowFile will have the same randomly generated UUID added for this attribute                                |
+| fragment.index            |              | A one-up number that indicates the ordering of the split FlowFiles that were created from a single parent FlowFile                                            |
+| fragment.count            |              | The number of split FlowFiles generated from the parent FlowFile                                                                                              |
+| segment.original.filename |              | The filename of the parent FlowFile                                                                                                                           |
+
+
 ## TailFile
 
 ### Description
diff --git a/README.md b/README.md
index f4eae4f88..1fa182637 100644
--- a/README.md
+++ b/README.md
@@ -65,7 +65,7 @@ The following table lists the base set of processors.
 
 | Extension Set | Processors                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 [...]
 |---------------|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ [...]
-| **Base**      | [AppendHostInfo](PROCESSORS.md#appendhostinfo)<br/>[AttributesToJSON](PROCESSORS.md#attributestojson)<br/>[DefragmentText](PROCESSORS.md#defragmenttext)<br/>[ExecuteProcess](PROCESSORS.md#executeprocess)<br/>[ExtractText](PROCESSORS.md#extracttext)<br/>[FetchFile](PROCESSORS.md#fetchfile)<br/>[GenerateFlowFile](PROCESSORS.md#generateflowfile)<br/>[GetFile](PROCESSORS.md#getfile)<br/>[GetTCP](PROCESSORS.md#gettcp)<br/>[HashContent](PROCESSORS.md#hashcontent)<br/>[ListenS [...]
+| **Base**      | [AppendHostInfo](PROCESSORS.md#appendhostinfo)<br/>[AttributesToJSON](PROCESSORS.md#attributestojson)<br/>[DefragmentText](PROCESSORS.md#defragmenttext)<br/>[ExecuteProcess](PROCESSORS.md#executeprocess)<br/>[ExtractText](PROCESSORS.md#extracttext)<br/>[FetchFile](PROCESSORS.md#fetchfile)<br/>[GenerateFlowFile](PROCESSORS.md#generateflowfile)<br/>[GetFile](PROCESSORS.md#getfile)<br/>[GetTCP](PROCESSORS.md#gettcp)<br/>[HashContent](PROCESSORS.md#hashcontent)<br/>[ListenS [...]
 
 The next table outlines CMAKE flags that correspond with MiNiFi extensions. Extensions that are enabled by default ( such as CURL ), can be disabled with the respective CMAKE flag on the command line.
 
diff --git a/docker/test/integration/features/splittext.feature b/docker/test/integration/features/splittext.feature
new file mode 100644
index 000000000..4de8b26b9
--- /dev/null
+++ b/docker/test/integration/features/splittext.feature
@@ -0,0 +1,42 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+@CORE
+Feature: Split input text line-by-line using SplitText
+  Background:
+    Given the content of "/tmp/output" is monitored
+
+  Scenario: Split textfile containing header lines specified by line count
+    Given a GetFile processor with the "Input Directory" property set to "/tmp/input"
+    And a file with filename "test_file.log" and content "[HEADER]header line 1\n[HEADER]header line 2\nDATA LINE 1\nDATA LINE 2\n\n" is present in "/tmp/input"
+    And a SplitText processor with the "Line Split Count" property set to "1"
+    And the "Header Line Count" property of the SplitText processor is set to "2"
+    And a PutFile processor with the "Directory" property set to "/tmp/output"
+    And the "success" relationship of the GetFile processor is connected to the SplitText
+    And the "splits" relationship of the SplitText processor is connected to the PutFile
+    When the MiNiFi instance starts up
+    Then flowfiles with these contents are placed in the monitored directory in less than 15 seconds: "[HEADER]header line 1\n[HEADER]header line 2\nDATA LINE 1,[HEADER]header line 1\n[HEADER]header line 2\nDATA LINE 2,[HEADER]header line 1\n[HEADER]header line 2"
+
+  Scenario: Split textfile containing header lines specified by header line marker characters
+    Given a GetFile processor with the "Input Directory" property set to "/tmp/input"
+    And a file with filename "test_file.log" and content "[HEADER]header line 1\n[HEADER]header line 2\nA BIT LONGER DATA LINE 1\nDATA 2\nDATA 3\n\n" is present in "/tmp/input"
+    And a SplitText processor with the "Line Split Count" property set to "3"
+    And the "Maximum Fragment Size" property of the SplitText processor is set to "60 B"
+    And the "Header Line Marker Characters" property of the SplitText processor is set to "[HEADER]"
+    And a PutFile processor with the "Directory" property set to "/tmp/output"
+    And the "success" relationship of the GetFile processor is connected to the SplitText
+    And the "splits" relationship of the SplitText processor is connected to the PutFile
+    When the MiNiFi instance starts up
+    Then flowfiles with these contents are placed in the monitored directory in less than 30 seconds: "[HEADER]header line 1\n[HEADER]header line 2\nA BIT LONGER DATA LINE 1,[HEADER]header line 1\n[HEADER]header line 2\nDATA 2\nDATA 3"
diff --git a/docker/test/integration/minifi/processors/SplitText.py b/docker/test/integration/minifi/processors/SplitText.py
new file mode 100644
index 000000000..e8298f3ab
--- /dev/null
+++ b/docker/test/integration/minifi/processors/SplitText.py
@@ -0,0 +1,24 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+from ..core.Processor import Processor
+
+
+class SplitText(Processor):
+    def __init__(self, context, schedule={'scheduling strategy': 'EVENT_DRIVEN'}):
+        super(SplitText, self).__init__(
+            context=context,
+            clazz='SplitText',
+            schedule=schedule,
+            auto_terminate=['original', "splits", "failure"])
diff --git a/extensions/standard-processors/processors/SplitText.cpp b/extensions/standard-processors/processors/SplitText.cpp
new file mode 100644
index 000000000..aacbfbfa0
--- /dev/null
+++ b/extensions/standard-processors/processors/SplitText.cpp
@@ -0,0 +1,443 @@
+/**
+ * @file SplitText.cpp
+ * SplitText class implementation
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <algorithm>
+
+#include "SplitText.h"
+#include "core/ProcessContext.h"
+#include "core/ProcessSession.h"
+#include "core/Resource.h"
+#include "core/FlowFile.h"
+#include "utils/gsl.h"
+#include "utils/ProcessorConfigUtils.h"
+
+namespace org::apache::nifi::minifi::processors {
+
+namespace detail {
+
+LineReader::LineReader(const std::shared_ptr<io::InputStream>& stream)
+    : stream_(stream) {
+  if (!stream_ || stream_->size() == 0) {
+    state_ = StreamReadState::EndOfStream;
+  }
+}
+
+uint8_t LineReader::getEndLineSize(size_t newline_position) {
+  gsl_Expects(buffer_.size() > newline_position);
+  if (buffer_[newline_position] != '\n') {
+    return 0;
+  }
+  if (newline_position == 0 || buffer_[newline_position - 1] != '\r') {
+    return 1;
+  }
+  return 2;
+}
+
+void LineReader::setLastLineInfoAttributes(uint8_t endline_size, const std::optional<std::string>& starts_with) {
+  const uint64_t size_from_beginning_of_stream = (current_buffer_count_ - 1) * SPLIT_TEXT_BUFFER_SIZE + buffer_offset_;
+  if (last_line_info_) {
+    LineInfo previous_line_info = *last_line_info_;
+    last_line_info_->offset = previous_line_info.offset + previous_line_info.size;
+    last_line_info_->size = size_from_beginning_of_stream - previous_line_info.offset - previous_line_info.size;
+    last_line_info_->endline_size = endline_size;
+    last_line_info_->matches_starts_with = true;
+  } else {
+    last_line_info_ = LineInfo{.offset = 0, .size = read_size_ - last_read_size_ + buffer_offset_, .endline_size = endline_size, .matches_starts_with = true};
+  }
+
+  if (starts_with) {
+    last_line_info_->matches_starts_with = last_line_info_->size >= starts_with->size() &&
+      std::equal(starts_with->begin(), starts_with->end(), buffer_.begin() + last_line_info_->offset, buffer_.begin() + last_line_info_->offset + starts_with->size());
+  }
+}
+
+bool LineReader::readNextBuffer() {
+  buffer_offset_ = 0;
+  last_read_size_ = (std::min)(gsl::narrow<size_t>(stream_->size() - read_size_), SPLIT_TEXT_BUFFER_SIZE);
+  const auto read_ret = stream_->read(as_writable_bytes(std::span(buffer_).subspan(0, last_read_size_)));
+  if (io::isError(read_ret)) {
+    state_ = StreamReadState::StreamReadError;
+    return false;
+  }
+  read_size_ += read_ret;
+  ++current_buffer_count_;
+  return true;
+}
+
+std::optional<LineReader::LineInfo> LineReader::finalizeLineInfo(uint8_t endline_size, const std::optional<std::string>& starts_with) {
+  setLastLineInfoAttributes(endline_size, starts_with);
+  if (last_line_info_->size == 0) {
+    return std::nullopt;
+  }
+  return last_line_info_;
+}
+
+std::optional<LineReader::LineInfo> LineReader::readNextLine(const std::optional<std::string>& starts_with) {
+  if (state_ != StreamReadState::Ok) {
+    return std::nullopt;
+  }
+
+  const auto isLastReadProcessed = [this]() { return last_read_size_ <= buffer_offset_; };
+  while (read_size_ < stream_->size() || !isLastReadProcessed()) {
+    if (isLastReadProcessed() && !readNextBuffer()) {
+      return std::nullopt;
+    }
+
+    auto endline_pos = std::find_if(buffer_.begin() + buffer_offset_, buffer_.begin() + last_read_size_, [](const auto& buffer_element) { return buffer_element == '\n'; });
+    if (endline_pos != buffer_.begin() + last_read_size_) {
+      const auto line_length = std::distance(buffer_.begin(), endline_pos);
+      buffer_offset_ = line_length + 1;
+      return finalizeLineInfo(getEndLineSize(line_length), starts_with);
+    } else {
+      buffer_offset_ = last_read_size_;
+    }
+  }
+
+  state_ = StreamReadState::EndOfStream;
+  return finalizeLineInfo(0, starts_with);
+}
+
+}  // namespace detail
+
+namespace {
+
+class SplitTextFragmentGenerator {
+ public:
+  struct Fragment {
+    uint64_t text_line_count = 0;
+    uint64_t processed_line_count = 0;
+    uint64_t fragment_size = 0;
+    uint64_t fragment_offset = 0;
+    uint8_t endline_size = 0;
+  };
+
+  SplitTextFragmentGenerator(const std::shared_ptr<io::InputStream>& stream, const SplitTextConfiguration& split_text_config);
+  std::optional<Fragment> readNextFragment();
+  nonstd::expected<Fragment, const char*> readHeaderFragment();
+  [[nodiscard]] detail::StreamReadState getState() const { return line_reader_.getState(); }
+
+ private:
+  static void addLineToFragment(Fragment& fragment, const detail::LineReader::LineInfo& line);
+  void finalizeFragmentOffset(Fragment& current_fragment);
+  [[nodiscard]] bool lineSizeWouldExceedMaxFragmentSize(const detail::LineReader::LineInfo& line, uint64_t fragment_size) const;
+  nonstd::expected<Fragment, const char*> createHeaderFragmentUsingLineCount();
+  nonstd::expected<Fragment, const char*> createHeaderFragmentUsingHeaderMarkerCharacters();
+
+  detail::LineReader line_reader_;
+  // In case the read line would exceed the maximum fragment size, we need to buffer it for the next fragment
+  std::optional<detail::LineReader::LineInfo> buffered_line_info_;
+  uint64_t flow_file_offset_ = 0;
+  const SplitTextConfiguration& split_text_config_;
+  uint64_t header_fragment_size_ = 0;
+};
+
+class ReadCallback {
+ public:
+  ReadCallback(std::shared_ptr<core::FlowFile> flow_file, const SplitTextConfiguration& split_text_config,
+    core::ProcessSession& session, std::shared_ptr<core::logging::Logger> logger);
+  int64_t operator()(const std::shared_ptr<io::InputStream>& stream);
+  std::optional<const char*> error;
+  std::vector<std::shared_ptr<org::apache::nifi::minifi::core::FlowFile>> results;
+
+ private:
+  void setAttributesOfDoneSegment(core::FlowFile& current_flow_file, uint64_t line_count);
+  void createHeaderOnlyFragmentFlow(const SplitTextFragmentGenerator::Fragment& header_fragment);
+  void mergeHeaderAndFragmentFlows(const std::shared_ptr<core::FlowFile>& header_flow, const SplitTextFragmentGenerator::Fragment& fragment, size_t fragment_trim_size);
+  void createFragmentFlowWithoutHeader(const SplitTextFragmentGenerator::Fragment& fragment, size_t fragment_trim_size);
+
+  std::shared_ptr<io::InputStream> stream_;
+  std::shared_ptr<core::FlowFile> flow_file_;
+  const SplitTextConfiguration& split_text_config_;
+  core::ProcessSession& session_;
+  size_t emitted_fragment_index_ = 1;
+  const std::string fragment_identifier_ = utils::IdGenerator::getIdGenerator()->generate().to_string();
+  std::shared_ptr<core::logging::Logger> logger_;
+};
+
+SplitTextFragmentGenerator::SplitTextFragmentGenerator(const std::shared_ptr<io::InputStream>& stream, const SplitTextConfiguration& split_text_config)
+    : line_reader_(stream),
+      split_text_config_(split_text_config) {
+}
+
+void SplitTextFragmentGenerator::finalizeFragmentOffset(Fragment& current_fragment) {
+  current_fragment.fragment_offset = flow_file_offset_;
+  flow_file_offset_ += current_fragment.fragment_size;
+}
+
+void SplitTextFragmentGenerator::addLineToFragment(Fragment& current_fragment, const detail::LineReader::LineInfo& line) {
+  if (line.endline_size == line.size) {  // if line consists only of endline characters, we need to append the fragment trim size
+    current_fragment.endline_size += line.endline_size;
+  } else {
+    current_fragment.endline_size = line.endline_size;
+  }
+  current_fragment.text_line_count += line.endline_size == line.size ? 0 : 1;
+  current_fragment.fragment_size += line.size;
+}
+
+bool SplitTextFragmentGenerator::lineSizeWouldExceedMaxFragmentSize(const detail::LineReader::LineInfo& line, uint64_t fragment_size) const {
+  return split_text_config_.maximum_fragment_size && fragment_size + line.size + header_fragment_size_ > split_text_config_.maximum_fragment_size.value();
+}
+
+nonstd::expected<SplitTextFragmentGenerator::Fragment, const char*> SplitTextFragmentGenerator::createHeaderFragmentUsingLineCount() {
+  Fragment header_fragment;
+  for (uint64_t i = 0; i < split_text_config_.header_line_count; ++i) {
+    auto line = line_reader_.readNextLine();
+    if (!line) {
+      if (getState() == detail::StreamReadState::EndOfStream) {
+        return nonstd::make_unexpected("The flow file's line count is less than the specified header line count!");
+      } else {
+        return nonstd::make_unexpected("Error while reading flow file stream!");
+      }
+    }
+    if (lineSizeWouldExceedMaxFragmentSize(*line, header_fragment.fragment_size)) {
+      return nonstd::make_unexpected("Header line would exceed the maximum fragment size!");
+    }
+
+    addLineToFragment(header_fragment, *line);
+  }
+
+  flow_file_offset_ += header_fragment.fragment_size;
+  header_fragment_size_ = header_fragment.fragment_size;
+  return header_fragment;
+}
+
+nonstd::expected<SplitTextFragmentGenerator::Fragment, const char*> SplitTextFragmentGenerator::createHeaderFragmentUsingHeaderMarkerCharacters() {
+  Fragment header_fragment;
+  while (auto line = line_reader_.readNextLine(split_text_config_.header_line_marker_characters)) {
+    if (line->size < split_text_config_.header_line_marker_characters->size() || !line->matches_starts_with) {
+      buffered_line_info_ = line;
+      break;
+    }
+    if (lineSizeWouldExceedMaxFragmentSize(*line, header_fragment.fragment_size)) {
+      return nonstd::make_unexpected("Header line would exceed the maximum fragment size!");
+    }
+
+    addLineToFragment(header_fragment, *line);
+  }
+
+  flow_file_offset_ += header_fragment.fragment_size;
+  header_fragment_size_ = header_fragment.fragment_size;
+  return header_fragment;
+}
+
+nonstd::expected<SplitTextFragmentGenerator::Fragment, const char*> SplitTextFragmentGenerator::readHeaderFragment() {
+  gsl_Expects(flow_file_offset_ == 0 && (split_text_config_.header_line_count > 0 || split_text_config_.header_line_marker_characters));
+  if (split_text_config_.header_line_count > 0) {
+    return createHeaderFragmentUsingLineCount();
+  }
+
+  return createHeaderFragmentUsingHeaderMarkerCharacters();
+}
+
+std::optional<SplitTextFragmentGenerator::Fragment> SplitTextFragmentGenerator::readNextFragment() {
+  Fragment current_fragment;
+  while (auto line = buffered_line_info_ ? buffered_line_info_ : line_reader_.readNextLine()) {
+    buffered_line_info_.reset();
+    if (lineSizeWouldExceedMaxFragmentSize(*line, current_fragment.fragment_size)) {
+      if (current_fragment.processed_line_count == 0) {  // first fragment line would be bigger than maximum fragment size (we don't have any other line in the fragment yet)
+        addLineToFragment(current_fragment, *line);
+      } else {
+        buffered_line_info_ = line;
+      }
+
+      finalizeFragmentOffset(current_fragment);
+      return current_fragment;
+    }
+
+    ++current_fragment.processed_line_count;
+    addLineToFragment(current_fragment, *line);
+    if (split_text_config_.line_split_count == current_fragment.processed_line_count) {
+      finalizeFragmentOffset(current_fragment);
+      return current_fragment;
+    }
+  }
+
+  if (current_fragment.fragment_size > 0) {
+    finalizeFragmentOffset(current_fragment);
+    return current_fragment;
+  }
+  return std::nullopt;
+}
+
+ReadCallback::ReadCallback(std::shared_ptr<core::FlowFile> flow_file, const SplitTextConfiguration& split_text_config,
+  core::ProcessSession& session,  std::shared_ptr<core::logging::Logger> logger)
+    : flow_file_(std::move(flow_file)),
+      split_text_config_(split_text_config),
+      session_(session),
+      logger_(std::move(logger)) {
+}
+
+void ReadCallback::setAttributesOfDoneSegment(core::FlowFile& current_flow_file, uint64_t line_count) {
+  const std::string original_filename_or_uuid = flow_file_->getAttribute(core::SpecialFlowAttribute::FILENAME).value_or(flow_file_->getUUIDStr());
+  current_flow_file.setAttribute(core::SpecialFlowAttribute::FILENAME, original_filename_or_uuid + ".fragment." + fragment_identifier_ + "." + std::to_string(emitted_fragment_index_));
+  current_flow_file.setAttribute(SplitText::TextLineCountOutputAttribute.name, std::to_string(line_count));
+  current_flow_file.setAttribute(SplitText::FragmentSizeOutputAttribute.name, std::to_string(current_flow_file.getSize()));
+  current_flow_file.setAttribute(SplitText::FragmentIdentifierOutputAttribute.name, fragment_identifier_);
+  current_flow_file.setAttribute(SplitText::FragmentIndexOutputAttribute.name, std::to_string(emitted_fragment_index_));
+  current_flow_file.setAttribute(SplitText::SegmentOriginalFilenameOutputAttribute.name, flow_file_->getAttribute(core::SpecialFlowAttribute::FILENAME).value_or(""));
+  ++emitted_fragment_index_;
+}
+
+void ReadCallback::createHeaderOnlyFragmentFlow(const SplitTextFragmentGenerator::Fragment& header_fragment) {
+  gsl_Expects(split_text_config_.remove_trailing_new_lines);  // This is only possible if the split fragment has no content and the endlines are trimmed
+  auto header_only_flow = session_.clone(flow_file_, gsl::narrow<int64_t>(header_fragment.fragment_offset), gsl::narrow<int64_t>(header_fragment.fragment_size - header_fragment.endline_size));
+  if (!header_only_flow) {
+    logger_->log_error("Failed to clone header only fragment flow!");
+    return;
+  }
+  logger_->log_debug("Creating a header only fragment with fragment index: {} fragment size: {}", emitted_fragment_index_, header_only_flow->getSize());
+  setAttributesOfDoneSegment(*header_only_flow, 0);
+  results.push_back(header_only_flow);
+}
+
+void ReadCallback::mergeHeaderAndFragmentFlows(const std::shared_ptr<core::FlowFile>& header_flow, const SplitTextFragmentGenerator::Fragment& fragment, size_t fragment_trim_size) {
+  auto fragment_flow = session_.clone(flow_file_, gsl::narrow<int64_t>(fragment.fragment_offset), gsl::narrow<int64_t>(fragment.fragment_size - fragment_trim_size));
+  if (!fragment_flow) {
+    logger_->log_error("Failed to clone fragment flow!");
+    return;
+  }
+  auto merged_flow = session_.clone(header_flow);  // clone header to copy attributes
+  if (!merged_flow) {
+    logger_->log_error("Failed to clone merged fragment flow!");
+    return;
+  }
+  session_.write(merged_flow, [this, &fragment_flow, &header_flow](const std::shared_ptr<io::OutputStream>& output_stream) -> int64_t {
+    auto header_write_result = session_.read(header_flow, [&output_stream](const std::shared_ptr<io::InputStream>& header_input_stream) -> int64_t {
+      return internal::pipe(*header_input_stream, *output_stream);
+    });
+    if (header_write_result < 0) {
+      logger_->log_error("Failed to write header to fragment!");
+      return header_write_result;
+    }
+    return session_.read(fragment_flow, [&output_stream](const std::shared_ptr<io::InputStream>& fragment_input_stream) -> int64_t {
+      return internal::pipe(*fragment_input_stream, *output_stream);
+    });
+  });
+  logger_->log_debug("Creating fragment with header with fragment index: {} fragment size: {}", emitted_fragment_index_, merged_flow->getSize());
+  setAttributesOfDoneSegment(*merged_flow, fragment.text_line_count);
+  results.push_back(merged_flow);
+  session_.remove(fragment_flow);
+}
+
+void ReadCallback::createFragmentFlowWithoutHeader(const SplitTextFragmentGenerator::Fragment& fragment, size_t fragment_trim_size) {
+  auto fragment_flow = session_.clone(flow_file_, gsl::narrow<int64_t>(fragment.fragment_offset), gsl::narrow<int64_t>(fragment.fragment_size - fragment_trim_size));
+  if (!fragment_flow) {
+    logger_->log_error("Failed to clone fragment flow without header!");
+    return;
+  }
+  logger_->log_debug("Creating fragment with header with fragment index: {} fragment size: {}", emitted_fragment_index_, fragment_flow->getSize());
+  setAttributesOfDoneSegment(*fragment_flow, fragment.text_line_count);
+  results.push_back(fragment_flow);
+}
+
+int64_t ReadCallback::operator()(const std::shared_ptr<io::InputStream>& stream) {
+  SplitTextFragmentGenerator fragment_generator(stream, split_text_config_);
+  nonstd::expected<SplitTextFragmentGenerator::Fragment, const char*> header_fragment;
+  std::shared_ptr<core::FlowFile> header_flow;  // cache header flow file to avoid cloning it for each fragment
+  if (split_text_config_.header_line_count > 0 || split_text_config_.header_line_marker_characters) {
+    header_fragment = fragment_generator.readHeaderFragment();
+    if (!header_fragment) {
+      error = header_fragment.error();
+      return gsl::narrow<int64_t>(flow_file_->getSize());
+    }
+    header_flow = session_.clone(flow_file_, gsl::narrow<int64_t>(header_fragment->fragment_offset), gsl::narrow<int64_t>(header_fragment->fragment_size));
+    if (!header_flow) {
+      logger_->log_error("Failed to clone header flow!");
+      return -1;
+    }
+  }
+
+  while (auto fragment = fragment_generator.readNextFragment()) {
+    size_t fragment_trim_size = split_text_config_.remove_trailing_new_lines ? fragment->endline_size : 0;
+    if (header_flow) {
+      if (fragment->fragment_size - fragment_trim_size == 0) {
+        createHeaderOnlyFragmentFlow(*header_fragment);
+      } else {
+        mergeHeaderAndFragmentFlows(header_flow, *fragment, fragment_trim_size);
+      }
+    } else if (fragment->fragment_size - fragment_trim_size != 0) {
+      createFragmentFlowWithoutHeader(*fragment, fragment_trim_size);
+    }
+  }
+  if (header_flow) {
+    session_.remove(header_flow);
+  }
+  return fragment_generator.getState() == detail::StreamReadState::EndOfStream ? gsl::narrow<int64_t>(flow_file_->getSize()) : -1;
+}
+
+}  // namespace
+
+void SplitText::initialize() {
+  setSupportedProperties(Properties);
+  setSupportedRelationships(Relationships);
+}
+
+void SplitText::onSchedule(core::ProcessContext& context, core::ProcessSessionFactory& /*sessionFactory*/) {
+  split_text_config_.line_split_count = utils::getRequiredPropertyOrThrow<uint64_t>(context, LineSplitCount.name);
+  logger_->log_debug("SplitText line split count: {}", split_text_config_.line_split_count);
+  auto max_fragment_data_size_value = context.getProperty<core::DataSizeValue>(MaximumFragmentSize);
+  if (max_fragment_data_size_value) {
+    split_text_config_.maximum_fragment_size = max_fragment_data_size_value->getValue();
+    logger_->log_debug("SplitText maximum fragment size: {}", split_text_config_.maximum_fragment_size.value());
+  }
+  if (split_text_config_.maximum_fragment_size && split_text_config_.maximum_fragment_size.value() == 0) {
+    throw Exception(PROCESS_SCHEDULE_EXCEPTION, "Maximum Fragment Size cannot be 0!");
+  }
+  if (split_text_config_.line_split_count == 0 && !split_text_config_.maximum_fragment_size) {
+    throw Exception(PROCESS_SCHEDULE_EXCEPTION, "Line Split Count is set to 0, but Maximum Fragment Size is not set!");
+  }
+  split_text_config_.header_line_count = utils::getRequiredPropertyOrThrow<uint64_t>(context, HeaderLineCount.name);
+  logger_->log_debug("SplitText header line count: {}", split_text_config_.header_line_count);
+  split_text_config_.header_line_marker_characters = context.getProperty(HeaderLineMarkerCharacters);
+  if (split_text_config_.header_line_marker_characters && split_text_config_.header_line_marker_characters->size() >= detail::SPLIT_TEXT_BUFFER_SIZE) {
+    throw Exception(PROCESS_SCHEDULE_EXCEPTION, fmt::format("SplitText header line marker characters length is larger than the maximum allowed: {} > {}",
+      split_text_config_.header_line_marker_characters->size(), detail::SPLIT_TEXT_BUFFER_SIZE - 1));
+  }
+  if (split_text_config_.header_line_marker_characters) {
+    logger_->log_debug("SplitText header line marker characters were set: {}", *split_text_config_.header_line_marker_characters);
+  }
+  split_text_config_.remove_trailing_new_lines = utils::getRequiredPropertyOrThrow<bool>(context, RemoveTrailingNewlines.name);
+  logger_->log_debug("SplitText should remove trailing new lines: {}", split_text_config_.remove_trailing_new_lines);
+}
+
+void SplitText::onTrigger(core::ProcessContext& context, core::ProcessSession& session) {
+  std::shared_ptr<core::FlowFile> flow_file = session.get();
+  if (!flow_file) {
+    context.yield();
+    return;
+  }
+
+  ReadCallback callback{flow_file, split_text_config_, session, logger_};
+  session.read(flow_file, std::ref(callback));
+  if (callback.error) {
+    logger_->log_error("Splitting flow file failed with error: {}", *callback.error);
+    session.transfer(flow_file, Failure);
+  } else {
+    logger_->log_info("Splitting flow file '{}' (id: {}) resulted in {} fragments", flow_file->getName(), flow_file->getUUIDStr(), callback.results.size());
+    for (const auto& res : callback.results) {
+      res->setAttribute(SplitText::FragmentCountOutputAttribute.name, std::to_string(callback.results.size()));
+      session.transfer(res, Splits);
+    }
+    session.transfer(flow_file, Original);
+  }
+}
+
+REGISTER_RESOURCE(SplitText, Processor);
+
+}  // namespace org::apache::nifi::minifi::processors
diff --git a/extensions/standard-processors/processors/SplitText.h b/extensions/standard-processors/processors/SplitText.h
new file mode 100644
index 000000000..02b2215a4
--- /dev/null
+++ b/extensions/standard-processors/processors/SplitText.h
@@ -0,0 +1,181 @@
+/**
+ * @file SplitText.h
+ * SplitText class declaration
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+
+#include <memory>
+#include <string_view>
+#include <utility>
+#include <optional>
+
+#include "core/Processor.h"
+#include "core/ProcessSession.h"
+#include "core/PropertyDefinitionBuilder.h"
+#include "core/PropertyDefinition.h"
+#include "core/PropertyType.h"
+#include "core/RelationshipDefinition.h"
+#include "FlowFileRecord.h"
+#include "utils/Export.h"
+#include "utils/expected.h"
+
+namespace org::apache::nifi::minifi::processors {
+
+struct SplitTextConfiguration {
+  uint64_t line_split_count = 0;
+  std::optional<uint64_t> maximum_fragment_size;
+  uint64_t header_line_count = 0;
+  std::optional<std::string> header_line_marker_characters;
+  bool remove_trailing_new_lines = true;
+};
+
+namespace detail {
+
+inline constexpr size_t SPLIT_TEXT_BUFFER_SIZE = 8192;
+
+enum class StreamReadState {
+  Ok,
+  StreamReadError,
+  EndOfStream
+};
+
+class LineReader {
+ public:
+  struct LineInfo {
+    uint64_t offset = 0;
+    uint64_t size = 0;  // size of the line including endline characters
+    uint8_t endline_size = 0;  // number of characters used in the endline
+    bool matches_starts_with = true;  // marks whether the line matches the starts_with filter of the readNextLine method (used in SplitText when Header Line Marker Characters is specified)
+
+    bool operator==(const LineInfo& line_info) const = default;
+  };
+
+  explicit LineReader(const std::shared_ptr<io::InputStream>& stream);
+  std::optional<LineInfo> readNextLine(const std::optional<std::string>& starts_with = std::nullopt);
+  StreamReadState getState() const { return state_; }
+
+ private:
+  uint8_t getEndLineSize(size_t newline_position);
+  void setLastLineInfoAttributes(uint8_t endline_size, const std::optional<std::string>& starts_with);
+  bool readNextBuffer();
+  std::optional<LineReader::LineInfo> finalizeLineInfo(uint8_t endline_size, const std::optional<std::string>& starts_with);
+
+  size_t buffer_offset_ = 0;
+  uint64_t current_buffer_count_ = 0;
+  size_t last_read_size_ = 0;
+  uint64_t read_size_ = 0;
+  std::array<char, SPLIT_TEXT_BUFFER_SIZE> buffer_{};
+  std::shared_ptr<io::InputStream> stream_;
+  std::optional<LineInfo> last_line_info_;
+  StreamReadState state_ = StreamReadState::Ok;
+};
+
+}  // namespace detail
+
+class SplitText : public core::Processor {
+ public:
+  explicit SplitText(std::string_view name,  const utils::Identifier& uuid = {})
+      : Processor(name, uuid) {
+  }
+
+  EXTENSIONAPI static constexpr const char* Description = "Splits a text file into multiple smaller text files on line boundaries limited by maximum number of lines or total size of fragment. "
+    "Each output split file will contain no more than the configured number of lines or bytes. If both Line Split Count and Maximum Fragment Size are specified, the split occurs at whichever "
+    "limit is reached first. If the first line of a fragment exceeds the Maximum Fragment Size, that line will be output in a single split file which exceeds the configured maximum size limit. "
+    "This component also allows one to specify that each split should include a header lines. Header lines can be computed by either specifying the amount of lines that should constitute a header "
+    "or by using header marker to match against the read lines. If such match happens then the corresponding line will be treated as header. Keep in mind that upon the first failure of header "
+    "marker match, no more matches will be performed and the rest of the data will be parsed as regular lines for a given split. If after computation of the header there are no more data, "
+    "the resulting split will consists of only header lines.";
+
+  EXTENSIONAPI static constexpr auto LineSplitCount = core::PropertyDefinitionBuilder<>::createProperty("Line Split Count")
+      .withDescription("The number of lines that will be added to each split file, excluding header lines. A value of zero requires Maximum Fragment Size to be set, and line count will not "
+        "be considered in determining splits.")
+      .withPropertyType(core::StandardPropertyTypes::UNSIGNED_LONG_TYPE)
+      .isRequired(true)
+      .build();
+  EXTENSIONAPI static constexpr auto MaximumFragmentSize = core::PropertyDefinitionBuilder<>::createProperty("Maximum Fragment Size")
+      .withDescription("The maximum size of each split file, including header lines. NOTE: in the case where a single line exceeds this property (including headers, if applicable), "
+        "that line will be output in a split of its own which exceeds this Maximum Fragment Size setting.")
+      .withPropertyType(core::StandardPropertyTypes::DATA_SIZE_TYPE)
+      .build();
+  EXTENSIONAPI static constexpr auto HeaderLineCount = core::PropertyDefinitionBuilder<>::createProperty("Header Line Count")
+      .withDescription("The number of lines that should be considered part of the header; the header lines will be duplicated to all split files.")
+      .withPropertyType(core::StandardPropertyTypes::UNSIGNED_LONG_TYPE)
+      .withDefaultValue("0")
+      .isRequired(true)
+      .build();
+  EXTENSIONAPI static constexpr auto HeaderLineMarkerCharacters = core::PropertyDefinitionBuilder<>::createProperty("Header Line Marker Characters")
+      .withDescription("The first character(s) on the line of the datafile which signifies a header line. This value is ignored when Header Line Count is non-zero. The first line not containing "
+        "the Header Line Marker Characters and all subsequent lines are considered non-header")
+      .build();
+  EXTENSIONAPI static constexpr auto RemoveTrailingNewlines = core::PropertyDefinitionBuilder<>::createProperty("Remove Trailing Newlines")
+      .withDescription("Whether to remove newlines at the end of each split file. This should be false if you intend to merge the split files later. If this is set to 'true' and a FlowFile is "
+        "generated that contains only 'empty lines' (i.e., consists only of \\r and \\n characters), the FlowFile will not be emitted. Note, however, that if header lines are specified, "
+        "the resultant FlowFile will never be empty as it will consist of the header lines, so a FlowFile may be emitted that contains only the header lines.")
+      .withPropertyType(core::StandardPropertyTypes::BOOLEAN_TYPE)
+      .withDefaultValue("true")
+      .isRequired(true)
+      .build();
+
+  EXTENSIONAPI static constexpr auto Properties = std::array<core::PropertyReference, 5>{
+      LineSplitCount,
+      MaximumFragmentSize,
+      HeaderLineCount,
+      HeaderLineMarkerCharacters,
+      RemoveTrailingNewlines
+  };
+
+  EXTENSIONAPI static constexpr auto Failure =
+    core::RelationshipDefinition{"failure", "If a file cannot be split for some reason, the original file will be routed to this destination and nothing will be routed elsewhere"};
+  EXTENSIONAPI static constexpr auto Original =
+    core::RelationshipDefinition{"original", "The original input file will be routed to this destination when it has been successfully split into 1 or more files"};
+  EXTENSIONAPI static constexpr auto Splits =
+    core::RelationshipDefinition{"splits", "The split files will be routed to this destination when an input file is successfully split into 1 or more split files"};
+  EXTENSIONAPI static constexpr auto Relationships = std::array{Failure, Original, Splits};
+
+  EXTENSIONAPI static constexpr auto TextLineCountOutputAttribute =
+    core::OutputAttributeDefinition<0>{"text.line.count", {}, "The number of lines of text from the original FlowFile that were copied to this FlowFile (does not count empty lines)"};
+  EXTENSIONAPI static constexpr auto FragmentSizeOutputAttribute =
+    core::OutputAttributeDefinition<0>{"fragment.size", {},
+      "The number of bytes from the original FlowFile that were copied to this FlowFile, including header, if applicable, which is duplicated in each split FlowFile"};
+  EXTENSIONAPI static constexpr auto FragmentIdentifierOutputAttribute =
+    core::OutputAttributeDefinition<0>{"fragment.identifier", {}, "All split FlowFiles produced from the same parent FlowFile will have the same randomly generated UUID added for this attribute"};
+  EXTENSIONAPI static constexpr auto FragmentIndexOutputAttribute =
+    core::OutputAttributeDefinition<0>{"fragment.index", {}, "A one-up number that indicates the ordering of the split FlowFiles that were created from a single parent FlowFile"};
+  EXTENSIONAPI static constexpr auto FragmentCountOutputAttribute =
+    core::OutputAttributeDefinition<0>{"fragment.count", {}, "The number of split FlowFiles generated from the parent FlowFile"};
+  EXTENSIONAPI static constexpr auto SegmentOriginalFilenameOutputAttribute =
+    core::OutputAttributeDefinition<0>{"segment.original.filename", {}, "The filename of the parent FlowFile"};
+  EXTENSIONAPI static constexpr auto OutputAttributes = std::array<core::OutputAttributeReference, 6>{TextLineCountOutputAttribute, FragmentSizeOutputAttribute, FragmentIdentifierOutputAttribute,
+    FragmentIndexOutputAttribute, FragmentCountOutputAttribute, SegmentOriginalFilenameOutputAttribute};
+
+  EXTENSIONAPI static constexpr bool SupportsDynamicProperties = true;
+  EXTENSIONAPI static constexpr bool SupportsDynamicRelationships = false;
+  EXTENSIONAPI static constexpr core::annotation::Input InputRequirement = core::annotation::Input::INPUT_REQUIRED;
+  EXTENSIONAPI static constexpr bool IsSingleThreaded = false;
+  ADD_COMMON_VIRTUAL_FUNCTIONS_FOR_PROCESSORS
+
+  void onSchedule(core::ProcessContext& context, core::ProcessSessionFactory& session_factory) override;
+  void onTrigger(core::ProcessContext& context, core::ProcessSession& session) override;
+  void initialize() override;
+
+ private:
+  SplitTextConfiguration split_text_config_;
+  std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<SplitText>::getLogger(uuid_);
+};
+
+}  // namespace org::apache::nifi::minifi::processors
diff --git a/extensions/standard-processors/tests/unit/SplitTextTests.cpp b/extensions/standard-processors/tests/unit/SplitTextTests.cpp
new file mode 100644
index 000000000..638f09a5c
--- /dev/null
+++ b/extensions/standard-processors/tests/unit/SplitTextTests.cpp
@@ -0,0 +1,862 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "FlowFileRecord.h"
+#include "TestBase.h"
+#include "Catch.h"
+#include "processors/SplitText.h"
+#include "SingleProcessorTestController.h"
+#include "io/BufferStream.h"
+
+namespace org::apache::nifi::minifi::test {
+
+TEST_CASE("Test LineReader with nullptr") {
+  processors::detail::LineReader reader{nullptr};
+  CHECK(reader.readNextLine() == std::nullopt);
+  CHECK(reader.getState() == processors::detail::StreamReadState::EndOfStream);
+}
+
+TEST_CASE("Test LineReader with empty stream") {
+  auto stream = std::make_shared<io::BufferStream>();
+  processors::detail::LineReader reader{stream};
+  CHECK(reader.readNextLine() == std::nullopt);
+  CHECK(reader.getState() == processors::detail::StreamReadState::EndOfStream);
+}
+
+TEST_CASE("Test LineReader with trailing endline") {
+  auto stream = std::make_shared<io::BufferStream>();
+  std::string input = "this is a new line\nand another line\r\nthirdline\n";
+  stream->write(reinterpret_cast<const uint8_t*>(input.data()), input.size());
+  processors::detail::LineReader reader{stream};
+  CHECK(reader.readNextLine() == processors::detail::LineReader::LineInfo{.offset = 0, .size = 19, .endline_size = 1});
+  CHECK(reader.readNextLine() == processors::detail::LineReader::LineInfo{.offset = 19, .size = 18, .endline_size = 2});
+  CHECK(reader.readNextLine() == processors::detail::LineReader::LineInfo{.offset = 37, .size = 10, .endline_size = 1});
+  CHECK(reader.readNextLine() == std::nullopt);
+  CHECK(reader.getState() == processors::detail::StreamReadState::EndOfStream);
+}
+
+TEST_CASE("Test LineReader without trailing endlines") {
+  auto stream = std::make_shared<io::BufferStream>();
+  std::string input = "this is a new line\nand another line\r\nthirdline";
+  stream->write(reinterpret_cast<const uint8_t*>(input.data()), input.size());
+  processors::detail::LineReader reader{stream};
+  CHECK(reader.readNextLine() == processors::detail::LineReader::LineInfo{.offset = 0, .size = 19, .endline_size = 1});
+  CHECK(reader.readNextLine() == processors::detail::LineReader::LineInfo{.offset = 19, .size = 18, .endline_size = 2});
+  CHECK(reader.readNextLine() == processors::detail::LineReader::LineInfo{.offset = 37, .size = 9, .endline_size = 0});
+  CHECK(reader.readNextLine() == std::nullopt);
+  CHECK(reader.getState() == processors::detail::StreamReadState::EndOfStream);
+}
+
+TEST_CASE("Test LineReader with input larger than buffer length") {
+  auto stream = std::make_shared<io::BufferStream>();
+  const auto first_line_size = static_cast<size_t>(processors::detail::SPLIT_TEXT_BUFFER_SIZE * 1.5);
+  const auto second_line_size = static_cast<size_t>(processors::detail::SPLIT_TEXT_BUFFER_SIZE * 1.7);
+  std::string input = std::string(first_line_size, 'a') + "\n" + std::string(second_line_size, 'b') + "\n";
+  stream->write(reinterpret_cast<const uint8_t*>(input.data()), input.size());
+  processors::detail::LineReader reader{stream};
+  CHECK(reader.readNextLine() == processors::detail::LineReader::LineInfo{.offset = 0, .size = first_line_size + 1, .endline_size = 1});
+  CHECK(reader.readNextLine() == processors::detail::LineReader::LineInfo{.offset = first_line_size +1 , .size = second_line_size + 1, .endline_size = 1});
+  CHECK(reader.readNextLine() == std::nullopt);
+  CHECK(reader.getState() == processors::detail::StreamReadState::EndOfStream);
+}
+
+TEST_CASE("Test LineReader with input of same size as buffer length") {
+  auto stream = std::make_shared<io::BufferStream>();
+  std::string input = std::string(processors::detail::SPLIT_TEXT_BUFFER_SIZE - 1, 'a') + "\n" + std::string(processors::detail::SPLIT_TEXT_BUFFER_SIZE * 2 - 1, 'b') + "\n";
+  stream->write(reinterpret_cast<const uint8_t*>(input.data()), input.size());
+  processors::detail::LineReader reader{stream};
+  CHECK(reader.readNextLine() == processors::detail::LineReader::LineInfo{.offset = 0, .size = processors::detail::SPLIT_TEXT_BUFFER_SIZE, .endline_size = 1});
+  CHECK(reader.readNextLine() ==
+    processors::detail::LineReader::LineInfo{.offset = processors::detail::SPLIT_TEXT_BUFFER_SIZE, .size = processors::detail::SPLIT_TEXT_BUFFER_SIZE * 2, .endline_size = 1});
+  CHECK(reader.readNextLine() == std::nullopt);
+  CHECK(reader.getState() == processors::detail::StreamReadState::EndOfStream);
+}
+
+TEST_CASE("Test LineReader with input larger than buffer length without trailing endline") {
+  auto stream = std::make_shared<io::BufferStream>();
+  const auto first_line_size = static_cast<size_t>(processors::detail::SPLIT_TEXT_BUFFER_SIZE * 1.5);
+  const auto second_line_size = static_cast<size_t>(processors::detail::SPLIT_TEXT_BUFFER_SIZE * 1.7);
+  std::string input = std::string(first_line_size, 'a') + "\n" + std::string(second_line_size, 'b');
+  stream->write(reinterpret_cast<const uint8_t*>(input.data()), input.size());
+  processors::detail::LineReader reader{stream};
+  CHECK(reader.readNextLine() == processors::detail::LineReader::LineInfo{.offset = 0, .size = first_line_size + 1, .endline_size = 1});
+  CHECK(reader.readNextLine() == processors::detail::LineReader::LineInfo{.offset = first_line_size + 1, .size = second_line_size, .endline_size = 0});
+  CHECK(reader.readNextLine() == std::nullopt);
+  CHECK(reader.getState() == processors::detail::StreamReadState::EndOfStream);
+}
+
+TEST_CASE("Test LineReader with input of same size as buffer length without trailing endline") {
+  auto stream = std::make_shared<io::BufferStream>();
+  std::string input = std::string(processors::detail::SPLIT_TEXT_BUFFER_SIZE - 1, 'a') + "\n" + std::string(processors::detail::SPLIT_TEXT_BUFFER_SIZE * 2, 'b');
+  stream->write(reinterpret_cast<const uint8_t*>(input.data()), input.size());
+  processors::detail::LineReader reader{stream};
+  CHECK(reader.readNextLine() == processors::detail::LineReader::LineInfo{.offset = 0, .size = processors::detail::SPLIT_TEXT_BUFFER_SIZE, .endline_size = 1});
+  CHECK(reader.readNextLine() ==
+    processors::detail::LineReader::LineInfo{.offset = processors::detail::SPLIT_TEXT_BUFFER_SIZE, .size = processors::detail::SPLIT_TEXT_BUFFER_SIZE * 2, .endline_size = 0});
+  CHECK(reader.readNextLine() == std::nullopt);
+  CHECK(reader.getState() == processors::detail::StreamReadState::EndOfStream);
+}
+
+TEST_CASE("Test LineReader with starts with filter") {
+  auto stream = std::make_shared<io::BufferStream>();
+  std::string input = "header this is a new line\nheader and another line\r\nthirdline\nheader line\n";
+  stream->write(reinterpret_cast<const uint8_t*>(input.data()), input.size());
+  processors::detail::LineReader reader{stream};
+  CHECK(reader.readNextLine("header") == processors::detail::LineReader::LineInfo{.offset = 0, .size = 26, .endline_size = 1, .matches_starts_with = true});
+  CHECK(reader.readNextLine("header") == processors::detail::LineReader::LineInfo{.offset = 26, .size = 25, .endline_size = 2, .matches_starts_with = true});
+  CHECK(reader.readNextLine("header") == processors::detail::LineReader::LineInfo{.offset = 51, .size = 10, .endline_size = 1, .matches_starts_with = false});
+  CHECK(reader.readNextLine("header") == processors::detail::LineReader::LineInfo{.offset = 61, .size = 12, .endline_size = 1, .matches_starts_with = true});
+  CHECK(reader.readNextLine() == std::nullopt);
+  CHECK(reader.getState() == processors::detail::StreamReadState::EndOfStream);
+}
+
+struct ExpectedSplitTextResult {
+  std::string content;
+  uint64_t fragment_index = 0;
+  uint64_t fragment_count = 0;
+  uint64_t text_line_count = 0;
+};
+
+struct SplitTextProperties {
+  uint64_t line_split_count = 0;
+  std::optional<bool> trim_trailing_newlines;
+  std::optional<uint64_t> maximum_fragment_size;
+  std::optional<uint64_t> header_line_count;
+  std::optional<std::string> header_line_marker_characters;
+};
+
+void verifySplitResults(const SingleProcessorTestController& controller, const ProcessorTriggerResult& trigger_results, const std::vector<ExpectedSplitTextResult>& expected_results) {
+  const auto& actual_results = trigger_results.at(processors::SplitText::Splits);
+  REQUIRE(actual_results.size() == expected_results.size());
+  std::string identifier;
+  for (size_t i = 0; i < expected_results.size(); ++i) {
+    CHECK(controller.plan->getContent(actual_results[i]) == expected_results[i].content);
+
+    CHECK(actual_results[i]->getAttribute(processors::SplitText::TextLineCountOutputAttribute.name) == std::to_string(expected_results[i].text_line_count));
+    CHECK(actual_results[i]->getAttribute(processors::SplitText::FragmentSizeOutputAttribute.name) == std::to_string(expected_results[i].content.size()));
+    if (i > 0) {
+      CHECK(actual_results[i]->getAttribute(processors::SplitText::FragmentIdentifierOutputAttribute.name).value() == identifier);
+    } else {
+      identifier = actual_results[i]->getAttribute(processors::SplitText::FragmentIdentifierOutputAttribute.name).value();
+      CHECK(!identifier.empty());
+    }
+    CHECK(actual_results[i]->getAttribute(core::SpecialFlowAttribute::FILENAME) ==
+      "a.foo.fragment." + identifier + "." + std::to_string(expected_results[i].fragment_index));
+    CHECK(actual_results[i]->getAttribute(processors::SplitText::FragmentIndexOutputAttribute.name) == std::to_string(expected_results[i].fragment_index));
+    CHECK(actual_results[i]->getAttribute(processors::SplitText::FragmentCountOutputAttribute.name) == std::to_string(expected_results[i].fragment_count));
+    CHECK(actual_results[i]->getAttribute(processors::SplitText::SegmentOriginalFilenameOutputAttribute.name) == "a.foo");
+  }
+}
+
+void runSplitTextTest(const std::string& input, const std::vector<ExpectedSplitTextResult>& expected_results, const SplitTextProperties& properties) {
+  const auto split_text = std::make_shared<processors::SplitText>("SplitText");
+  SingleProcessorTestController controller{split_text};
+  split_text->setProperty(processors::SplitText::LineSplitCount, std::to_string(properties.line_split_count));
+  if (properties.maximum_fragment_size) {
+    split_text->setProperty(processors::SplitText::MaximumFragmentSize, std::to_string(*properties.maximum_fragment_size) + " B");
+  }
+  if (properties.trim_trailing_newlines) {
+    split_text->setProperty(processors::SplitText::RemoveTrailingNewlines, properties.trim_trailing_newlines.value() ? "true" : "false");
+  }
+  if (properties.header_line_count) {
+    split_text->setProperty(processors::SplitText::HeaderLineCount, std::to_string(*properties.header_line_count));
+  }
+  if (properties.header_line_marker_characters) {
+    split_text->setProperty(processors::SplitText::HeaderLineMarkerCharacters, *properties.header_line_marker_characters);
+  }
+  const auto trigger_results = controller.trigger(input, {{std::string(core::SpecialFlowAttribute::FILENAME), "a.foo"}});
+  CHECK(trigger_results.at(processors::SplitText::Failure).empty());
+  CHECK(trigger_results.at(processors::SplitText::Original).size() == 1);
+  CHECK(trigger_results.at(processors::SplitText::Original)[0]->getAttribute(core::SpecialFlowAttribute::FILENAME) == "a.foo");
+  CHECK(controller.plan->getContent(trigger_results.at(processors::SplitText::Original)[0]) == input);
+  verifySplitResults(controller, trigger_results, expected_results);
+}
+
+TEST_CASE("Line Split Count property is required") {
+  const auto split_text = std::make_shared<processors::SplitText>("SplitText");
+  SingleProcessorTestController controller{split_text};
+  REQUIRE_THROWS_AS(controller.trigger("", {}), minifi::Exception);
+}
+
+TEST_CASE("Line Split Count property can only be 0 if Maximum Fragment Size is set") {
+  const auto split_text = std::make_shared<processors::SplitText>("SplitText");
+  SingleProcessorTestController controller{split_text};
+  split_text->setProperty(processors::SplitText::LineSplitCount, "0");
+  REQUIRE_THROWS_AS(controller.trigger("", {}), minifi::Exception);
+}
+
+TEST_CASE("Maximum Fragment Size cannot be set to 0") {
+  const auto split_text = std::make_shared<processors::SplitText>("SplitText");
+  SingleProcessorTestController controller{split_text};
+  split_text->setProperty(processors::SplitText::LineSplitCount, "0");
+  split_text->setProperty(processors::SplitText::MaximumFragmentSize, "0 B");
+  REQUIRE_THROWS_AS(controller.trigger("", {}), minifi::Exception);
+}
+
+TEST_CASE("Header Line Marker Characters size cannot be equal or larger than split text buffer size") {
+  const auto split_text = std::make_shared<processors::SplitText>("SplitText");
+  SingleProcessorTestController controller{split_text};
+  split_text->setProperty(processors::SplitText::LineSplitCount, "1");
+  std::string header_marker_character(processors::detail::SPLIT_TEXT_BUFFER_SIZE, 'A');
+  split_text->setProperty(processors::SplitText::HeaderLineMarkerCharacters, header_marker_character);
+  REQUIRE_THROWS_AS(controller.trigger("", {}), minifi::Exception);
+}
+
+
+TEST_CASE("SplitText only forwards empty flowfile") {
+  const auto split_text = std::make_shared<processors::SplitText>("SplitText");
+  SingleProcessorTestController controller{split_text};
+  split_text->setProperty(processors::SplitText::LineSplitCount, "1");
+  const auto trigger_results = controller.trigger("", {{std::string(core::SpecialFlowAttribute::FILENAME), "a.foo"}});
+  CHECK(trigger_results.at(processors::SplitText::Splits).empty());
+  CHECK(trigger_results.at(processors::SplitText::Failure).empty());
+  CHECK(trigger_results.at(processors::SplitText::Original).size() == 1);
+  CHECK(trigger_results.at(processors::SplitText::Original)[0]->getAttribute(core::SpecialFlowAttribute::FILENAME) == "a.foo");
+  CHECK(controller.plan->getContent(trigger_results.at(processors::SplitText::Original)[0]).empty());
+}
+
+TEST_CASE("SplitText creates new flow file for a single line") {
+  std::vector<ExpectedSplitTextResult> expected_results(1, ExpectedSplitTextResult{});
+  expected_results[0].fragment_index = 1;
+  expected_results[0].fragment_count = 1;
+  expected_results[0].text_line_count = 1;
+  std::string line;
+  SECTION("Empty line with LF endline") {
+    line = "\n";
+    expected_results[0].content = line;
+    expected_results[0].text_line_count = 0;
+  }
+  SECTION("LF endline") {
+    line = "this is a new line\n";
+    expected_results[0].content = line;
+  }
+  SECTION("CRLF endline") {
+    line = "this is a new line\r\n";
+    expected_results[0].content = line;
+  }
+  SECTION("Line size larger than buffer size") {
+    line = std::string(static_cast<size_t>(processors::detail::SPLIT_TEXT_BUFFER_SIZE * 1.5), 'a') + "\n";
+    expected_results[0].content = line;
+  }
+  SECTION("Content without endline is a single line") {
+    line = "this is a new line";
+    expected_results[0].content = line;
+  }
+
+  SplitTextProperties properties;
+  properties.line_split_count = 1;
+  properties.trim_trailing_newlines = false;
+  runSplitTextTest(line, expected_results, properties);
+}
+
+TEST_CASE("SplitText creates new flow file with 2 lines") {
+  std::vector<ExpectedSplitTextResult> expected_results(1, ExpectedSplitTextResult{});
+  expected_results[0].fragment_index = 1;
+  expected_results[0].fragment_count = 1;
+  expected_results[0].text_line_count = 2;
+  std::string input;
+  bool remove_trailing_endline = false;
+  SECTION("Only LF endlines") {
+    input = "\n\n";
+    expected_results[0].text_line_count = 0;
+    expected_results[0].content = input;
+  }
+  SECTION("LF endline") {
+    input = "this is a new line\nand another line\n";
+    expected_results[0].content = input;
+  }
+  SECTION("LF endline removing trailing endlines") {
+    input = "this is a new line\nand another line\n\n";
+    remove_trailing_endline = true;
+    expected_results[0].content = "this is a new line\nand another line";
+  }
+  SECTION("CRLF endline") {
+    input = "this is a new line\r\nand another line\r\n";
+    expected_results[0].content = input;
+  }
+  SECTION("CRLF endline removing trailing endlines") {
+    input = "this is a new line\r\nand another line\r\n\r\n";
+    remove_trailing_endline = true;
+    expected_results[0].content = "this is a new line\r\nand another line";
+  }
+  SECTION("Line size larger than buffer size") {
+    std::string str(static_cast<size_t>(processors::detail::SPLIT_TEXT_BUFFER_SIZE * 1.5), 'a');
+    input = str + "\n" + str + "\n";
+    expected_results[0].content = input;
+  }
+  SECTION("Line size larger than buffer size without endline at the end") {
+    std::string str(static_cast<size_t>(processors::detail::SPLIT_TEXT_BUFFER_SIZE * 1.5), 'a');
+    input = str + "\n" + str;
+    expected_results[0].content = input;
+  }
+
+  SplitTextProperties properties;
+  properties.line_split_count = 2;
+  properties.trim_trailing_newlines = remove_trailing_endline;
+  runSplitTextTest(input, expected_results, properties);
+}
+
+TEST_CASE("SplitText creates separate flow files from 2 lines") {
+  std::vector<ExpectedSplitTextResult> expected_results(2, ExpectedSplitTextResult{});
+  expected_results[0].fragment_index = 1;
+  expected_results[0].fragment_count = 2;
+  expected_results[0].text_line_count = 1;
+  expected_results[1].fragment_index = 2;
+  expected_results[1].fragment_count = 2;
+  expected_results[1].text_line_count = 1;
+  std::string input;
+  SECTION("Only LF endline") {
+    input = "\n\n";
+    expected_results[0].content = "\n";
+    expected_results[0].text_line_count = 0;
+    expected_results[1].content = "\n";
+    expected_results[1].text_line_count = 0;
+  }
+  SECTION("LF endline") {
+    input = "this is a new line\nand another line\n";
+    expected_results[0].content = "this is a new line\n";
+    expected_results[1].content = "and another line\n";
+  }
+  SECTION("CRLF endline") {
+    input = "this is a new line\r\nand another line\r\n";
+    expected_results[0].content = "this is a new line\r\n";
+    expected_results[1].content = "and another line\r\n";
+  }
+  SECTION("Line size larger than buffer size") {
+    std::string str(static_cast<size_t>(processors::detail::SPLIT_TEXT_BUFFER_SIZE * 1.5), 'a');
+    input = str + "\n" + str + "\n";
+    expected_results[0].content = str + "\n";
+    expected_results[1].content = str + "\n";
+  }
+  SECTION("Line size larger than buffer size without endline at the end") {
+    std::string str(static_cast<size_t>(processors::detail::SPLIT_TEXT_BUFFER_SIZE * 1.5), 'a');
+    input = str + "\n" + str;
+    expected_results[0].content = str + "\n";
+    expected_results[1].content = str;
+  }
+
+  SplitTextProperties properties;
+  properties.line_split_count = 1;
+  properties.trim_trailing_newlines = false;
+  runSplitTextTest(input, expected_results, properties);
+}
+
+TEST_CASE("Endlines are trimmed when Remove Trailing Newlines is set to true and splitting by lines") {
+  std::vector<ExpectedSplitTextResult> expected_results;
+  uint64_t line_split_count = 0;
+  std::string input;
+  SECTION("Only newlines") {
+    input = "\n\n\n\n\n\n\n";
+    line_split_count = 3;
+  }
+  SECTION("Starting new lines are removed") {
+    input = "\n\n\n\nline1\nline2\nline3\n\n\n";
+    line_split_count = 3;
+    expected_results.push_back(ExpectedSplitTextResult{
+      .content = "\nline1\nline2",
+      .fragment_index = 1,
+      .fragment_count = 2,
+      .text_line_count = 2
+    });
+    expected_results.push_back(ExpectedSplitTextResult{
+      .content = "line3",
+      .fragment_index = 2,
+      .fragment_count = 2,
+      .text_line_count = 1
+    });
+  }
+  SECTION("Endline types are mixed") {
+    input = "\n\r\n\n\r\nline1\nline2\r\nline3\r\n\n";
+    line_split_count = 3;
+    expected_results.push_back(ExpectedSplitTextResult{
+      .content = "\r\nline1\nline2",
+      .fragment_index = 1,
+      .fragment_count = 2,
+      .text_line_count = 2
+    });
+    expected_results.push_back(ExpectedSplitTextResult{
+      .content = "line3",
+      .fragment_index = 2,
+      .fragment_count = 2,
+      .text_line_count = 1
+    });
+  }
+
+  SplitTextProperties properties;
+  properties.line_split_count = line_split_count;
+  properties.trim_trailing_newlines = true;
+  runSplitTextTest(input, expected_results, properties);
+}
+
+TEST_CASE("If flowfile is empty after trailing new lines are removed then flow file is not emitted") {
+  const auto split_text = std::make_shared<processors::SplitText>("SplitText");
+  SingleProcessorTestController controller{split_text};
+  SECTION("Line split count 1") {
+    split_text->setProperty(processors::SplitText::LineSplitCount, "1");
+  }
+  SECTION("Line split count 2") {
+    split_text->setProperty(processors::SplitText::LineSplitCount, "2");
+  }
+  const auto trigger_results = controller.trigger("\n\n", {{std::string(core::SpecialFlowAttribute::FILENAME), "a.foo"}});
+  CHECK(trigger_results.at(processors::SplitText::Splits).empty());
+  CHECK(trigger_results.at(processors::SplitText::Failure).empty());
+  CHECK(trigger_results.at(processors::SplitText::Original).size() == 1);
+  CHECK(trigger_results.at(processors::SplitText::Original)[0]->getAttribute(core::SpecialFlowAttribute::FILENAME) == "a.foo");
+  CHECK(controller.plan->getContent(trigger_results.at(processors::SplitText::Original)[0]) == "\n\n");
+}
+
+TEST_CASE("Test Maximum Fragment Size without Line Split Count") {
+  std::vector<ExpectedSplitTextResult> expected_results;
+  std::string input;
+  std::optional<uint64_t> maximum_fragment_size;
+  bool trim_trailing_newlines = false;
+  SECTION("When line split count is zero only max fragment size is used") {
+    input = "this is a new line\nand another line\nthirdline\n";
+    maximum_fragment_size = 40;
+    expected_results.push_back(ExpectedSplitTextResult{
+      .content = "this is a new line\nand another line\n",
+      .fragment_index = 1,
+      .fragment_count = 2,
+      .text_line_count = 2
+    });
+    expected_results.push_back(ExpectedSplitTextResult{
+      .content = "thirdline\n",
+      .fragment_index = 2,
+      .fragment_count = 2,
+      .text_line_count = 1
+    });
+  }
+  SECTION("Max fragment size is larger than the input") {
+    input = "this is a new line\nand another line\nthirdline\n";
+    maximum_fragment_size = 100;
+    expected_results.push_back(ExpectedSplitTextResult{
+      .content = input,
+      .fragment_index = 1,
+      .fragment_count = 1,
+      .text_line_count = 3
+    });
+  }
+  SECTION("When max fragment size limit is reached with only empty lines, flowfile should not be emitted") {
+    input = "\n\nthis is a new line\n\n\nand another line\n";
+    maximum_fragment_size = 2;
+    trim_trailing_newlines = true;
+    expected_results.push_back(ExpectedSplitTextResult{
+      .content = "this is a new line",
+      .fragment_index = 1,
+      .fragment_count = 2,
+      .text_line_count = 1
+    });
+    expected_results.push_back(ExpectedSplitTextResult{
+      .content = "and another line",
+      .fragment_index = 2,
+      .fragment_count = 2,
+      .text_line_count = 1
+    });
+  }
+  SECTION("When max fragment size limit is reached and only empty lines are present, flowfile should be emitted if trailing newlines are not removed") {
+    input = "\n\nthis is a new line\n\nand another line\n";
+    maximum_fragment_size = 2;
+    trim_trailing_newlines = false;
+    expected_results.push_back(ExpectedSplitTextResult{
+      .content = "\n\n",
+      .fragment_index = 1,
+      .fragment_count = 4,
+      .text_line_count = 0
+    });
+    expected_results.push_back(ExpectedSplitTextResult{
+      .content = "this is a new line\n",
+      .fragment_index = 2,
+      .fragment_count = 4,
+      .text_line_count = 1
+    });
+    expected_results.push_back(ExpectedSplitTextResult{
+      .content = "\n",
+      .fragment_index = 3,
+      .fragment_count = 4,
+      .text_line_count = 0
+    });
+    expected_results.push_back(ExpectedSplitTextResult{
+      .content = "and another line\n",
+      .fragment_index = 4,
+      .fragment_count = 4,
+      .text_line_count = 1
+    });
+  }
+  SECTION("Fragment index should not be incremented for removed only-newline fragments") {
+    input = "trim\n\n\n\n\n\nand another line\n\n";
+    maximum_fragment_size = 5;
+    trim_trailing_newlines = true;
+    expected_results.push_back(ExpectedSplitTextResult{
+      .content = "trim",
+      .fragment_index = 1,
+      .fragment_count = 2,
+      .text_line_count = 1
+    });
+    expected_results.push_back(ExpectedSplitTextResult{
+      .content = "and another line",
+      .fragment_index = 2,
+      .fragment_count = 2,
+      .text_line_count = 1
+    });
+  }
+
+  SplitTextProperties properties;
+  properties.line_split_count = 0;
+  properties.trim_trailing_newlines = trim_trailing_newlines;
+  properties.maximum_fragment_size = maximum_fragment_size;
+  runSplitTextTest(input, expected_results, properties);
+}
+
+TEST_CASE("Test Maximum Fragment Size together with Line Split Count") {
+  std::vector<ExpectedSplitTextResult> expected_results;
+  std::string input;
+  uint64_t line_split_count = 0;
+  uint64_t maximum_fragment_size = 0;
+  SECTION("Maximum fragment size reaches the limit first") {
+    input = "this is a new line\nand another line\nthirdline\n";
+    line_split_count = 3;
+    maximum_fragment_size = 40;
+    expected_results.push_back(ExpectedSplitTextResult{
+      .content = "this is a new line\nand another line\n",
+      .fragment_index = 1,
+      .fragment_count = 2,
+      .text_line_count = 2
+    });
+    expected_results.push_back(ExpectedSplitTextResult{
+      .content = "thirdline\n",
+      .fragment_index = 2,
+      .fragment_count = 2,
+      .text_line_count = 1
+    });
+  }
+  SECTION("Maximum fragment size reaches the limit before the first line") {
+    input = "this is a new line\nand another line\nthirdline\n";
+    line_split_count = 2;
+    maximum_fragment_size = 13;
+    expected_results.push_back(ExpectedSplitTextResult{
+      .content = "this is a new line\n",
+      .fragment_index = 1,
+      .fragment_count = 3,
+      .text_line_count = 1
+    });
+    expected_results.push_back(ExpectedSplitTextResult{
+      .content = "and another line\n",
+      .fragment_index = 2,
+      .fragment_count = 3,
+      .text_line_count = 1
+    });
+    expected_results.push_back(ExpectedSplitTextResult{
+      .content = "thirdline\n",
+      .fragment_index = 3,
+      .fragment_count = 3,
+      .text_line_count = 1
+    });
+  }
+  SECTION("Line split count reaches the limit before the max fragment size") {
+    input = "this is a new line\nand another line\nthirdline\n";
+    line_split_count = 2;
+    maximum_fragment_size = 50;
+    expected_results.push_back(ExpectedSplitTextResult{
+      .content = "this is a new line\nand another line\n",
+      .fragment_index = 1,
+      .fragment_count = 2,
+      .text_line_count = 2
+    });
+    expected_results.push_back(ExpectedSplitTextResult{
+      .content = "thirdline\n",
+      .fragment_index = 2,
+      .fragment_count = 2,
+      .text_line_count = 1
+    });
+  }
+
+  SplitTextProperties properties;
+  properties.line_split_count = line_split_count;
+  properties.trim_trailing_newlines = false;
+  properties.maximum_fragment_size = maximum_fragment_size;
+  runSplitTextTest(input, expected_results, properties);
+}
+
+TEST_CASE("If the header defined by the header line count is larger than the flow file line count then the processor should fail") {
+  std::string input;
+  SECTION("Empty flow file") {
+    input = "";
+  }
+  SECTION("Header line count is one line shorter larger than the flow file") {
+    input = "header line 1\nheader line 2\nthis is a new line\n";
+  }
+  const auto split_text = std::make_shared<processors::SplitText>("SplitText");
+  SingleProcessorTestController controller{split_text};
+  split_text->setProperty(processors::SplitText::LineSplitCount, "1");
+  split_text->setProperty(processors::SplitText::HeaderLineCount, "4");
+  const auto trigger_results = controller.trigger(input, {{std::string(core::SpecialFlowAttribute::FILENAME), "a.foo"}});
+  CHECK(trigger_results.at(processors::SplitText::Splits).empty());
+  REQUIRE(trigger_results.at(processors::SplitText::Original).empty());
+  REQUIRE(trigger_results.at(processors::SplitText::Failure).size() == 1);
+  CHECK(controller.plan->getContent(trigger_results.at(processors::SplitText::Failure)[0]) == input);
+}
+
+TEST_CASE("If the header defined by the header line count is larger than the max fragment size then the processor should fail") {
+  std::string input;
+  input = "header line 1\nheader line 2\nthis is a new line\n";
+  const auto split_text = std::make_shared<processors::SplitText>("SplitText");
+  SingleProcessorTestController controller{split_text};
+  split_text->setProperty(processors::SplitText::MaximumFragmentSize, "20 B");
+  split_text->setProperty(processors::SplitText::HeaderLineCount, "2");
+  split_text->setProperty(processors::SplitText::LineSplitCount, "0");
+  const auto trigger_results = controller.trigger(input, {{std::string(core::SpecialFlowAttribute::FILENAME), "a.foo"}});
+  CHECK(trigger_results.at(processors::SplitText::Splits).empty());
+  REQUIRE(trigger_results.at(processors::SplitText::Original).empty());
+  REQUIRE(trigger_results.at(processors::SplitText::Failure).size() == 1);
+  CHECK(controller.plan->getContent(trigger_results.at(processors::SplitText::Failure)[0]) == input);
+}
+
+TEST_CASE("If header line count is the same as the flow file line count then no new flow file should be emitted") {
+  std::string input = "header line 1\nheader line 2\nthis is a new line\n";
+  const auto split_text = std::make_shared<processors::SplitText>("SplitText");
+  SingleProcessorTestController controller{split_text};
+  split_text->setProperty(processors::SplitText::LineSplitCount, "1");
+  split_text->setProperty(processors::SplitText::HeaderLineCount, "3");
+  const auto trigger_results = controller.trigger(input, {{std::string(core::SpecialFlowAttribute::FILENAME), "a.foo"}});
+  CHECK(trigger_results.at(processors::SplitText::Splits).empty());
+  REQUIRE(trigger_results.at(processors::SplitText::Failure).empty());
+  REQUIRE(trigger_results.at(processors::SplitText::Original).size() == 1);
+  CHECK(trigger_results.at(processors::SplitText::Original)[0]->getAttribute(core::SpecialFlowAttribute::FILENAME) == "a.foo");
+  CHECK(controller.plan->getContent(trigger_results.at(processors::SplitText::Original)[0]) == input);
+}
+
+TEST_CASE("Append generated flow files with specified number of header lines") {
+  std::vector<ExpectedSplitTextResult> expected_results;
+  std::string input = "header line 1\nheader line 2\nthis is a new line\nand another line\n";
+  uint64_t line_split_count = 0;
+  bool trim_trailing_newlines = false;
+  SECTION("Line split count 1") {
+    line_split_count = 1;
+    expected_results.push_back(ExpectedSplitTextResult{
+      .content = "header line 1\nheader line 2\nthis is a new line\n",
+      .fragment_index = 1,
+      .fragment_count = 2,
+      .text_line_count = 1
+    });
+    expected_results.push_back(ExpectedSplitTextResult{
+      .content = "header line 1\nheader line 2\nand another line\n",
+      .fragment_index = 2,
+      .fragment_count = 2,
+      .text_line_count = 1
+    });
+  }
+  SECTION("Line split count 2") {
+    line_split_count = 2;
+    trim_trailing_newlines = true;
+    expected_results.push_back(ExpectedSplitTextResult{
+      .content = "header line 1\nheader line 2\nthis is a new line\nand another line",
+      .fragment_index = 1,
+      .fragment_count = 1,
+      .text_line_count = 2
+    });
+  }
+  runSplitTextTest(input, expected_results, SplitTextProperties{
+    .line_split_count = line_split_count,
+    .trim_trailing_newlines = trim_trailing_newlines,
+    .maximum_fragment_size = std::nullopt,
+    .header_line_count = 2,
+    .header_line_marker_characters = "ignored"
+  });
+}
+
+TEST_CASE("If a split fragment would only consist of new lines then only the trimmed header should be emitted") {
+  std::vector<ExpectedSplitTextResult> expected_results;
+  std::string input = "header line 1\n\nline1\nline2\n\n\nline3\nline4\n\n\n\n";
+  expected_results.push_back(ExpectedSplitTextResult{
+    .content = "header line 1\n\nline1\nline2",
+    .fragment_index = 1,
+    .fragment_count = 5,
+    .text_line_count = 2
+  });
+  expected_results.push_back(ExpectedSplitTextResult{
+    .content = "header line 1",
+    .fragment_index = 2,
+    .fragment_count = 5,
+    .text_line_count = 0
+  });
+  expected_results.push_back(ExpectedSplitTextResult{
+    .content = "header line 1\n\nline3\nline4",
+    .fragment_index = 3,
+    .fragment_count = 5,
+    .text_line_count = 2
+  });
+  expected_results.push_back(ExpectedSplitTextResult{
+    .content = "header line 1",
+    .fragment_index = 4,
+    .fragment_count = 5,
+    .text_line_count = 0
+  });
+  expected_results.push_back(ExpectedSplitTextResult{
+    .content = "header line 1",
+    .fragment_index = 5,
+    .fragment_count = 5,
+    .text_line_count = 0
+  });
+
+  runSplitTextTest(input, expected_results, SplitTextProperties{
+    .line_split_count = 2,
+    .trim_trailing_newlines = true,
+    .maximum_fragment_size = std::nullopt,
+    .header_line_count = 2,
+    .header_line_marker_characters = "ignored"
+  });
+}
+
+TEST_CASE("Append generated flow files with header lines specified with header line marker characters") {
+  std::vector<ExpectedSplitTextResult> expected_results;
+  std::string input = "header line 1\nheader line 2\nthis is a new line\nand another line\n";
+  uint64_t line_split_count = 0;
+  bool trim_trailing_newlines = false;
+  SECTION("Line split count 1") {
+    line_split_count = 1;
+    expected_results.push_back(ExpectedSplitTextResult{
+      .content = "header line 1\nheader line 2\nthis is a new line\n",
+      .fragment_index = 1,
+      .fragment_count = 2,
+      .text_line_count = 1
+    });
+    expected_results.push_back(ExpectedSplitTextResult{
+      .content = "header line 1\nheader line 2\nand another line\n",
+      .fragment_index = 2,
+      .fragment_count = 2,
+      .text_line_count = 1
+    });
+  }
+  SECTION("Line split count 2") {
+    line_split_count = 2;
+    trim_trailing_newlines = true;
+    expected_results.push_back(ExpectedSplitTextResult{
+      .content = "header line 1\nheader line 2\nthis is a new line\nand another line",
+      .fragment_index = 1,
+      .fragment_count = 1,
+      .text_line_count = 2
+    });
+  }
+  runSplitTextTest(input, expected_results, SplitTextProperties{
+    .line_split_count = line_split_count,
+    .trim_trailing_newlines = trim_trailing_newlines,
+    .maximum_fragment_size = std::nullopt,
+    .header_line_count = std::nullopt,
+    .header_line_marker_characters = "hea"
+  });
+}
+
+TEST_CASE("If a split fragment would only consist of new lines then only the trimmed header should be emitted when using header line marker characters") {
+  std::vector<ExpectedSplitTextResult> expected_results;
+  std::string input = "header line 1\nvery long line should be splitted before split line count\nline2\n\n\n\nline3\nline4\n\n";
+  expected_results.push_back(ExpectedSplitTextResult{
+    .content = "header line 1\nvery long line should be splitted before split line count",
+    .fragment_index = 1,
+    .fragment_count = 5,
+    .text_line_count = 1
+  });
+  expected_results.push_back(ExpectedSplitTextResult{
+    .content = "header line 1\nline2",
+    .fragment_index = 2,
+    .fragment_count = 5,
+    .text_line_count = 1
+  });
+  expected_results.push_back(ExpectedSplitTextResult{
+    .content = "header line 1",
+    .fragment_index = 3,
+    .fragment_count = 5,
+    .text_line_count = 0
+  });
+  expected_results.push_back(ExpectedSplitTextResult{
+    .content = "header line 1\nline3\nline4",
+    .fragment_index = 4,
+    .fragment_count = 5,
+    .text_line_count = 2
+  });
+  expected_results.push_back(ExpectedSplitTextResult{
+    .content = "header line 1",
+    .fragment_index = 5,
+    .fragment_count = 5,
+    .text_line_count = 0
+  });
+
+  runSplitTextTest(input, expected_results, SplitTextProperties{
+    .line_split_count = 2,
+    .trim_trailing_newlines = true,
+    .maximum_fragment_size = 30,
+    .header_line_count = std::nullopt,
+    .header_line_marker_characters = "hea"
+  });
+}
+
+TEST_CASE("If the header defined by header marker characters is larger than the max fragments size then the processor should fail") {
+  std::string input;
+  input = "header line 1\nheader line 2\nthis is a new line\n";
+  const auto split_text = std::make_shared<processors::SplitText>("SplitText");
+  SingleProcessorTestController controller{split_text};
+  split_text->setProperty(processors::SplitText::MaximumFragmentSize, "20 B");
+  split_text->setProperty(processors::SplitText::HeaderLineMarkerCharacters, "hea");
+  split_text->setProperty(processors::SplitText::LineSplitCount, "0");
+  const auto trigger_results = controller.trigger(input, {{std::string(core::SpecialFlowAttribute::FILENAME), "a.foo"}});
+  CHECK(trigger_results.at(processors::SplitText::Splits).empty());
+  REQUIRE(trigger_results.at(processors::SplitText::Original).empty());
+  REQUIRE(trigger_results.at(processors::SplitText::Failure).size() == 1);
+  CHECK(controller.plan->getContent(trigger_results.at(processors::SplitText::Failure)[0]) == input);
+}
+
+TEST_CASE("If the header defined by header marker characters is the only content in the flow file then the processor should not emit new flow files") {
+  std::string input;
+  input = "header line 1\nheader line 2\n";
+  const auto split_text = std::make_shared<processors::SplitText>("SplitText");
+  SingleProcessorTestController controller{split_text};
+  split_text->setProperty(processors::SplitText::MaximumFragmentSize, "40 B");
+  split_text->setProperty(processors::SplitText::HeaderLineMarkerCharacters, "hea");
+  split_text->setProperty(processors::SplitText::LineSplitCount, "0");
+  const auto trigger_results = controller.trigger(input, {{std::string(core::SpecialFlowAttribute::FILENAME), "a.foo"}});
+  CHECK(trigger_results.at(processors::SplitText::Splits).empty());
+  REQUIRE(trigger_results.at(processors::SplitText::Failure).empty());
+  REQUIRE(trigger_results.at(processors::SplitText::Original).size() == 1);
+  CHECK(controller.plan->getContent(trigger_results.at(processors::SplitText::Original)[0]) == input);
+}
+
+TEST_CASE("Header lines should be counted as part of the fragment size when maximum fragment size is specified") {
+  std::vector<ExpectedSplitTextResult> expected_results;
+  std::string input = "[header] hline 1\nline 2\nline 3\n";
+  expected_results.push_back(ExpectedSplitTextResult{
+    .content = "[header] hline 1\nline 2",
+    .fragment_index = 1,
+    .fragment_count = 2,
+    .text_line_count = 1
+  });
+  expected_results.push_back(ExpectedSplitTextResult{
+    .content = "[header] hline 1\nline 3",
+    .fragment_index = 2,
+    .fragment_count = 2,
+    .text_line_count = 1
+  });
+
+  runSplitTextTest(input, expected_results, SplitTextProperties{
+    .line_split_count = 2,
+    .trim_trailing_newlines = true,
+    .maximum_fragment_size = 30,
+    .header_line_count = std::nullopt,
+    .header_line_marker_characters = "[header]"
+  });
+}
+
+}  // namespace org::apache::nifi::minifi::test
diff --git a/libminifi/test/TestBase.cpp b/libminifi/test/TestBase.cpp
index d0d54e608..ff244ba98 100644
--- a/libminifi/test/TestBase.cpp
+++ b/libminifi/test/TestBase.cpp
@@ -674,7 +674,7 @@ std::string TestPlan::getContent(const minifi::core::FlowFile& file) const {
   auto content_stream = content_repo_->read(*content_claim);
   auto output_stream = std::make_shared<minifi::io::BufferStream>();
   minifi::InputStreamPipe{*output_stream}(content_stream);
-  return utils::span_to<std::string>(utils::as_span<const char>(output_stream->getBuffer()));
+  return utils::span_to<std::string>(utils::as_span<const char>(output_stream->getBuffer()).subspan(file.getOffset(), file.getSize()));
 }
 
 TestController::TestController()