ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r326640 - /ant/core/trunk/src/main/org/apache/tools/ant/types/resources/CompressedResource.java
Date Wed, 19 Oct 2005 18:40:05 GMT
Author: bodewig
Date: Wed Oct 19 11:40:02 2005
New Revision: 326640

URL: http://svn.apache.org/viewcvs?rev=326640&view=rev
Log:
better return the correct size

Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/types/resources/CompressedResource.java

Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/resources/CompressedResource.java
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/main/org/apache/tools/ant/types/resources/CompressedResource.java?rev=326640&r1=326639&r2=326640&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/resources/CompressedResource.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/resources/CompressedResource.java Wed
Oct 19 11:40:02 2005
@@ -25,12 +25,14 @@
 import org.apache.tools.ant.types.Resource;
 import org.apache.tools.ant.types.Reference;
 import org.apache.tools.ant.types.ResourceCollection;
+import org.apache.tools.ant.util.FileUtils;
 
 /**
  * A compressed resource.
  *
- * <p>Wraps around another resource, delegates all queries to that
- * other resource but uncompresses/compresses streams on the fly.</p>
+ * <p>Wraps around another resource, delegates all queries (except
+ * getSize) to that other resource but uncompresses/compresses streams
+ * on the fly.</p>
  *
  * @since Ant 1.7
  */
@@ -124,7 +126,26 @@
      *         compatibility with java.io.File), or UNKNOWN_SIZE if not known.
      */
     public long getSize() {
-        return getResource().getSize();
+        if (isExists()) {
+            InputStream in = null;
+            try {
+                in = getInputStream();
+                byte[] buf = new byte[8192];
+                int size = 0;
+                int readNow;
+                while ((readNow = in.read(buf, 0, buf.length)) > 0) {
+                    size += readNow;
+                }
+                return size;
+            } catch (IOException ex) {
+                throw new BuildException("caught exception while reading "
+                                         + getName(), ex);
+            } finally {
+                FileUtils.close(in);
+            }
+        } else {
+            return 0;
+        }
     }
 
     public void setSize(long size) {



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


Mime
View raw message