donaldp 02/02/18 00:28:51
Modified: proposal/myrmidon/src/java/org/apache/antlib/build
Checksum.java
Log:
Use StringBuffer inside loops and dont reasign parameters to method
Revision Changes Path
1.4 +12 -27
jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/build/Checksum.java
Index: Checksum.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/build/Checksum.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Checksum.java 14 Feb 2002 11:21:58 -0000 1.3
+++ Checksum.java 18 Feb 2002 08:28:51 -0000 1.4
@@ -32,7 +32,7 @@
*
* @ant:task name="checksum"
* @author <a href="mailto:[EMAIL PROTECTED]">Magesh Umasankar</a>
- * @version $Revision: 1.3 $ $Date: 2002/02/14 11:21:58 $
+ * @version $Revision: 1.4 $ $Date: 2002/02/18 08:28:51 $
*/
public class Checksum
extends AbstractMatchingTask
@@ -89,8 +89,6 @@
/**
* Sets the MessageDigest algorithm to be used to calculate the checksum.
- *
- * @param algorithm The new Algorithm value
*/
public void setAlgorithm( final String algorithm )
{
@@ -99,8 +97,6 @@
/**
* Sets the file for which the checksum is to be calculated.
- *
- * @param file The new File value
*/
public void setFile( final File file )
{
@@ -110,8 +106,6 @@
/**
* Sets the File Extension that is be to used to create or identify
* destination file
- *
- * @param fileext The new Fileext value
*/
public void setFileext( final String fileext )
{
@@ -121,8 +115,6 @@
/**
* Overwrite existing file irrespective of whether it is newer than the
* source file? Defaults to false.
- *
- * @param forceOverwrite The new ForceOverwrite value
*/
public void setForceOverwrite( boolean forceOverwrite )
{
@@ -131,8 +123,6 @@
/**
* Sets the property to hold the generated checksum
- *
- * @param property The new Property value
*/
public void setProperty( String property )
{
@@ -153,8 +143,6 @@
/**
* Sets verify property. This project property holds the result of a
* checksum verification - "true" or "false"
- *
- * @param verifyProperty The new Verifyproperty value
*/
public void setVerifyproperty( final String verifyProperty )
{
@@ -163,8 +151,6 @@
/**
* Adds a set of files (nested fileset attribute).
- *
- * @param set The feature to be added to the Fileset attribute
*/
public void addFileset( final FileSet set )
{
@@ -173,8 +159,6 @@
/**
* Calculate the checksum(s).
- *
- * @exception TaskException Description of Exception
*/
public void execute()
throws TaskException
@@ -182,9 +166,7 @@
final boolean value = validateAndExecute();
if( m_verifyProperty != null )
{
- final String name = m_verifyProperty;
- final Object value1 = new Boolean( value ).toString();
- getContext().setProperty( name, value1 );
+ getContext().setProperty( m_verifyProperty, "" + value );
}
}
@@ -251,9 +233,10 @@
return checksumMatches;
}
- private boolean z( final File src, boolean checksumMatches )
+ private boolean z( final File src, final boolean checksumMatches )
throws TaskException
{
+ boolean match = checksumMatches;
FileInputStream fis = null;
FileOutputStream fos = null;
try
@@ -262,23 +245,25 @@
final byte[] fileDigest = buildDigest( fis );
IOUtil.shutdownStream( fis );
- String checksum = "";
+ final StringBuffer sb = new StringBuffer();
for( int i = 0; i < fileDigest.length; i++ )
{
final String hexStr = Integer.toHexString( 0x00ff &
fileDigest[ i ] );
if( hexStr.length() < 2 )
{
- checksum += "0";
+ sb.append( '0' );
}
- checksum += hexStr;
+ sb.append( hexStr );
}
+ final String checksum = sb.toString();
+
//can either be a property name string or a file
- Object destination = m_includeFileMap.get( src );
+ final Object destination = m_includeFileMap.get( src );
if( destination instanceof String )
{
final String prop = (String)destination;
- checksumMatches = checksum.equals( m_property );
+ match = checksum.equals( m_property );
getContext().setProperty( prop, checksum );
}
else if( destination instanceof File )
@@ -299,7 +284,7 @@
IOUtil.shutdownStream( fis );
IOUtil.shutdownStream( fos );
}
- return checksumMatches;
+ return match;
}
private byte[] buildDigest( final InputStream input )
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>