emiliosetiadarma commented on code in PR #6054:
URL: https://github.com/apache/nifi/pull/6054#discussion_r876449199
##########
nifi-commons/nifi-flow-encryptor/src/main/java/org/apache/nifi/flow/encryptor/StandardFlowEncryptor.java:
##########
@@ -49,38 +42,27 @@ public class StandardFlowEncryptor implements FlowEncryptor
{
*/
@Override
public void processFlow(final InputStream inputStream, final OutputStream
outputStream, final PropertyEncryptor inputEncryptor, final PropertyEncryptor
outputEncryptor) {
- try (final PrintWriter writer = new PrintWriter(new
OutputStreamWriter(outputStream))) {
- try (final BufferedReader reader = new BufferedReader(new
InputStreamReader(inputStream))) {
- reader.lines().forEach(line -> {
- final Matcher matcher = ENCRYPTED_PATTERN.matcher(line);
-
- final StringBuffer sb = new StringBuffer();
- boolean matched = false;
- while (matcher.find()) {
- final String outputEncrypted =
getOutputEncrypted(matcher.group(FIRST_GROUP), inputEncryptor, outputEncryptor);
- matcher.appendReplacement(sb, outputEncrypted);
- matched = true;
- }
-
- final String outputLine;
- if (matched) {
- matcher.appendTail(sb);
- outputLine = sb.toString();
- } else {
- outputLine = line;
- }
-
- writer.println(outputLine);
- });
+ final BufferedInputStream bufferedInputStream = new
BufferedInputStream(inputStream);
+ if (bufferedInputStream.markSupported()) {
+ final byte[] firstByte = new byte[1];
+ bufferedInputStream.mark(1);
+ try {
+ bufferedInputStream.read(firstByte, 0, 1);
Review Comment:
Making the changes
##########
nifi-commons/nifi-flow-encryptor/src/main/java/org/apache/nifi/flow/encryptor/StandardFlowEncryptor.java:
##########
@@ -49,38 +42,27 @@ public class StandardFlowEncryptor implements FlowEncryptor
{
*/
@Override
public void processFlow(final InputStream inputStream, final OutputStream
outputStream, final PropertyEncryptor inputEncryptor, final PropertyEncryptor
outputEncryptor) {
- try (final PrintWriter writer = new PrintWriter(new
OutputStreamWriter(outputStream))) {
- try (final BufferedReader reader = new BufferedReader(new
InputStreamReader(inputStream))) {
- reader.lines().forEach(line -> {
- final Matcher matcher = ENCRYPTED_PATTERN.matcher(line);
-
- final StringBuffer sb = new StringBuffer();
- boolean matched = false;
- while (matcher.find()) {
- final String outputEncrypted =
getOutputEncrypted(matcher.group(FIRST_GROUP), inputEncryptor, outputEncryptor);
- matcher.appendReplacement(sb, outputEncrypted);
- matched = true;
- }
-
- final String outputLine;
- if (matched) {
- matcher.appendTail(sb);
- outputLine = sb.toString();
- } else {
- outputLine = line;
- }
-
- writer.println(outputLine);
- });
+ final BufferedInputStream bufferedInputStream = new
BufferedInputStream(inputStream);
+ if (bufferedInputStream.markSupported()) {
+ final byte[] firstByte = new byte[1];
+ bufferedInputStream.mark(1);
+ try {
+ bufferedInputStream.read(firstByte, 0, 1);
+ bufferedInputStream.reset();
+ // Flow must be XML or JSON
+ if (firstByte[0] == '<') {
+ final XmlFlowEncryptor flowEncryptor = new
XmlFlowEncryptor();
+ flowEncryptor.processFlow(bufferedInputStream,
outputStream, inputEncryptor, outputEncryptor);
+ } else {
+ final JsonFlowEncryptor flowEncryptor = new
JsonFlowEncryptor();
+ flowEncryptor.processFlow(bufferedInputStream,
outputStream, inputEncryptor, outputEncryptor);
+ }
+ } catch (IOException e) {
+ logger.error(e.getMessage());
+ e.printStackTrace();
Review Comment:
Making the changes
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]