FileDocCategorySizeDatePackage
HashvalueAlgorithm.javaAPI DocApache Ant 1.702521Wed Dec 13 06:16:18 GMT 2006org.apache.tools.ant.types.selectors.modifiedselector

HashvalueAlgorithm

public class HashvalueAlgorithm extends Object implements Algorithm
Computes a 'hashvalue' for the content of file using String.hashValue(). Use of this algorithm doesn't require any additional nested s and doesn't support any.
version
2003-09-13
since
Ant 1.6

Fields Summary
Constructors Summary
Methods Summary
public java.lang.StringgetValue(java.io.File file)
Computes a 'hashvalue' for a file content. It reads the content of a file, convert that to String and use the String.hashCode() method.

param
file The file for which the value should be computed
return
the hashvalue or null if the file couldn't be read

        try {
            if (!file.canRead()) {
                return null;
            }
            java.io.FileInputStream fis = new java.io.FileInputStream(file);
            byte[] content = new byte[fis.available()];
            fis.read(content);
            fis.close();
            String s = new String(content);
            int hash = s.hashCode();
            return Integer.toString(hash);
        } catch (Exception e) {
            return null;
        }
    
public booleanisValid()
This algorithm doesn't need any configuration. Therefore it's always valid.

return
always true

        return true;
    
public java.lang.StringtoString()
Override Object.toString().

return
information about this comparator

        return "HashvalueAlgorithm";