Fix unclosing file
This commit is contained in:
@@ -63,7 +63,7 @@ public final class MinecraftInstanceTask<T> extends Task {
|
||||
@Override
|
||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
||||
String relativePath = root.relativize(file).normalize().toString();
|
||||
overrides.add(new ModpackConfiguration.FileInformation(relativePath, encodeHex(digest("SHA-1", Files.newInputStream(file)))));
|
||||
overrides.add(new ModpackConfiguration.FileInformation(relativePath, encodeHex(digest("SHA-1", file))));
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -19,6 +19,8 @@ package org.jackhuang.hmcl.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
@@ -51,6 +53,12 @@ public final class DigestUtils {
|
||||
return getDigest(algorithm).digest(data);
|
||||
}
|
||||
|
||||
public static byte[] digest(String algorithm, Path path) throws IOException {
|
||||
try (InputStream is = Files.newInputStream(path)) {
|
||||
return digest(algorithm, is);
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] digest(String algorithm, InputStream data) throws IOException {
|
||||
return digest(getDigest(algorithm), data);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user