You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by ch...@apache.org on 2014/10/09 16:50:01 UTC

[9/9] git commit: Revert input stream splitting

Revert input stream splitting

Signed-off-by: Christian Amend <ch...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata2/commit/8dfd515e
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata2/tree/8dfd515e
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata2/diff/8dfd515e

Branch: refs/heads/olingo436BatchRefactoring
Commit: 8dfd515e89e1ddf0ec91f347264bb4be9144c6d3
Parents: dbaa667
Author: Christian Holzer <c....@sap.com>
Authored: Thu Oct 9 16:31:23 2014 +0200
Committer: Christian Amend <ch...@apache.org>
Committed: Thu Oct 9 16:45:27 2014 +0200

----------------------------------------------------------------------
 .../odata2/core/batch/v2/BatchParser.java       | 14 ++++-
 .../odata2/core/batch/v2/BatchParserCommon.java | 56 --------------------
 2 files changed, 13 insertions(+), 57 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/8dfd515e/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/v2/BatchParser.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/v2/BatchParser.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/v2/BatchParser.java
index bf4ce93..09bf987 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/v2/BatchParser.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/v2/BatchParser.java
@@ -20,6 +20,7 @@ package org.apache.olingo.odata2.core.batch.v2;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.InputStreamReader;
 import java.util.LinkedList;
 import java.util.List;
 
@@ -80,7 +81,7 @@ public class BatchParser {
     final String baseUri = getBaseUri();
     final String boundary = BatchParserCommon.getBoundary(contentTypeMime, 1);
     final List<BatchParserResult> resultList = new LinkedList<BatchParserResult>();
-    final List<List<Line>> bodyPartStrings = BatchParserCommon.splitRequestByBoundary(in, boundary);
+    final List<List<Line>> bodyPartStrings = splitBodyParts(in, boundary);
 
     for (List<Line> bodyPartString : bodyPartStrings) {
       BatchBodyPart bodyPart = new BatchBodyPart(bodyPartString, boundary, isStrict).parse();
@@ -89,6 +90,17 @@ public class BatchParser {
 
     return resultList;
   }
+  
+  private List<List<Line>> splitBodyParts(final InputStream in, final String boundary)
+      throws IOException, BatchException {
+
+    final BufferedReaderIncludingLineEndings reader = new BufferedReaderIncludingLineEndings(new InputStreamReader(in));
+    final List<Line> message = reader.toList();
+    reader.close();
+
+    return BatchParserCommon.splitMessageByBoundary(message, boundary);
+  }
+
 
   private String getBaseUri() throws BatchException {
     String baseUri = "";

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/8dfd515e/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/v2/BatchParserCommon.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/v2/BatchParserCommon.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/v2/BatchParserCommon.java
index 5c6cd69..cac340e 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/v2/BatchParserCommon.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/v2/BatchParserCommon.java
@@ -19,9 +19,7 @@
 package org.apache.olingo.odata2.core.batch.v2;
 
 import java.io.ByteArrayInputStream;
-import java.io.IOException;
 import java.io.InputStream;
-import java.io.InputStreamReader;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.ArrayList;
@@ -93,60 +91,6 @@ public class BatchParserCommon {
     return new ByteArrayInputStream(message.getBytes());
   }
 
-  static List<List<Line>> splitRequestByBoundary(final InputStream in, final String boundary)
-      throws BatchException, IOException {
-    final List<List<Line>> messageParts = new LinkedList<List<Line>>();
-    List<Line> currentPart = new ArrayList<Line>();
-    boolean isEndReached = false;
-
-    final String quotedBoundary = Pattern.quote(boundary);
-    final Pattern boundaryDelimiterPattern = Pattern.compile("--" + quotedBoundary + "--[\\s ]*");
-    final Pattern boundaryPattern = Pattern.compile("--" + quotedBoundary + "[\\s ]*");
-
-    final BufferedReaderIncludingLineEndings reader = new BufferedReaderIncludingLineEndings(new InputStreamReader(in));
-    String currentLine;
-    int lineNumber = 1;
-
-    while ((currentLine = reader.readLine()) != null) {
-      if (boundaryDelimiterPattern.matcher(currentLine.toString()).matches()) {
-        removeEndingCRLFFromList(currentPart);
-        messageParts.add(currentPart);
-        isEndReached = true;
-      } else if (boundaryPattern.matcher(currentLine.toString()).matches()) {
-        removeEndingCRLFFromList(currentPart);
-        messageParts.add(currentPart);
-        currentPart = new LinkedList<Line>();
-      } else {
-        currentPart.add(new Line(currentLine, lineNumber));
-      }
-
-      if (isEndReached) {
-        break;
-      }
-
-      lineNumber++;
-    }
-    reader.close();
-
-    // Remove preamble
-    if (messageParts.size() > 0) {
-      messageParts.remove(0);
-    } else {
-
-      throw new BatchException(BatchException.MISSING_BOUNDARY_DELIMITER.addContent(1));
-    }
-
-    if (!isEndReached) {
-      throw new BatchException(BatchException.MISSING_CLOSE_DELIMITER.addContent(1));
-    }
-
-    if (messageParts.size() == 0) {
-      throw new BatchException(BatchException.NO_MATCH_WITH_BOUNDARY_STRING.addContent(boundary).addContent(0));
-    }
-
-    return messageParts;
-  }
-
   static List<List<Line>> splitMessageByBoundary(final List<Line> message, final String boundary)
       throws BatchException {
     final List<List<Line>> messageParts = new LinkedList<List<Line>>();