You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by ma...@apache.org on 2018/10/17 14:58:29 UTC

[1/2] nifi git commit: NIFI-5711 NLKBufferedReader appears extend and copy portions of the JDK BufferedReader

Repository: nifi
Updated Branches:
  refs/heads/master 87c6b3aa7 -> d6422e2d2


NIFI-5711 NLKBufferedReader appears extend and copy portions of the JDK BufferedReader


Project: http://git-wip-us.apache.org/repos/asf/nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/95e42946
Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/95e42946
Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/95e42946

Branch: refs/heads/master
Commit: 95e42946738fb4875e66ef80755d1a668df45954
Parents: 87c6b3a
Author: patricker <pa...@gmail.com>
Authored: Tue Oct 16 15:56:55 2018 -0600
Committer: Mark Payne <ma...@hotmail.com>
Committed: Wed Oct 17 10:57:53 2018 -0400

----------------------------------------------------------------------
 .../standard/util/NLKBufferedReader.java        | 146 ++++---------------
 1 file changed, 27 insertions(+), 119 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi/blob/95e42946/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/util/NLKBufferedReader.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/util/NLKBufferedReader.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/util/NLKBufferedReader.java
index d2e56c5..7193a1b 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/util/NLKBufferedReader.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/util/NLKBufferedReader.java
@@ -22,18 +22,6 @@ import java.io.Reader;
 
 //NLKBufferedReader = New Line Keeper Buffered Reader
 public class NLKBufferedReader extends BufferedReader {
-
-    private Reader in;
-    private char cb[];
-    private int nChars, nextChar;
-    private static final int INVALIDATED = -2;
-    private static final int UNMARKED = -1;
-    private int markedChar = UNMARKED;
-    private int readAheadLimit = 0; /* Valid only when markedChar > 0 */
-
-    private static int defaultCharBufferSize = 8192;
-    private static int defaultExpectedLineLength = 80;
-
     /**
      * Creates a buffering character-input stream that uses an input buffer of the specified size.
      *
@@ -44,18 +32,16 @@ public class NLKBufferedReader extends BufferedReader {
      */
     public NLKBufferedReader(Reader in, int sz) {
         super(in, sz);
-        this.in = in;
-        cb = new char[sz];
-        nextChar = nChars = 0;
     }
 
     /**
      * Creates a buffering character-input stream that uses a default-sized input buffer.
      *
      * @param in A Reader
+     *
      */
     public NLKBufferedReader(Reader in) {
-        this(in, defaultCharBufferSize);
+        super(in);
     }
 
     /**
@@ -67,115 +53,37 @@ public class NLKBufferedReader extends BufferedReader {
      */
     @Override
     public String readLine() throws IOException {
-        StringBuffer s = null;
-        int startChar;
-
-        synchronized (lock) {
-            ensureOpen();
-
-            bufferLoop:
-            for (;;) {
-
-                if (nextChar >= nChars) {
-                    fill();
-                }
-                if (nextChar >= nChars) { /* EOF */
-
-                    if (s != null && s.length() > 0) {
-                        return s.toString();
-                    } else {
-                        return null;
-                    }
-                }
-                boolean eol = false;
-                char c = 0;
-                int i;
-
-                charLoop:
-                for (i = nextChar; i < nChars; i++) {
-                    c = cb[i];
-                    if ((c == '\n') || (c == '\r')) {
-                        if ((c == '\r') && (cb.length > i + 1) && cb[i + 1] == '\n') { // windows case '\r\n' here verify the next character i+1
-                            i++;
-                        }
-                        eol = true;
-                        break charLoop;
-                    }
-                }
-
-                startChar = nextChar;
-                nextChar = i;
-
-                if (eol) {
-                    String str;
-                    if (s == null) {
-                        str = new String(cb, startChar, (i + 1) - startChar);
-                    } else {
-                        s.append(cb, startChar, (i + 1) - startChar);
-                        str = s.toString();
-                    }
-                    nextChar++;
-                    return str;
+        StringBuilder stringBuilder = new StringBuilder();
+
+        int intchar = read();
+        while(intchar != -1){
+            char c = (char) intchar;
+            stringBuilder.append(c);
+
+            if(c == '\n') {
+                break;
+            } else if(c == '\r'){
+                // Peek at next character, check if it's \n
+                int charPeek = peek();
+                if(charPeek != -1 && (char)charPeek=='\n'){
+                    stringBuilder.append((char)read());
                 }
-
-                if (s == null) {
-                    s = new StringBuffer(defaultExpectedLineLength);
-                }
-                s.append(cb, startChar, i - startChar);
+                break;
             }
-        }
-    }
 
-    /**
-     * Checks to make sure that the stream has not been closed
-     */
-    private void ensureOpen() throws IOException {
-        if (in == null) {
-            throw new IOException("Stream closed");
+            intchar = read();
         }
+
+        String result = stringBuilder.toString();
+
+        return result.length()==0?null:result;
     }
 
-    /**
-     * Fills the input buffer, taking the mark into account if it is valid.
-     */
-    private void fill() throws IOException {
-        int dst;
-        if (markedChar <= UNMARKED) {
-            /* No mark */
-            dst = 0;
-        } else {
-            /* Marked */
-            int delta = nextChar - markedChar;
-            if (delta >= readAheadLimit) {
-                /* Gone past read-ahead limit: Invalidate mark */
-                markedChar = INVALIDATED;
-                readAheadLimit = 0;
-                dst = 0;
-            } else {
-                if (readAheadLimit <= cb.length) {
-                    /* Shuffle in the current buffer */
-                    System.arraycopy(cb, markedChar, cb, 0, delta);
-                    markedChar = 0;
-                    dst = delta;
-                } else {
-                    /* Reallocate buffer to accommodate read-ahead limit */
-                    char ncb[] = new char[readAheadLimit];
-                    System.arraycopy(cb, markedChar, ncb, 0, delta);
-                    cb = ncb;
-                    markedChar = 0;
-                    dst = delta;
-                }
-                nextChar = nChars = delta;
-            }
-        }
+    public int peek() throws IOException {
+        mark(1);
+        int readByte = read();
+        reset();
 
-        int n;
-        do {
-            n = in.read(cb, dst, cb.length - dst);
-        } while (n == 0);
-        if (n > 0) {
-            nChars = dst + n;
-            nextChar = dst;
-        }
+        return readByte;
     }
 }


[2/2] nifi git commit: NIFI-5711: Replaced JavaDocs that appear also to be copied/pasted from BufferedReader, ran IDE code formatter to get consistent whitespace/formatting

Posted by ma...@apache.org.
NIFI-5711: Replaced JavaDocs that appear also to be copied/pasted from BufferedReader, ran IDE code formatter to get consistent whitespace/formatting

This closes #3085.

Signed-off-by: Mark Payne <ma...@hotmail.com>


Project: http://git-wip-us.apache.org/repos/asf/nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/d6422e2d
Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/d6422e2d
Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/d6422e2d

Branch: refs/heads/master
Commit: d6422e2d2caf855125583455e3c97496e66cc964
Parents: 95e4294
Author: Mark Payne <ma...@hotmail.com>
Authored: Wed Oct 17 10:57:38 2018 -0400
Committer: Mark Payne <ma...@hotmail.com>
Committed: Wed Oct 17 10:57:57 2018 -0400

----------------------------------------------------------------------
 .../standard/util/NLKBufferedReader.java        | 41 +++++++-------------
 1 file changed, 14 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi/blob/d6422e2d/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/util/NLKBufferedReader.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/util/NLKBufferedReader.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/util/NLKBufferedReader.java
index 7193a1b..df8847f 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/util/NLKBufferedReader.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/util/NLKBufferedReader.java
@@ -22,61 +22,48 @@ import java.io.Reader;
 
 //NLKBufferedReader = New Line Keeper Buffered Reader
 public class NLKBufferedReader extends BufferedReader {
-    /**
-     * Creates a buffering character-input stream that uses an input buffer of the specified size.
-     *
-     * @param in A Reader
-     * @param sz Input-buffer size
-     *
-     * @exception IllegalArgumentException If sz is <= 0
-     */
     public NLKBufferedReader(Reader in, int sz) {
         super(in, sz);
     }
 
-    /**
-     * Creates a buffering character-input stream that uses a default-sized input buffer.
-     *
-     * @param in A Reader
-     *
-     */
     public NLKBufferedReader(Reader in) {
         super(in);
     }
 
     /**
-     * Reads a line of text. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed.
+     * Reads a line of text in the same manner as {@link BufferedReader} except that any line-termination characters (\r and \n) are preserved in the String
+     * that is returned from this reader, whereas {@link BufferedReader} will strip those out.
      *
-     * @return A String containing the contents of the line, including any line-termination characters, or null if the end of the stream has been reached
+     * @return A String containing the next line of text (including any line-termination characters) from the underlying Reader, or null if no more data is available
      *
-     * @exception IOException If an I/O error occurs
+     * @throws IOException If unable to read from teh underlying Reader
      */
     @Override
     public String readLine() throws IOException {
-        StringBuilder stringBuilder = new StringBuilder();
+        final StringBuilder stringBuilder = new StringBuilder();
 
         int intchar = read();
-        while(intchar != -1){
-            char c = (char) intchar;
+        while (intchar != -1) {
+            final char c = (char) intchar;
             stringBuilder.append(c);
 
-            if(c == '\n') {
+            if (c == '\n') {
                 break;
-            } else if(c == '\r'){
+            } else if (c == '\r') {
                 // Peek at next character, check if it's \n
                 int charPeek = peek();
-                if(charPeek != -1 && (char)charPeek=='\n'){
-                    stringBuilder.append((char)read());
+                if (charPeek == '\n') {
+                    stringBuilder.append((char) read());
                 }
+
                 break;
             }
 
             intchar = read();
         }
 
-        String result = stringBuilder.toString();
-
-        return result.length()==0?null:result;
+        final String result = stringBuilder.toString();
+        return (result.length() == 0) ? null : result;
     }
 
     public int peek() throws IOException {