Author: lindner
Date: Thu Jan 15 12:12:59 2009
New Revision: 734793

URL: http://svn.apache.org/viewvc?rev=734793&view=rev
Log:
SHINDIG-695 | Patch from Zsolt Bányai |  HttpResponse's externalizable 
implementation not works on Linux/Unix systems

Modified:
    
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/HttpResponse.java

Modified: 
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/HttpResponse.java
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/HttpResponse.java?rev=734793&r1=734792&r2=734793&view=diff
==============================================================================
--- 
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/HttpResponse.java
 (original)
+++ 
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/HttpResponse.java
 Thu Jan 15 12:12:59 2009
@@ -502,16 +502,23 @@
    */
   @SuppressWarnings("unchecked")
   public void readExternal(ObjectInput in) throws IOException, 
ClassNotFoundException {
-    httpStatusCode = in.readInt();
-    Map<String, List<String>> headerCopy = (Map<String, 
List<String>>)in.readObject();
-    int bodyLength = in.readInt();
-    responseBytes = new byte[bodyLength];
-    in.read(responseBytes, 0, bodyLength);
+    httpStatusCode = in.readInt(); 
+    Map<String, List<String>> headerCopy = (Map<String, 
List<String>>)in.readObject(); 
+    int bodyLength = in.readInt(); 
+    responseBytes = new byte[bodyLength]; 
+    int cnt, offset = 0; 
+    while ((cnt = in.read(responseBytes, offset, bodyLength)) > 0) { 
+        offset += cnt; 
+        bodyLength -= cnt; 
+    } 
+    if (offset != responseBytes.length) { 
+       throw new IOException("Invalid body! Expected length = " + 
responseBytes.length + ", bytes readed = " + offset + "."); 
+    } 
 
-    date = getAndUpdateDate(headerCopy);
-    encoding = getAndUpdateEncoding(headerCopy, responseBytes);
-    headers = Collections.unmodifiableMap(headerCopy);
-    metadata = Collections.emptyMap();
+    date = getAndUpdateDate(headerCopy); 
+    encoding = getAndUpdateEncoding(headerCopy, responseBytes); 
+    headers = Collections.unmodifiableMap(headerCopy); 
+    metadata = Collections.emptyMap(); 
   }
 
   public void writeExternal(ObjectOutput out) throws IOException {


Reply via email to