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?

Categories

HOME
pandas
bluetooth
clips
hive
webstorm
jxls
contact
facebook-messenger-bot
facebook-php-sdk
user-input
mapserver
n-gram
orleans
captiveportal
microsoft-r
opentype
google-cloud-nl
delicious-api
nameservers
javascriptcore
ecto
karaf
pim
subset-sum
cloud-code
catalog
simplexml
x11-forwarding
az-application-insights
grid.mvc
eigenvalue
password-encryption
bootstrap-dialog
skeleton-css-boilerplate
fancybox-2
zendesk-app
blacklist
messenger
slicknav
google-web-starter-kit
firebaseui
gstreamer-0.10
jwplayer7
sigabrt
actionbardrawertoggle
revolution-r
wapiti
freelancer.com-api
unity-networking
content-length
appfabric-cache
pretty-print
bridge.net
qpainter
gui-test-framework
cctv
fluentautomation
phpthumb
fmod
floating-point-precision
sitemesh
apc
dataservice
file-locking
pygit2
lcs
dsn
bubble-chart
bigcouch
subscript
window-management
recent-documents
yui-datatable
propagation
h.323
createwindow
digest-authentication
icanhaz.js
mozilla-prism
xsdobjectgen
perfect-hash
firefox-5
fixed-width
multi-tier
nintendo-ds
microsoft-virtualization
uimenucontroller
xetex
windows-live-messenger
uiq3

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile