Browse Source

Move contentEquals method into FixCRLF as it is not used anywhere else

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270404 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Donald 24 years ago
parent
commit
74b3200d90
4 changed files with 146 additions and 174 deletions
  1. +70
    -1
      proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/FixCRLF.java
  2. +3
    -86
      proposal/myrmidon/src/main/org/apache/tools/ant/util/FileUtils.java
  3. +70
    -1
      proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/FixCRLF.java
  4. +3
    -86
      proposal/myrmidon/src/todo/org/apache/tools/ant/util/FileUtils.java

+ 70
- 1
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/FixCRLF.java View File

@@ -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".
*


+ 3
- 86
proposal/myrmidon/src/main/org/apache/tools/ant/util/FileUtils.java View File

@@ -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 <code>destFile</code>
* file should be made equal to the last modified time of <code>sourceFile</code>
* .
*
* @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() ||


+ 70
- 1
proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/FixCRLF.java View File

@@ -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".
*


+ 3
- 86
proposal/myrmidon/src/todo/org/apache/tools/ant/util/FileUtils.java View File

@@ -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 <code>destFile</code>
* file should be made equal to the last modified time of <code>sourceFile</code>
* .
*
* @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() ||


Loading…
Cancel
Save