Browse Source

better return the correct size

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@326640 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 19 years ago
parent
commit
1400dc3c1b
1 changed files with 24 additions and 3 deletions
  1. +24
    -3
      src/main/org/apache/tools/ant/types/resources/CompressedResource.java

+ 24
- 3
src/main/org/apache/tools/ant/types/resources/CompressedResource.java View File

@@ -25,12 +25,14 @@ import org.apache.tools.ant.types.DataType;
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 @@ public abstract class CompressedResource extends Resource
* 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) {


Loading…
Cancel
Save