You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2019/04/08 02:58:34 UTC

[GitHub] [nifi] ijokarumawak commented on a change in pull request #3375: NIFI-5979 : enhanced ReplaceText processor with "Number of Occurrences" and "Occurrence offset" configurations

ijokarumawak commented on a change in pull request #3375: NIFI-5979 : enhanced ReplaceText processor with "Number of Occurrences" and "Occurrence offset" configurations
URL: https://github.com/apache/nifi/pull/3375#discussion_r272866399
 
 

 ##########
 File path: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ReplaceText.java
 ##########
 @@ -366,46 +386,40 @@ public void process(final InputStream in, final OutputStream out) throws IOExcep
                     }
                 });
             } else {
-                flowFile = session.write(flowFile, new StreamCallback() {
-                    @Override
-                    public void process(final InputStream in, final OutputStream out) throws IOException {
-                        try (final LineDemarcator demarcator = new LineDemarcator(in, charset, maxBufferSize, 8192);
-                            final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out, charset))) {
-
-                            String line;
-                            while ((line = demarcator.nextLine()) != null) {
-                                // We need to determine what line ending was used and use that after our replacement value.
-                                lineEndingBuilder.setLength(0);
-                                for (int i = line.length() - 1; i >= 0; i--) {
-                                    final char c = line.charAt(i);
-                                    if (c == '\r' || c == '\n') {
-                                        lineEndingBuilder.append(c);
-                                    } else {
-                                        break;
-                                    }
-                                }
-
-                                bw.write(replacementValue);
-
-                                // Preserve original line endings. Reverse string because we iterated over original line ending in reverse order, appending to builder.
-                                // So if builder has multiple characters, they are now reversed from the original string's ordering.
-                                bw.write(lineEndingBuilder.reverse().toString());
-                            }
-                        }
-                    }
-                });
+                flowFile = session.write(flowFile, new StreamReplaceCallback(this, charset, maxBufferSize, context, flowFile,  null));
             }
 
             return flowFile;
         }
 
+        public void replaceInLine(BufferedWriter bw, String oneLine, @Nullable Matcher matcher, @Nullable Pattern searchPattern, ProcessContext context, FlowFile flowFile) throws IOException {
+            final String replacementValue = context.getProperty(REPLACEMENT_VALUE).evaluateAttributeExpressions(flowFile).getValue();
+            final StringBuilder lineEndingBuilder = new StringBuilder(2);
 
 Review comment:
   There are remaining `lineEndingBuilder` in `AlwaysReplace.replace` method which is no longer used. Please remove that.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services