Author: mbenson Date: Wed May 9 07:49:46 2007 New Revision: 536548 URL: http://svn.apache.org/viewvc?view=rev&rev=536548 Log: refactorings
Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Length.java Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Length.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Length.java?view=diff&rev=536548&r1=536547&r2=536548 ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Length.java (original) +++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Length.java Wed May 9 07:49:46 2007 @@ -34,6 +34,7 @@ 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 @@ 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 @@ protected abstract void handle(Resource r); void complete() { - ps.close(); + FileUtils.close(ps); } } @@ -294,9 +295,13 @@ } } - 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 @@ 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(); } } + } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]