donaldp 02/01/20 01:51:04
Modified: proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/text
FixCRLF.java
Added: proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/text
CrLf.java AddAsisRemove.java
Log:
Extract inner classes and move contentEuqls to FileUtil
Revision Changes Path
1.4 +5 -101
jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/text/FixCRLF.java
Index: FixCRLF.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/text/FixCRLF.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- FixCRLF.java 13 Jan 2002 00:00:34 -0000 1.3
+++ FixCRLF.java 20 Jan 2002 09:51:04 -0000 1.4
@@ -7,7 +7,6 @@
*/
package org.apache.tools.ant.taskdefs.text;
-import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
@@ -16,17 +15,16 @@
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
-import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
import java.util.Iterator;
import java.util.NoSuchElementException;
+import org.apache.avalon.excalibur.io.FileUtil;
import org.apache.myrmidon.api.TaskException;
-import org.apache.tools.ant.types.DirectoryScanner;
import org.apache.tools.ant.taskdefs.MatchingTask;
-import org.apache.tools.ant.types.EnumeratedAttribute;
+import org.apache.tools.ant.types.DirectoryScanner;
/**
* Task to convert text source files to local OS formatting conventions, as
well
@@ -67,9 +65,8 @@
*
* @author Sam Ruby <a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Peter B. West</a>
- * @version $Revision: 1.3 $ $Name: $
+ * @version $Revision: 1.4 $ $Name: $
*/
-
public class FixCRLF
extends MatchingTask
{
@@ -759,7 +756,8 @@
{
// Compare the destination with the temp file
getLogger().debug( "destFile exists" );
- if( !contentEquals( destFile, tmpFile ) )
+ boolean result = FileUtil.contentEquals( destFile, tmpFile );
+ if( !result )
{
getLogger().debug( destFile + " is being written" );
if( !destFile.delete() )
@@ -829,99 +827,6 @@
}// 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".
- *
- * @author RT
- */
- public static class AddAsisRemove extends EnumeratedAttribute
- {
- public String[] getValues()
- {
- return new String[]{"add", "asis", "remove"};
- }
- }
-
- /**
- * Enumerated attribute with the values "asis", "cr", "lf" and "crlf".
- *
- * @author RT
- */
- public static class CrLf extends EnumeratedAttribute
- {
- public String[] getValues()
- {
- return new String[]{"asis", "cr", "lf", "crlf"};
- }
- }
-
class OneLiner
implements Iterator
{
@@ -1200,5 +1105,4 @@
}
}
}
-
}
1.1
jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/text/CrLf.java
Index: CrLf.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.tools.ant.taskdefs.text;
import org.apache.tools.ant.types.EnumeratedAttribute;
/**
* Enumerated attribute with the values "asis", "cr", "lf" and "crlf".
*/
public class CrLf
extends EnumeratedAttribute
{
public String[] getValues()
{
return new String[]{"asis", "cr", "lf", "crlf"};
}
}
1.1
jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/text/AddAsisRemove.java
Index: AddAsisRemove.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.tools.ant.taskdefs.text;
import org.apache.tools.ant.types.EnumeratedAttribute;
/**
* Enumerated attribute with the values "asis", "add" and "remove".
*/
public class AddAsisRemove
extends EnumeratedAttribute
{
public String[] getValues()
{
return new String[]{"add", "asis", "remove"};
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>