java
Java hash checking
For some reason i can't figure out why it downloads the new applet every time even though i have the newest application on my computer already (that's what this downloader/checker does, to check the hash, and if its outdated, it re-downloads the newer version which is uploaded to web host) My downloader class 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"); } } }
Related Links
Spring REST #RequestMapping practices
Java return multiple strings in one method
How to hold a button and change its size to fullscreen
How to return a String in an inherited class?
getId() on view obtained from recyclerView.findChildViewUnder(e.getX(), e.getY()) is -1
Null handling in Java 1.7 and 1.6
Java Programming , Type Casting
RecyclerView GridLayoutManager first row with 2 items
Reading Linux Repositories from Third Party
why function are not getting executed in sequence?
Java - Jersey GET request returns null; equivalent URL produces correct output in browser
Deploy a WebService from the command line or a script
How do I send a variable to external scope in Thymeleaf?
NullPointerException in broadleaf AdminAuditableListener
Using Timer in a stateless EJB method to time out long-running operation
How do I make it so JOptionPane.showMessageDialog can sense multiple strings?