From 512567d2f68e90c8c9e36441c6a0bee8f64997ef Mon Sep 17 00:00:00 2001 From: Matthew Jason Benson Date: Wed, 9 May 2007 14:49:46 +0000 Subject: [PATCH] refactorings git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@536548 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/tools/ant/taskdefs/Length.java | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/Length.java b/src/main/org/apache/tools/ant/taskdefs/Length.java index 6de77ddf6..4be5a3476 100755 --- a/src/main/org/apache/tools/ant/taskdefs/Length.java +++ b/src/main/org/apache/tools/ant/taskdefs/Length.java @@ -34,6 +34,7 @@ import org.apache.tools.ant.types.ResourceCollection; import org.apache.tools.ant.types.EnumeratedAttribute; import org.apache.tools.ant.types.resources.Resources; import org.apache.tools.ant.types.resources.FileResource; +import org.apache.tools.ant.util.FileUtils; import org.apache.tools.ant.util.PropertyOutputStream; /** @@ -184,13 +185,13 @@ public class Length extends Task implements Condition { if (length == null) { throw new BuildException(LENGTH_REQUIRED); } - Long ell = null; + Long ell; if (STRING.equals(mode)) { ell = new Long(getLength(string, getTrim())); - } else { - ConditionHandler h = new ConditionHandler(); + } else { + AccumHandler h = new AccumHandler(); handleResources(h); - ell = new Long(h.getLength()); + ell = new Long(h.getAccum()); } return when.evaluate(ell.compareTo(length)); } @@ -273,7 +274,7 @@ public class Length extends Task implements Condition { protected abstract void handle(Resource r); void complete() { - ps.close(); + FileUtils.close(ps); } } @@ -294,9 +295,13 @@ public class Length extends Task implements Condition { } } - private class AllHandler extends Handler { + private class AccumHandler extends Handler { private long accum = 0L; - AllHandler(PrintStream ps) { + + AccumHandler() { + super(null); + } + protected AccumHandler(PrintStream ps) { super(ps); } protected long getAccum() { @@ -310,20 +315,16 @@ public class Length extends Task implements Condition { accum += size; } } - void complete() { - getPs().print(accum); - super.complete(); - } } - private class ConditionHandler extends AllHandler { - ConditionHandler() { - super(null); + private class AllHandler extends AccumHandler { + AllHandler(PrintStream ps) { + super(ps); } void complete() { - } - long getLength() { - return getAccum(); + getPs().print(getAccum()); + super.complete(); } } + }