Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Sha1 hash function (Message Digest)

807600Aug 23 2007 — edited Aug 23 2007
I am trying to create a program that lists the current java programs in a directory that is run through command line arguments, ( which works) however once i have populated all the java files i need to then turn the file names into sha1 message digests for the next step. I have the relevant code for this to work but i can not get it to compile is there something i have done wrong? or put the code in the wrong place?? here is my code feel free to amend it.

Thanks Mich

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.io.File;
import java.io.FilenameFilter;
import java.util.Scanner;


public class ListDirectories implements FilenameFilter {

static Scanner sc = new Scanner(System.in);

public static void main (String [] args) throws UnsupportedEncodingException, NoSuchAlgorithmException {
String path = args [0];

ListDirectories ff = new ListDirectories();
ff.process(path);
}

}


public void process(String dir) {
String objects[] = (new File(dir)).list(this);
for (int i = 0; i < objects.length; i++) {
System.out.println("TRACE:"+objects);
}
}

public boolean accept(File dir, String s) {

if (s.endsWith(".java")) {
return true;

}
return false;
}

//public void MessageDigest(){
MessageDigest md = MessageDigest.getInstance("SHA");
try {
md.update(objects);
MessageDigest objects = md.clone();
byte[] objectsDigest = objects.digest();
md.update(objects);

} catch (CloneNotSupportedException cnse) {
throw new DigestException("couldn't make digest of partial content");
//}


}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 20 2007
Added on Aug 23 2007
4 comments
777 views