You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ra...@apache.org on 2015/01/29 12:45:53 UTC

[4/6] git commit: updated refs/heads/volume-upload to e08522d

volume upload: modified parsing logic

vhd file download works fine. some open issues with parsing params


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

Branch: refs/heads/volume-upload
Commit: 92669e314e4fdd4f8764d728e988cb00acb018b1
Parents: 89ef9e7
Author: Rajani Karuturi <ra...@gmail.com>
Authored: Fri Jan 23 10:34:41 2015 +0530
Committer: Rajani Karuturi <ra...@gmail.com>
Committed: Thu Jan 29 16:55:28 2015 +0530

----------------------------------------------------------------------
 .../resource/NfsSecondaryStorageResource.java   | 63 ++++++++++++++------
 1 file changed, 45 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/92669e31/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
----------------------------------------------------------------------
diff --git a/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java b/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
index 6ad7df5..5227659 100755
--- a/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
+++ b/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
@@ -2848,26 +2848,35 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
             return null;
         }
 
-        private void parsePostBody(InputStream input, OutputStream output, Map<String, String> params) throws IOException {
-            BufferedReader reader = new BufferedReader(new InputStreamReader(input));
-            String currentLine = reader.readLine();
-            String boundary = currentLine;
+        private void parsePostBody(ByteArrayInputStream input, OutputStream output, Map<String, String> params) throws IOException {
 
-            while(reader.ready()) {
+            byte [] bytebuf = new byte[4096];
+            input.read(bytebuf,0,1024);
+
+            BufferedReader reader = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(bytebuf)));
+            int readBytes=0;
+            String boundary =reader.readLine();
+            readBytes+=boundary.length()+2;
+            String currentLine =null;
+
+            while (reader.ready()) {
                 currentLine = reader.readLine();
+                readBytes+=currentLine.length()+2;
                 if (currentLine.contains("Content-Disposition: form-data;")) {
                     String paramName = currentLine;
-                    paramName = paramName.replace("Content-Disposition: form-data; name=","").replace("\"","");
+                    paramName = paramName.replace("Content-Disposition: form-data; name=", "").replace("\"", "");
                     StringBuilder paramValue = new StringBuilder();
-                    if(paramName.contains("filename")) {
+                    if (paramName.contains("filename")) {
                         String[] temp = paramName.split(";");
                         paramName = temp[0];
                         paramValue.append(temp[1].replace("filename", "").replace("=", "").replace(" ", ""));
                     } else {
                         currentLine = reader.readLine();
-                        while(!currentLine.contains(boundary)) {
+                        readBytes+=currentLine.length()+2;
+                        while (!currentLine.contains(boundary)) {
                             paramValue.append(currentLine);
                             currentLine = reader.readLine();
+                            readBytes+=currentLine.length()+2;
                         }
                     }
                     params.put(paramName, paramValue.toString());
@@ -2876,20 +2885,38 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
                     // File Content here
                     reader.readLine();
 
-                    String prevLine = reader.readLine();
-                    currentLine = reader.readLine();
+                    readBytes+=2;
 
-                    //writing the data to a output stream
+                    input.reset();
+                    input.skip(readBytes);
+                    int read=0;
                     while (true) {
-                        if (currentLine.contains(boundary)) {
-                            output.write(prevLine.getBytes());
+                        read=input.read(bytebuf,0,1024);
+                        if (read == -1) {
+                            break;
+                        }
+                        readBytes+=read;
+                        String stringBuf= new String(bytebuf);
+                        if (stringBuf.contains(boundary)) {
+                            int i=0;
+                            while (!(bytebuf[i] == '\r' && bytebuf[i+1] == '\n')) {
+                                output.write(bytebuf[i]);
+                                i++;
+                            }
                             break;
                         }
-                        else {
-                            output.write(currentLine.getBytes());
+                        if (stringBuf.contains("-")) {
+                            int i=0;
+                            while (bytebuf[i] != '-') {
+                                output.write(bytebuf[i]);
+                                i++;
+                            }
+                            readBytes+=i;
+                            input.reset();
+                            input.skip(readBytes);
+                        } else {
+                            output.write(bytebuf,0,1024);
                         }
-                        prevLine = currentLine;
-                        currentLine = reader.readLine();
                     }
 
                 }
@@ -2912,7 +2939,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
                 data = EntityUtils.toByteArray(entity);
             }
 
-            InputStream inputStream = new ByteArrayInputStream(data);
+            ByteArrayInputStream inputStream = new ByteArrayInputStream(data);
             ByteArrayOutputStream output = new ByteArrayOutputStream();
             HashMap<String, String> params = new HashMap<>();