ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kev Jackson <kevin.jack...@it.fts-vn.com>
Subject [Patch] FileUtils more minor changes
Date Thu, 16 Dec 2004 03:55:35 GMT
- new generic close method - reduces duplicate code (may be useful for 
when we can finally remove code -> Ant2?)
- minor loop tweak
- buffer compare for JDK1.4+ (only runs on files < 1Mb to conserve 
memory during builds)

>>+        int stackSize = s.size();
>>         while (tok.hasMoreTokens()) {
>>             String thisToken = tok.nextToken();
>>             if (".".equals(thisToken)) {
>>                 continue;
>>             } else if ("..".equals(thisToken)) {
>>-                if (s.size() < 2) {
>>-                    throw new BuildException("Cannot resolve path " + orig);
>>-                } else {
>>+                if (stackSize > 2) {
>>                     s.pop();
>>+                } else {
>>+                    throw new BuildException("Cannot resolve path " + orig);
>>                 }
>>    
>>
>
>here s.pop() is going to change s.size(), but you don't update
>stackSize.
>  
>
Yes, I'm sorry - I looked over the code again and actually storing and 
then manually updating was nowhere near as maintainable.

>  
>
>>+        /* If we have Java => 1.4, we can use NIO
>>+         * This buffer comparison simply maps the entire file into memory,
>>+         * it's not concerned with memory usage - for large files this
>>+         * may cause problems         
>>+         */
>>+        if (JavaEnvUtils.getJavaVersion().equals(JavaEnvUtils.JAVA_1_4)
>>+                ||JavaEnvUtils.getJavaVersion().equals(JavaEnvUtils.JAVA_1_5)
>>+                ) {
>>    
>>
>
>If you want to assert JDK 1.4+, you better reverse the logic for
>forwards compatibility reasons.  I.e. check that we currently are not
>running on JDK 1.2 or 1.3 (less than 1.2 is not possible anymore).
>
>  
>
Ok done in attached patch.  I also check for 1.0 and 1.2 (just in case) 
and the check also includes filesize too (< 1Mb).

Going to hack my way through all the horrible MSVSS* code now for style 
- Eclipse is throwing a fit over variable names :(
As an aside, I went through the entire codebase last night and replaced 
every
try {
  somthing.close()
} catch (IOException e) {
    //swallow exception
}

with FileUtils.close()

These were done against a slightly older sourcebase as I don't have net 
access at home and have to lug my laptop down the road.  If you're 
interested I'll post the patch tonight, but it affects a lot of classes 
(~50+) and I can imagine it being a nightmare to be certain of 
everything still being ok afterwards (although the test cases help with 
that).

Kev

Mime
View raw message