Github user markap14 commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/280#discussion_r56329501
  
    --- Diff: 
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/SplitText.java
 ---
    @@ -143,72 +199,82 @@ protected void init(final 
ProcessorInitializationContext context) {
             return properties;
         }
     
    -    private int readLines(final InputStream in, final int maxNumLines, 
final OutputStream out, final boolean keepAllNewLines) throws IOException {
    +    private int readLines(final InputStream in, final int maxNumLines, 
final long maxByteCount, final OutputStream out) throws IOException {
             int numLines = 0;
    +        long totalBytes = 0L;
             for (int i = 0; i < maxNumLines; i++) {
    -            final long bytes = countBytesToSplitPoint(in, out, 
keepAllNewLines || (i != maxNumLines - 1));
    +            final long bytes = countBytesToSplitPoint(in, out, totalBytes, 
maxByteCount);
    +            totalBytes += bytes;
                 if (bytes <= 0) {
                     return numLines;
                 }
    -
                 numLines++;
    +            if (totalBytes >= maxByteCount && numLines > maxNumLines) {
    +                break;
    +            }
             }
    -
             return numLines;
         }
     
    -    private long countBytesToSplitPoint(final InputStream in, final 
OutputStream out, final boolean includeLineDelimiter) throws IOException {
    -        int lastByte = -1;
    +    private long countBytesToSplitPoint(final InputStream in, final 
OutputStream out, final long bytesReadSoFar, final long maxSize) throws 
IOException {
             long bytesRead = 0L;
    +        final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    --- End diff --
    
    It looks like we always buffer this data into Java heap, but we don't 
actually use it for anything if out == null (which is the case more often than 
not, I believe). This is pretty concerning, as we should avoid buffering 
potentially large amounts of data into Java heap unless absolutely necessary. I 
think this needs to be reworked so that we don't buffer the data here, if out 
== null, since we won't make use of it anyway.


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to