Author: bodewig
Date: Mon Dec 7 16:30:43 2009
New Revision: 887990
URL: http://svn.apache.org/viewvc?rev=887990&view=rev
Log:
take advantage of FileUtils
Modified:
ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/modifiedselector/HashvalueAlgorithm.java
Modified:
ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/modifiedselector/HashvalueAlgorithm.java
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/modifiedselector/HashvalueAlgorithm.java?rev=887990&r1=887989&r2=887990&view=diff
==============================================================================
---
ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/modifiedselector/HashvalueAlgorithm.java
(original)
+++
ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/modifiedselector/HashvalueAlgorithm.java
Mon Dec 7 16:30:43 2009
@@ -18,9 +18,10 @@
package org.apache.tools.ant.types.selectors.modifiedselector;
-
+import org.apache.tools.ant.util.FileUtils;
import java.io.File;
-
+import java.io.FileReader;
+import java.io.Reader;
/**
* Computes a 'hashvalue' for the content of file using String.hashValue().
@@ -51,22 +52,18 @@
// Because the content is only read the file will not be damaged. I tested
// with JPG, ZIP and PDF as binary files.
public String getValue(File file) {
+ Reader r = null;
try {
if (!file.canRead()) {
return null;
}
- java.io.FileInputStream fis = new java.io.FileInputStream(file);
- StringBuffer content = new StringBuffer();
- byte[] buffer = new byte[256];
- int len = 0;
- while ((len = fis.read(buffer, 0, len)) != -1) {
- content.append(new String(buffer, 0, len));
- }
- fis.close();
- int hash = content.toString().hashCode();
+ r = new FileReader(file);
+ int hash = FileUtils.readFully(r).hashCode();
return Integer.toString(hash);
} catch (Exception e) {
return null;
+ } finally {
+ FileUtils.close(r);
}
}