ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs FixCRLF.java
Date Sat, 29 Dec 2001 23:48:15 GMT
donaldp     01/12/29 15:48:15

  Modified:    proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs
                        FixCRLF.java
  Log:
  Move contentEquals method into FixCRLF as it is not used anywhere else
  
  Revision  Changes    Path
  1.11      +71 -2     jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/FixCRLF.java
  
  Index: FixCRLF.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/FixCRLF.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- FixCRLF.java	23 Dec 2001 14:21:50 -0000	1.10
  +++ FixCRLF.java	29 Dec 2001 23:48:15 -0000	1.11
  @@ -19,6 +19,8 @@
   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;
  @@ -65,7 +67,7 @@
    *
    * @author Sam Ruby <a href="mailto:rubys@us.ibm.com">rubys@us.ibm.com</a>
    * @author <a href="mailto:pbwest@powerup.com.au">Peter B. West</a>
  - * @version $Revision: 1.10 $ $Name:  $
  + * @version $Revision: 1.11 $ $Name:  $
    */
   
   public class FixCRLF extends MatchingTask
  @@ -757,7 +759,7 @@
               {
                   // 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() )
  @@ -825,6 +827,73 @@
                   tmpFile.delete();
               }
           }// 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 )
  +                {
  +                }
  +            }
  +        }
       }
   
       /**
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message