]> source.dussan.org Git - vaadin-framework.git/commitdiff
Merged fix for #2847 - Problem running on Oracle OAS10g
authorArtur Signell <artur.signell@itmill.com>
Thu, 16 Apr 2009 06:01:59 +0000 (06:01 +0000)
committerArtur Signell <artur.signell@itmill.com>
Thu, 16 Apr 2009 06:01:59 +0000 (06:01 +0000)
svn changeset:7430/svn branch:6.0

src/com/itmill/toolkit/terminal/gwt/server/CommunicationManager.java

index cd4fcae766355a28f829b854904d0ea7e5f990d1..cfedb42dc4edbf3db29b9e9e49360892967d74a7 100644 (file)
@@ -612,17 +612,7 @@ public class CommunicationManager implements Paintable.RepaintRequestListener,
         boolean success = true;
 
         if (request.getContentLength() > 0) {
-
-            byte[] buffer = new byte[request.getContentLength()];
-            ServletInputStream inputStream = request.getInputStream();
-            int totalBytesRead = 0;
-            int bytesRead;
-            while ((bytesRead = inputStream.read(buffer, totalBytesRead,
-                    MAX_BUFFER_SIZE)) != -1) {
-                totalBytesRead += bytesRead;
-            }
-
-            String changes = new String(buffer, "utf-8");
+            String changes = readRequest(request);
 
             // Manage bursts one by one
             final String[] bursts = changes.split(VAR_BURST_SEPARATOR);
@@ -780,6 +770,39 @@ public class CommunicationManager implements Paintable.RepaintRequestListener,
         return success;
     }
 
+    /**
+     * Reads the request data from the HttpServletRequest and returns it
+     * converted to an UTF-8 string.
+     * 
+     * @param request
+     * @return
+     * @throws IOException
+     */
+    private static String readRequest(HttpServletRequest request)
+            throws IOException {
+
+        int requestLength = request.getContentLength();
+
+        byte[] buffer = new byte[requestLength];
+        ServletInputStream inputStream = request.getInputStream();
+
+        int bytesRemaining = requestLength;
+        while (bytesRemaining >= 0) {
+            int bytesToRead = Math.min(bytesRemaining, MAX_BUFFER_SIZE);
+            int bytesRead = inputStream.read(buffer, requestLength
+                    - bytesRemaining, bytesToRead);
+            if (bytesRead == -1) {
+                break;
+            }
+
+            bytesRemaining -= bytesRead;
+        }
+
+        String result = new String(buffer, "utf-8");
+
+        return result;
+    }
+
     public class ErrorHandlerErrorEvent implements ErrorEvent, Serializable {
         private final Throwable throwable;