diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/FixCRLF.java b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/FixCRLF.java index af7582581..e159f45c1 100644 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/FixCRLF.java +++ b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/FixCRLF.java @@ -19,6 +19,8 @@ import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.Reader; import java.io.Writer; +import java.io.InputStream; +import java.io.BufferedInputStream; import java.util.Iterator; import java.util.NoSuchElementException; import org.apache.myrmidon.api.TaskException; @@ -757,7 +759,7 @@ public class FixCRLF extends MatchingTask { // Compare the destination with the temp file getLogger().debug( "destFile exists" ); - if( !FileUtils.contentEquals( destFile, tmpFile ) ) + if( !contentEquals( destFile, tmpFile ) ) { getLogger().debug( destFile + " is being written" ); if( !destFile.delete() ) @@ -827,6 +829,73 @@ public class FixCRLF extends MatchingTask }// end of finally } + private boolean contentEquals( File f1, File f2 ) + throws IOException + { + if( f1.exists() != f2.exists() ) + { + return false; + } + + if( !f1.exists() ) + { + // two not existing files are equal + return true; + } + + if( f1.isDirectory() || f2.isDirectory() ) + { + // don't want to compare directory contents for now + return false; + } + + InputStream in1 = null; + InputStream in2 = null; + try + { + in1 = new BufferedInputStream( new FileInputStream( f1 ) ); + in2 = new BufferedInputStream( new FileInputStream( f2 ) ); + + int expectedByte = in1.read(); + while( expectedByte != -1 ) + { + if( expectedByte != in2.read() ) + { + return false; + } + expectedByte = in1.read(); + } + if( in2.read() != -1 ) + { + return false; + } + return true; + } + finally + { + if( in1 != null ) + { + try + { + in1.close(); + } + catch( IOException e ) + { + } + } + if( in2 != null ) + { + try + { + in2.close(); + } + catch( IOException e ) + { + } + } + } + } + /** * Enumerated attribute with the values "asis", "add" and "remove". * diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/util/FileUtils.java b/proposal/myrmidon/src/main/org/apache/tools/ant/util/FileUtils.java index 96c0e4e5b..4ca5112b7 100644 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/util/FileUtils.java +++ b/proposal/myrmidon/src/main/org/apache/tools/ant/util/FileUtils.java @@ -35,99 +35,16 @@ import org.apache.tools.ant.types.FilterSetCollection; public class FileUtils { - /** - * Compares the contents of two files. - * - * @param f1 Description of Parameter - * @param f2 Description of Parameter - * @return Description of the Returned Value - * @exception IOException Description of Exception - * @since 1.9 - */ - public static boolean contentEquals( File f1, File f2 ) - throws IOException - { - if( f1.exists() != f2.exists() ) - { - return false; - } - - if( !f1.exists() ) - { - // two not existing files are equal - return true; - } - - if( f1.isDirectory() || f2.isDirectory() ) - { - // don't want to compare directory contents for now - return false; - } - - InputStream in1 = null; - InputStream in2 = null; - try - { - in1 = new BufferedInputStream( new FileInputStream( f1 ) ); - in2 = new BufferedInputStream( new FileInputStream( f2 ) ); - - int expectedByte = in1.read(); - while( expectedByte != -1 ) - { - if( expectedByte != in2.read() ) - { - return false; - } - expectedByte = in1.read(); - } - if( in2.read() != -1 ) - { - return false; - } - return true; - } - finally - { - if( in1 != null ) - { - try - { - in1.close(); - } - catch( IOException e ) - { - } - } - if( in2 != null ) - { - try - { - in2.close(); - } - catch( IOException e ) - { - } - } - } - } - /** * Convienence method to copy a file from a source to a destination * specifying if token filtering must be used, if source files may overwrite * newer destination files and the last modified time of destFile * file should be made equal to the last modified time of sourceFile * . - * - * @param sourceFile Description of Parameter - * @param destFile Description of Parameter - * @param filters Description of Parameter - * @param overwrite Description of Parameter - * @param preserveLastModified Description of Parameter - * @throws IOException */ - public static void copyFile( File sourceFile, - File destFile, - FilterSetCollection filters ) + public static void copyFile( final File sourceFile, + final File destFile, + final FilterSetCollection filters ) throws IOException, TaskException { if( !destFile.exists() || diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/FixCRLF.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/FixCRLF.java index af7582581..e159f45c1 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/FixCRLF.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/FixCRLF.java @@ -19,6 +19,8 @@ import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.Reader; import java.io.Writer; +import java.io.InputStream; +import java.io.BufferedInputStream; import java.util.Iterator; import java.util.NoSuchElementException; import org.apache.myrmidon.api.TaskException; @@ -757,7 +759,7 @@ public class FixCRLF extends MatchingTask { // Compare the destination with the temp file getLogger().debug( "destFile exists" ); - if( !FileUtils.contentEquals( destFile, tmpFile ) ) + if( !contentEquals( destFile, tmpFile ) ) { getLogger().debug( destFile + " is being written" ); if( !destFile.delete() ) @@ -827,6 +829,73 @@ public class FixCRLF extends MatchingTask }// end of finally } + private boolean contentEquals( File f1, File f2 ) + throws IOException + { + if( f1.exists() != f2.exists() ) + { + return false; + } + + if( !f1.exists() ) + { + // two not existing files are equal + return true; + } + + if( f1.isDirectory() || f2.isDirectory() ) + { + // don't want to compare directory contents for now + return false; + } + + InputStream in1 = null; + InputStream in2 = null; + try + { + in1 = new BufferedInputStream( new FileInputStream( f1 ) ); + in2 = new BufferedInputStream( new FileInputStream( f2 ) ); + + int expectedByte = in1.read(); + while( expectedByte != -1 ) + { + if( expectedByte != in2.read() ) + { + return false; + } + expectedByte = in1.read(); + } + if( in2.read() != -1 ) + { + return false; + } + return true; + } + finally + { + if( in1 != null ) + { + try + { + in1.close(); + } + catch( IOException e ) + { + } + } + if( in2 != null ) + { + try + { + in2.close(); + } + catch( IOException e ) + { + } + } + } + } + /** * Enumerated attribute with the values "asis", "add" and "remove". * diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/util/FileUtils.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/util/FileUtils.java index 96c0e4e5b..4ca5112b7 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/util/FileUtils.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/ant/util/FileUtils.java @@ -35,99 +35,16 @@ import org.apache.tools.ant.types.FilterSetCollection; public class FileUtils { - /** - * Compares the contents of two files. - * - * @param f1 Description of Parameter - * @param f2 Description of Parameter - * @return Description of the Returned Value - * @exception IOException Description of Exception - * @since 1.9 - */ - public static boolean contentEquals( File f1, File f2 ) - throws IOException - { - if( f1.exists() != f2.exists() ) - { - return false; - } - - if( !f1.exists() ) - { - // two not existing files are equal - return true; - } - - if( f1.isDirectory() || f2.isDirectory() ) - { - // don't want to compare directory contents for now - return false; - } - - InputStream in1 = null; - InputStream in2 = null; - try - { - in1 = new BufferedInputStream( new FileInputStream( f1 ) ); - in2 = new BufferedInputStream( new FileInputStream( f2 ) ); - - int expectedByte = in1.read(); - while( expectedByte != -1 ) - { - if( expectedByte != in2.read() ) - { - return false; - } - expectedByte = in1.read(); - } - if( in2.read() != -1 ) - { - return false; - } - return true; - } - finally - { - if( in1 != null ) - { - try - { - in1.close(); - } - catch( IOException e ) - { - } - } - if( in2 != null ) - { - try - { - in2.close(); - } - catch( IOException e ) - { - } - } - } - } - /** * Convienence method to copy a file from a source to a destination * specifying if token filtering must be used, if source files may overwrite * newer destination files and the last modified time of destFile * file should be made equal to the last modified time of sourceFile * . - * - * @param sourceFile Description of Parameter - * @param destFile Description of Parameter - * @param filters Description of Parameter - * @param overwrite Description of Parameter - * @param preserveLastModified Description of Parameter - * @throws IOException */ - public static void copyFile( File sourceFile, - File destFile, - FilterSetCollection filters ) + public static void copyFile( final File sourceFile, + final File destFile, + final FilterSetCollection filters ) throws IOException, TaskException { if( !destFile.exists() ||