prepare for compressor streams that can take advantage of Files - Pack200 will be one once Commons Compress 1.3 supports it
git-svn-id: https://svn.apache.org/repos/asf/ant/antlibs/compress/trunk@1154209 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/org/apache/ant/compress/taskdefs/PackBase.java b/src/main/org/apache/ant/compress/taskdefs/PackBase.java
index 6e0d8aa..a6e2d7f 100644
--- a/src/main/org/apache/ant/compress/taskdefs/PackBase.java
+++ b/src/main/org/apache/ant/compress/taskdefs/PackBase.java
@@ -27,11 +27,13 @@
import org.apache.ant.compress.resources.CommonsCompressCompressorResource;
import org.apache.ant.compress.util.CompressorStreamFactory;
+import org.apache.ant.compress.util.FileAwareCompressorStreamFactory;
import org.apache.commons.compress.utils.IOUtils;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.Resource;
import org.apache.tools.ant.types.ResourceCollection;
+import org.apache.tools.ant.types.resources.FileProvider;
import org.apache.tools.ant.types.resources.FileResource;
import org.apache.tools.ant.types.resources.Resources;
import org.apache.tools.ant.util.FileUtils;
@@ -185,8 +187,16 @@
OutputStream out = null;
try {
in = src.getInputStream();
+ if (factory instanceof FileAwareCompressorStreamFactory
+ && dest.as(FileProvider.class) != null) {
+ FileProvider p = (FileProvider) dest.as(FileProvider.class);
+ FileAwareCompressorStreamFactory f =
+ (FileAwareCompressorStreamFactory) factory;
+ out = f.getCompressorOutputStream(p.getFile());
+ } else {
out =
factory.getCompressorStream(new BufferedOutputStream(dest.getOutputStream()));
+ }
IOUtils.copy(in, out, BUFFER_SIZE);
} catch (IOException e) {
throw new BuildException("Error compressing " + src.getName()
diff --git a/src/main/org/apache/ant/compress/taskdefs/UnpackBase.java b/src/main/org/apache/ant/compress/taskdefs/UnpackBase.java
index 9baae1e..4b91eaa 100644
--- a/src/main/org/apache/ant/compress/taskdefs/UnpackBase.java
+++ b/src/main/org/apache/ant/compress/taskdefs/UnpackBase.java
@@ -24,8 +24,10 @@
import java.io.InputStream;
import org.apache.ant.compress.util.CompressorStreamFactory;
+import org.apache.ant.compress.util.FileAwareCompressorStreamFactory;
import org.apache.commons.compress.compressors.CompressorInputStream;
import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.types.resources.FileProvider;
import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.taskdefs.Unpack;
@@ -65,8 +67,17 @@
InputStream fis = null;
try {
out = new FileOutputStream(dest);
+ if (factory instanceof FileAwareCompressorStreamFactory
+ && srcResource.as(FileProvider.class) != null) {
+ FileProvider p =
+ (FileProvider) srcResource.as(FileProvider.class);
+ FileAwareCompressorStreamFactory f =
+ (FileAwareCompressorStreamFactory) factory;
+ zIn = f.getCompressorInputStream(p.getFile());
+ } else {
fis = srcResource.getInputStream();
zIn = factory.getCompressorStream(new BufferedInputStream(fis));
+ }
byte[] buffer = new byte[BUFFER_SIZE];
int count = 0;
do {
diff --git a/src/main/org/apache/ant/compress/util/FileAwareCompressorStreamFactory.java b/src/main/org/apache/ant/compress/util/FileAwareCompressorStreamFactory.java
new file mode 100644
index 0000000..3b43f22
--- /dev/null
+++ b/src/main/org/apache/ant/compress/util/FileAwareCompressorStreamFactory.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.ant.compress.util;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.commons.compress.compressors.CompressorInputStream;
+import org.apache.commons.compress.compressors.CompressorOutputStream;
+
+/**
+ * Creates streams for the supported compression formats that may take
+ * advantage of writing to/reading from a file.
+ *
+ * @since Apache Compress Antlib 1.1
+ */
+public interface FileAwareCompressorStreamFactory {
+
+ /**
+ * @param file the file to read from
+ */
+ public CompressorInputStream getCompressorInputStream(File file)
+ throws IOException;
+
+
+ /**
+ * @param file the file to write to
+ */
+ public CompressorOutputStream getCompressorOutputStream(File file)
+ throws IOException;
+
+}
\ No newline at end of file