ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maart...@apache.org
Subject svn commit: r995589 - in /ant/ivy/core/trunk: CHANGES.txt src/java/org/apache/ivy/util/FileUtil.java src/java/org/apache/ivy/util/url/HttpClientHandler.java
Date Thu, 09 Sep 2010 22:04:54 GMT
Author: maartenc
Date: Thu Sep  9 22:04:54 2010
New Revision: 995589

URL: http://svn.apache.org/viewvc?rev=995589&view=rev
Log:
FIX: New attempt to fix the OutOfMemoryError when uploading large files using commons-httpclient
(IVY-1197) (thanks to Torkild U. Resheim)

Modified:
    ant/ivy/core/trunk/CHANGES.txt
    ant/ivy/core/trunk/src/java/org/apache/ivy/util/FileUtil.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/util/url/HttpClientHandler.java

Modified: ant/ivy/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/CHANGES.txt?rev=995589&r1=995588&r2=995589&view=diff
==============================================================================
--- ant/ivy/core/trunk/CHANGES.txt (original)
+++ ant/ivy/core/trunk/CHANGES.txt Thu Sep  9 22:04:54 2010
@@ -88,6 +88,7 @@ for detailed view of each issue, please 
 	Carl Quinn
 	Damon Rand
 	Geoff Reedy
+	Torkild U. Resheim
 	Christian Riege
 	Andreas Sahlbach
 	Brian Sanders
@@ -125,7 +126,7 @@ for detailed view of each issue, please 
 - IMPROVEMENT: ivy:makepom now accepts a list of configurations to include (IVY-1005) (thanks
to Jesper Pedersen)
 - IMPROVEMENT: ivy:makepom can generate a <description> element in the pom (IVY-1215)
(thanks to Jesper Pedersen)
 
-- FIX: OutOfMemoryError when uploading large files using commons-httpclient (IVY-1197)
+- FIX: OutOfMemoryError when uploading large files using commons-httpclient (IVY-1197) (thanks
to Torkild U. Resheim)
 - FIX: artifactreport ant task doesn't honor log attribute (IVY-1212)
 - FIX: XmlModuleDescriptorWriter does not write the transitive attribute (IVY-1207) (thanks
to Abel Muino)
 - FIX: Ivy info/extends/extendsType attribute is misspelled by XmlModuleDescriptorWriter
(IVY-1203) (thanks to Jason Trump)

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/util/FileUtil.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/util/FileUtil.java?rev=995589&r1=995588&r2=995589&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/util/FileUtil.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/util/FileUtil.java Thu Sep  9 22:04:54 2010
@@ -155,7 +155,12 @@ public final class FileUtil {
         copy(src, new FileOutputStream(dest), l);
     }
 
-    public static void copy(InputStream src, OutputStream dest, CopyProgressListener l)
+    public static void copy(InputStream src, OutputStream dest, CopyProgressListener l) 
+            throws IOException {
+        copy(src, dest, l, true);
+    }
+    
+    public static void copy(InputStream src, OutputStream dest, CopyProgressListener l, boolean
autoClose)
             throws IOException {
         CopyProgressEvent evt = null;
         if (l != null) {
@@ -191,18 +196,22 @@ public final class FileUtil {
             }
 
             // close the streams
-            src.close();
-            dest.close();
-        } finally {
-            try {
+            if (autoClose) {
                 src.close();
-            } catch (IOException ex) {
-                // ignore
-            }
-            try {
                 dest.close();
-            } catch (IOException ex) {
-                // ignore
+            }
+        } finally {
+            if (autoClose) {
+                try {
+                    src.close();
+                } catch (IOException ex) {
+                    // ignore
+                }
+                try {
+                    dest.close();
+                } catch (IOException ex) {
+                    // ignore
+                }
             }
         }
 

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/util/url/HttpClientHandler.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/util/url/HttpClientHandler.java?rev=995589&r1=995588&r2=995589&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/util/url/HttpClientHandler.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/util/url/HttpClientHandler.java Thu Sep  9
22:04:54 2010
@@ -21,6 +21,7 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
 import java.net.URL;
 import java.net.UnknownHostException;
 import java.text.ParseException;
@@ -46,6 +47,7 @@ import org.apache.commons.httpclient.met
 import org.apache.commons.httpclient.methods.HeadMethod;
 import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
 import org.apache.commons.httpclient.methods.PutMethod;
+import org.apache.commons.httpclient.methods.RequestEntity;
 import org.apache.commons.httpclient.params.HttpMethodParams;
 import org.apache.ivy.Ivy;
 import org.apache.ivy.util.CopyProgressListener;
@@ -130,20 +132,11 @@ public class HttpClientHandler extends A
 
         PutMethod put = new PutMethod(normalizeToString(dest));
         put.setDoAuthentication(useAuthentication(dest) || useProxyAuthentication());
-        FileInputStream fileStream = null;
         try {
-            fileStream = new FileInputStream(src);
-            put.setRequestEntity(new InputStreamRequestEntity(fileStream, src.length()));
+            put.setRequestEntity(new FileRequestEntity(src));
             int statusCode = client.executeMethod(put);
             validatePutStatusCode(dest, statusCode, null);
         } finally {
-            if (fileStream != null) {
-                try {
-                    fileStream.close();
-                } catch (IOException e) {
-                    /* ignored */
-                }
-            }
             put.releaseConnection();
         }
     }
@@ -399,4 +392,34 @@ public class HttpClientHandler extends A
         
         return new NTCredentials(user, password, HostUtil.getLocalHostName(), domain);
     }
+    
+    private static class FileRequestEntity implements RequestEntity {
+        private File file;
+        
+        public FileRequestEntity(File file) {
+            this.file = file;
+        }
+
+        public long getContentLength() {
+            return file.length();
+        }
+
+        public String getContentType() {
+            return null;
+        }
+
+        public boolean isRepeatable() {
+            return true;
+        }
+
+        public void writeRequest(OutputStream out) throws IOException {
+            InputStream instream = new FileInputStream(file);
+            try {
+                FileUtil.copy(instream, out, null, false);
+            } finally {
+                instream.close();
+            }
+        }            
+    }
+
 }



Mime
View raw message