This commit is contained in:
parent
3e3a7f57a9
commit
8f6dac310a
1 changed files with 0 additions and 82 deletions
|
|
@ -1,82 +0,0 @@
|
|||
package ei.engine.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.math.BigInteger;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class FileFinderHasher {
|
||||
public static void main(String[] args){
|
||||
ArrayList<File> files = Search(new File("C:\\Documents and Settings\\Ziver\\Mina dokument\\Roligt"));
|
||||
for(int i=0; i<files.size(); i++){
|
||||
try {
|
||||
Hash(files.get(i),"MD5");
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (FileNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static ArrayList<File> Search(File dir){
|
||||
return Search(dir, new ArrayList<File>());
|
||||
}
|
||||
|
||||
private static ArrayList<File> Search(File dir, ArrayList<File> fileList){
|
||||
String[] temp = dir.list();
|
||||
File file;
|
||||
|
||||
for(int i=0;i<temp.length;i++){
|
||||
file = new File(dir.getPath()+File.separator+temp[i]);
|
||||
//System.out.println(temp[i]);
|
||||
if(file.isDirectory()){
|
||||
//System.out.println(file.getPath()+File.separator+temp[i]+File.separator);
|
||||
Search(new File(dir.getPath()+File.separator+temp[i]+File.separator),fileList);
|
||||
}
|
||||
else if(file.isFile()){
|
||||
fileList.add(file);
|
||||
}
|
||||
}
|
||||
|
||||
return fileList;
|
||||
}
|
||||
|
||||
public static void Hash(File file, String hashType) throws NoSuchAlgorithmException, FileNotFoundException {
|
||||
MessageDigest digest = MessageDigest.getInstance(hashType);//"MD5"
|
||||
InputStream is = new FileInputStream(file);
|
||||
String output = "";
|
||||
byte[] buffer = new byte[8192];
|
||||
int read = 0;
|
||||
try {
|
||||
System.out.println("FILE: " + file.toString());
|
||||
while( (read = is.read(buffer)) > 0) {
|
||||
System.out.print("#");
|
||||
digest.update(buffer, 0, read);
|
||||
}
|
||||
byte[] md5sum = digest.digest();
|
||||
BigInteger bigInt = new BigInteger(1, md5sum);
|
||||
output = bigInt.toString(16);
|
||||
System.out.println(" DONE");
|
||||
System.out.println("MD5: " + output);
|
||||
}
|
||||
catch(IOException e) {
|
||||
throw new RuntimeException("Unable to process file for MD5", e);
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
is.close();
|
||||
}
|
||||
catch(IOException e) {
|
||||
throw new RuntimeException("Unable to close input stream for MD5 calculation", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue