Java哈希检查

Java哈希检查,java,Java,由于某些原因,我不明白为什么它每次都下载新的小程序,即使我的计算机上已经有了最新的应用程序(这就是这个下载程序/检查器所做的,检查散列,如果它过时了,它会重新下载上传到web主机的更新版本) 我的下载类 public class Downloader { private static final String HASH_URL = "/current"; private static final String DOWNLOAD_URL = ".jar"; private

由于某些原因,我不明白为什么它每次都下载新的小程序,即使我的计算机上已经有了最新的应用程序(这就是这个下载程序/检查器所做的,检查散列,如果它过时了,它会重新下载上传到web主机的更新版本)

我的下载类

public class Downloader {
    private static final String HASH_URL = "/current";
    private static final String DOWNLOAD_URL = ".jar";

    private LoadingFrame loadingFrame;

    public Downloader(LoadingFrame loadingFrame) {
        this.loadingFrame = loadingFrame;
    }

    private String getLatestHash() {
        loadingFrame.setLoadingText("Checking if client is up to date...");
        try (InputStream in = new URL(HASH_URL).openStream()) {
            return new String(IOUtils.toByteArray(in)).trim();
        } catch (IOException e) {
            loadingFrame.setLoadingText("Error loading client [ErrorCode: 7A]");
            throw new RuntimeException("Error loading client");
        }
    }


    public File downloadLatestPack() {
        try {
            File dir = new File(System.getProperty("user.home") + File.separator + "Project" + File.separator + "client");
            if (!dir.exists()) {
                dir.mkdirs();
            }
            loadingFrame.setLoadingText("Checking if client is up to date...");
            String latestHash = getLatestHash();
            File latest = new File(dir.getPath() + File.separator + latestHash + ".jar");

            if (!latest.exists() || !com.google.common.io.Files.hash(latest, Hashing.sha1()).toString().equals(latestHash)) {
                loadingFrame.setLoadingText("Doing some house keeping...");
                for (File f : dir.listFiles()) {
                    if (f.getName().endsWith(".jar") && !f.getName().equals(latest.getName())) {
                        f.delete();
                    }
                }
                loadingFrame.setLoadingText("Downloading latest client...");
                latest.createNewFile();
                try (InputStream in = new URL(DOWNLOAD_URL).openStream()) {
                    Files.copy(in, latest.toPath(), StandardCopyOption.REPLACE_EXISTING);
                }
            } else {
                loadingFrame.setLoadingText("Client is up to date!");
            }

            return latest;
        } catch (IOException e) {
            loadingFrame.setLoadingText("Error loading client [ErrorCode: 6B]");
            throw new RuntimeException("Error loading client");
        }
    }
}

看起来散列不同,继续提供
com.google.common.io.Files.hash(最新,Hashing.sha1()).toString()
值和
getLatestHash()的返回值
我是否将它们粘贴到这里@RafaelGo继续编辑原始帖子可能听起来有点奇怪,但是我如何提供
com.google.common.io.Files.hash(最新版本,Hashing.sha1()).toString()
value?只需将其打印到控制台,然后复制内容即可