|
|
Return Digest3 Java code example - Click here to copy ->>>
Can't find what you're looking for? Try our search:
|
|
Really working examples categorized by API, package, class. You can compile and run our examples right away!
Not from source code for Java projects - only working examples! Copy, compile and run!
|
------------------
| Code: |
import java.io.*;
import java.security.*;
public class ReturnDigest3 implements Runnable {
private File input;
private byte[] digest;
public ReturnDigest3(File input) {
this.input = input;
}
public void run() {
try {
FileInputStream in = new FileInputStream(input);
MessageDigest sha = MessageDigest.getInstance("SHA");
DigestInputStream din = new DigestInputStream(in, sha);
int b;
while ((b = din.read()) != -1) ;
din.close();
digest = sha.digest();
}
catch (IOException e) {
System.err.println(e);
}
catch (NoSuchAlgorithmException e) {
System.err.println(e);
}
}
public byte[] getDigest() {
return digest;
}
public static void main(String[] args) {
ReturnDigest1[] digests = new ReturnDigest1[args.length];
for (int i = 0; i < args.length; i++) {
// Calculate the digest
File f = new File(args[i]);
digests[i] = new ReturnDigest1(f);
Thread t = new Thread(digests[i]);
t.start();
}
for (int i = 0; i < args.length; i++) {
while (true) {
// Now print the result
byte[] digest = digests[i].getDigest();
if (digest != null) {
StringBuffer result = new StringBuffer(args[i]);
result.append(": ");
for (int j = 0; j < digest.length; j++) {
result.append(digest[j] + " ");
}
System.out.println(result);
break;
}
}
}
}
}
/**
* Java Network Programming, Third Edition
* By Elliotte Rusty Harold
* Third Edition October 2004
* ISBN: 0-596-00721-3
*/
|
|
|
|
Click on the links below and read more tips on classes from this code example.
Do it right now!
It is not a big secret that file system in Java looks like UNIX file system. It...
Serialize Java Object to file? How can I store and retrieve serialized objects t...
When I copy an MS Excel file to another Excel file, I'm getting garbage characte...
Deadlocks in Java...
Anonymous Inner Classes...
I am sure that in my program I create 100 new threads and when I use isAlive met...
Logging part 1...
Logging part 2...
Java Newsletters Archive: 6...
Java Newsletters Archive: 13...
Java Newsletters Archive: 17...
Java Newsletters Archive: 168...
Hooking into the shutdown call...
Setting focus to second component of modal dialog...
The thread constructor since 1.4.1 allows the thread stack size to be specified....
Serializing GUI Components Across Network...
Serializing GUI Components Across Network, follow up...
How do I stop a thread that waits for long periods (e.g., for input)?...
Insane Strings...
Can I combine the two techniques to produce a thread that may be safely ''stoppe...
JDK 5.0: More Flexible, Scalable Locking...
The Java Lesson 25: Interfaces, instanceof, and object conversion and casting...
Blocking Queue...
Java: Example - FileTest.java...
Class names don't identify a class...
Java Lesson 41: Exception handling with try, catch, and finally blocks...
Serializing Objects Into Database...
Java Lesson 42: Claiming and throwing exceptions...
Java Lesson 43: Multithreading, the Thread class, and the Runnable interface...
Java Lesson 45: Low-level and high-level stream classes...
|
|
References.
The list of classes which were used on this page you can find below. The
links to Java API contain official SUN documentation about all used classes.
[ Go Back ]
|
|