You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by th...@apache.org on 2007/03/07 13:07:16 UTC

svn commit: r515544 - in /webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments: Attachments.java MIMEBodyPartInputStream.java PartOnFile.java PushbackFilePartInputStream.java

Author: thilina
Date: Wed Mar  7 04:07:15 2007
New Revision: 515544

URL: http://svn.apache.org/viewvc?view=rev&rev=515544
Log:
Improving the logic of the Attachment parsing to make it more 
efficient...
Probably this will fix AXIS2-1970

Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Attachments.java
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEBodyPartInputStream.java
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartOnFile.java
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PushbackFilePartInputStream.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=515544&r1=515543&r2=515544
==============================================================================
--- 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 Wed Mar  7 04:07:15 2007
@@ -499,22 +499,24 @@
                     partStream = new MIMEBodyPartInputStream(pushbackInStream,
                                                              boundary, this);
                     int count = 0;
-                    int value;
-                    // Make sure *not* to modify this to a Short Circuit "&". If
-                    // removed a byte will be lost
-                    while (count != fileStorageThreshold
-                           && (!partStream.getBoundaryStatus())) {
-                        value = partStream.read();
-                        buffer[count] = (byte) value;
-                        count++;
-                    }
+                    do {
+                        int len = 0;
+                        int off = 0;
+                        int rem = fileStorageThreshold;
+                        while ((len = partStream.read(buffer, off, rem)) > 0) {
+                            off = off + len;
+                            rem = rem - len;
+                        }
+                        count += off;
+                    } while (partStream.available() > 0);
+                    
                     if (count == fileStorageThreshold) {
                         PushbackFilePartInputStream filePartStream = new PushbackFilePartInputStream(
                                 partStream, buffer);
                         part = new PartOnFile(filePartStream, attachmentRepoDir);
                     } else {
-                        ByteArrayInputStream byteArrayInStream = new ByteArrayInputStream(
-                                buffer, 0, count - 1);
+                        ByteArrayInputStream byteArrayInStream = new ByteArrayInputStream(buffer,
+                                0, count);
                         part = new PartOnMemory(byteArrayInStream);
                     }
                 } catch (Exception e) {

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEBodyPartInputStream.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEBodyPartInputStream.java?view=diff&rev=515544&r1=515543&r2=515544
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEBodyPartInputStream.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEBodyPartInputStream.java Wed Mar  7 04:07:15 2007
@@ -47,7 +47,6 @@
         }
         // read the next value from stream
         int value = inStream.read();
-        
         // A problem occured because all the mime parts tends to have a /r/n at
         // the end. Making it hard to transform them to correct DataSources.
         // This logic introduced to handle it
@@ -104,10 +103,5 @@
         inStream.unread(boundary, 0, boundaryIndex);
         inStream.unread(10);
         return 13;
-    }
-    
-    public boolean getBoundaryStatus()
-    {
-        return boundaryFound;
     }
 }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartOnFile.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartOnFile.java?view=diff&rev=515544&r1=515543&r2=515544
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartOnFile.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartOnFile.java Wed Mar  7 04:07:15 2007
@@ -32,6 +32,7 @@
 import javax.mail.MessagingException;
 
 import org.apache.axiom.om.OMException;
+import org.apache.axiom.om.util.Base64;
 
 public class PartOnFile implements Part {
 
@@ -47,39 +48,37 @@
 
     public PartOnFile(PushbackFilePartInputStream inStream, String repoDir) {
         super();
-
+        
         headers = new Hashtable();
-
+        
         if (repoDir == null) {
             repoDir = ".";
         }
         try {
-        	File repoDirFile = null; 
-        	if (repoDir!=null)
-        	{
-        		repoDirFile= new File(repoDir);
-        		if (!repoDirFile.exists())
-        		{
-					repoDirFile.mkdirs();
-				}
-        	}
-        	if (!repoDirFile.isDirectory()){
-        		throw new IllegalArgumentException("Given Axis2 Attachment File Cache Location "+repoDir+"  should be a directory.");
-        	}
-            cacheFile = File.createTempFile("Axis2", ".att",
-                    repoDirFile);
-
+            File repoDirFile = null;
+            if (repoDir != null) {
+                repoDirFile = new File(repoDir);
+                if (!repoDirFile.exists()) {
+                    repoDirFile.mkdirs();
+                }
+            }
+            if (!repoDirFile.isDirectory()) {
+                throw new IllegalArgumentException("Given Axis2 Attachment File Cache Location "
+                        + repoDir + "  should be a directory.");
+            }
+            cacheFile = File.createTempFile("Axis2", ".att", repoDirFile);
+            
             FileOutputStream fileOutStream = new FileOutputStream(cacheFile);
             int value;
             value = parseTheHeaders(inStream);
             fileOutStream.write(value);
-            while (!inStream.getBoundaryStatus()) {
-                value = inStream.read();
-                if (!inStream.getBoundaryStatus()) {
-                    fileOutStream.write(value);
+            do {
+                byte[] buffer = new byte[4000];
+                int len;
+                while ((len = inStream.read(buffer)) > 0) {
+                    fileOutStream.write(buffer, 0, len);
                 }
-            }
-
+            } while (inStream.available() > 0);
             fileOutStream.flush();
             fileOutStream.close();
         } catch (IOException e) {

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PushbackFilePartInputStream.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PushbackFilePartInputStream.java?view=diff&rev=515544&r1=515543&r2=515544
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PushbackFilePartInputStream.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PushbackFilePartInputStream.java Wed Mar  7 04:07:15 2007
@@ -42,7 +42,9 @@
     public int read() throws IOException {
         int data;
         if (count > 0) {
-            data = buffer[buffer.length - count];
+            byte byteValue = buffer[buffer.length - count];
+            // converting the byte to unsigned int value
+            data = byteValue & 0xff;
             count--;
         } else {
             data = inStream.read();
@@ -50,9 +52,31 @@
         return data;
     }
     
-    public boolean getBoundaryStatus()
-    {
-        return inStream.getBoundaryStatus();
+    public int read(byte b[], int off, int len) throws IOException {
+        if (count > 0) {
+            if (b == null) {
+                throw new NullPointerException();
+            } else if ((off < 0) || (off > b.length) || (len < 0) || ((off + len) > b.length)
+                    || ((off + len) < 0)) {
+                throw new IndexOutOfBoundsException();
+            } else if (len == 0) {
+                return 0;
+            }
+            int bytesCopied;
+            if (count < len) {
+                System.arraycopy(buffer, (buffer.length - count), b, off, count);
+                bytesCopied = count;
+                count=0;
+                return bytesCopied;
+            }
+            System.arraycopy(buffer, (buffer.length - count), b, off, len);
+            count -= len;
+            return len;
+        }
+        return inStream.read(b, off, len);
+    }
+    
+    public int available() throws IOException {
+        return count+inStream.available();
     }
-
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: commons-dev-help@ws.apache.org