|
|
@@ -31,6 +31,8 @@ |
|
|
import java.io.IOException;
|
|
|
import java.io.OutputStream;
|
|
|
import java.math.BigInteger;
|
|
|
+import java.nio.file.Files;
|
|
|
+import java.nio.file.Path;
|
|
|
import java.security.MessageDigest;
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
|
|
|
@@ -43,14 +45,14 @@ |
|
|
|
|
|
private final OutputStream os;
|
|
|
private final MessageDigest md5;
|
|
|
- private final File digestFile;
|
|
|
+ private final Path digestFile;
|
|
|
private String hash;
|
|
|
|
|
|
/**
|
|
|
* Constructor that takes in the OutputStream that we are wrapping
|
|
|
* and creates the MD5 MessageDigest
|
|
|
*/
|
|
|
- public Md5CalculatingOutputStream(OutputStream os, File digestFile) {
|
|
|
+ public Md5CalculatingOutputStream(OutputStream os, Path digestFile) {
|
|
|
super();
|
|
|
this.hash = null;
|
|
|
this.os = os;
|
|
|
@@ -65,6 +67,10 @@ public Md5CalculatingOutputStream(OutputStream os, File digestFile) { |
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public Md5CalculatingOutputStream(OutputStream os, File digestFile) {
|
|
|
+ this(os, digestFile.toPath());
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void write(int b) throws IOException {
|
|
|
md5.update((byte)b);
|
|
|
@@ -111,7 +117,7 @@ public void close() throws IOException { |
|
|
makeHash();
|
|
|
|
|
|
if(digestFile != null) {
|
|
|
- BufferedWriter writer = new BufferedWriter(new FileWriter(digestFile));
|
|
|
+ BufferedWriter writer = Files.newBufferedWriter(digestFile);
|
|
|
writer.write(hash);
|
|
|
writer.close();
|
|
|
}
|
|
|
|