nifi-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From markap14 <...@git.apache.org>
Subject [GitHub] nifi pull request #1214: NIFI-2876 refactored demarcators into a common abst...
Date Thu, 23 Feb 2017 14:40:32 GMT
Github user markap14 commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/1214#discussion_r102726151
  
    --- Diff: nifi-commons/nifi-utils/src/main/java/org/apache/nifi/stream/io/util/TextLineDemarcator.java
---
    @@ -95,52 +71,61 @@ public OffsetInfo nextOffsetInfo() {
          *
          * @return offset info
          */
    -    public OffsetInfo nextOffsetInfo(byte[] startsWith) {
    +    public OffsetInfo nextOffsetInfo(byte[] startsWith) throws IOException {
             OffsetInfo offsetInfo = null;
    -        int lineLength = 0;
    -        byte[] token = null;
    -        lineLoop:
    -        while (this.bufferLength != -1) {
    +        byte previousByteVal = 0;
    +        byte[] data = null;
    +        nextTokenLoop: 
    +        while (data == null && this.bufferLength != -1) {
                 if (this.index >= this.bufferLength) {
                     this.fill();
                 }
    +            int delimiterSize = 0;
                 if (this.bufferLength != -1) {
    -                int i;
                     byte byteVal;
    +                int i;
                     for (i = this.index; i < this.bufferLength; i++) {
                         byteVal = this.buffer[i];
    -                    lineLength++;
    -                    int crlfLength = computeEol(byteVal, i + 1);
    -                    if (crlfLength > 0) {
    -                        i += crlfLength;
    -                        if (crlfLength == 2) {
    -                            lineLength++;
    -                        }
    -                        offsetInfo = new OffsetInfo(this.offset, lineLength, crlfLength);
    +
    +                    if (byteVal == 10) {
    +                        delimiterSize = previousByteVal == 13 ? 2 : 1;
    +                    } else if (previousByteVal == 13) {
    +                        delimiterSize = 1;
    +                        i--;
    +                    }
    +                    previousByteVal = byteVal;
    +                    if (delimiterSize > 0) {
    +                        this.index = i + 1;
    +                        int size = Math.max(1, this.index - this.mark);
    +                        offsetInfo = new OffsetInfo(this.offset, size, delimiterSize);
    +                        this.offset += size;
                             if (startsWith != null) {
    -                            token = this.extractDataToken(lineLength);
    +                            data = this.extractDataToken(size);
                             }
                             this.mark = this.index;
    -                        break lineLoop;
    +                        break nextTokenLoop;
                         }
                     }
                     this.index = i;
    +            } else {
    +                delimiterSize = previousByteVal == 13 || previousByteVal == 10 ? 1 :
0;
    +                if (offsetInfo == null) {
    +                    int size = this.index - this.mark;
    +                    if (size > 0) {
    +                        offsetInfo = new OffsetInfo(this.offset, size, delimiterSize);
    +                        this.offset += size;
    +                    }
    +                }
    +                if (startsWith != null) {
    +                    data = this.extractDataToken(this.index - this.mark);
    +                }
                 }
             }
    -        // EOF where last char(s) are not CRLF.
    -        if (lineLength > 0 && offsetInfo == null) {
    -            offsetInfo = new OffsetInfo(this.offset, lineLength, 0);
    -            if (startsWith != null) {
    -                token = this.extractDataToken(lineLength);
    -            }
    -        }
    -        this.offset += lineLength;
     
    -        // checks if the new line starts with 'startsWith' chars
    -        if (startsWith != null) {
    +        if (startsWith != null && data != null) {
                 for (int i = 0; i < startsWith.length; i++) {
                     byte sB = startsWith[i];
    -                if (token != null && sB != token[i]) {
    +                if (data != null && sB != data[i]) {
    --- End diff --
    
    `data` is guaranteed non-null here because it is checked above.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message