Author: bodewig
Date: Fri Mar 14 21:13:06 2014
New Revision: 1577711
URL: http://svn.apache.org/r1577711
Log:
add gzip content-encoding support to <get>, submitted by Maarten Coene. PR
49453
Modified:
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Get.java
Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Get.java
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Get.java?rev=1577711&r1=1577710&r2=1577711&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Get.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Get.java Fri Mar 14
21:13:06 2014
@@ -29,6 +29,7 @@ import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.Date;
+import java.util.zip.GZIPInputStream;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.MagicNames;
@@ -68,6 +69,7 @@ public class Get extends Task {
private static final String HTTPS = "https";
private static final String DEFAULT_AGENT_PREFIX = "Apache Ant";
+ private static final String GZIP_CONTENT_ENCODING = "gzip";
private Resources sources = new Resources();
private File destination; // required
@@ -679,6 +681,8 @@ public class Get extends Task {
+ encoding);
}
+ connection.setRequestProperty("Accept-Encoding",
GZIP_CONTENT_ENCODING);
+
if (connection instanceof HttpURLConnection) {
((HttpURLConnection) connection)
.setInstanceFollowRedirects(false);
@@ -767,6 +771,10 @@ public class Get extends Task {
getLocation());
}
+ if (GZIP_CONTENT_ENCODING.equals(connection.getContentEncoding()))
{
+ is = new GZIPInputStream(is);
+ }
+
os = new FileOutputStream(dest);
progress.beginDownload();
boolean finished = false;