Author: scheu
Date: Thu Jul 12 13:13:10 2007
New Revision: 555743

URL: http://svn.apache.org/viewvc?view=rev&rev=555743
Log:
JIRA AXIS2-2946
Contributor:Rich Scheuerle
Upgrade the buffer read logic to be super safe.  

Modified:
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Attachments.java

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Attachments.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Attachments.java?view=diff&rev=555743&r1=555742&r2=555743
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Attachments.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Attachments.java
 Thu Jul 12 13:13:10 2007
@@ -570,10 +570,8 @@
                                                         boundary,
                                                         this,
                                                         PUSHBACK_SIZE);
-                        int count = 0;
-                        int value;
-                        count = partStream.read(buffer);
-                        
+                        int count = readToBuffer(partStream, buffer);
+                  
                         if (count == fileStorageThreshold) {
                             if (log.isDebugEnabled()) {
                                 log.debug("The calculated attachment size is " 
+ count + ". Storing Part in file.");
@@ -605,5 +603,25 @@
         }
         partIndex++;
         return part;
+    }
+    
+    /**
+     * Read bytes into the buffer until full or until the EOS
+     * @param is
+     * @param buffer
+     * @return number of bytes read
+     * @throws IOException
+     */
+    private static int readToBuffer(InputStream is, byte[] buffer) throws 
IOException {
+        int index = 0;
+        int remainder = buffer.length;
+        do {
+            int bytesRead;
+            while ((bytesRead = is.read(buffer, index, remainder)) > 0) {
+                index += bytesRead;
+                remainder -= bytesRead;
+            }
+        } while (remainder > 0 && is.available() > 0);  // repeat if more 
bytes are now available
+        return index;
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to