Browse Source

take advantage of FileUtils

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@887990 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 15 years ago
parent
commit
87142931bd
1 changed files with 8 additions and 11 deletions
  1. +8
    -11
      src/main/org/apache/tools/ant/types/selectors/modifiedselector/HashvalueAlgorithm.java

+ 8
- 11
src/main/org/apache/tools/ant/types/selectors/modifiedselector/HashvalueAlgorithm.java View File

@@ -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 @@ public class HashvalueAlgorithm implements Algorithm {
// 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);
}
}



Loading…
Cancel
Save