use of org.pdown.core.dispatch.HttpDownCallback in project proxyee-down by monkeyWie.
the class NativeController method doUpdate.
@RequestMapping("doUpdate")
public FullHttpResponse doUpdate(Channel channel, FullHttpRequest request) throws Exception {
Map<String, Object> map = getJSONParams(request);
String url = (String) map.get("path");
String path = PathUtil.ROOT_PATH + File.separator + "proxyee-down-main.jar.tmp";
try {
File updateTmpJar = new File(path);
if (updateTmpJar.exists()) {
updateTmpJar.delete();
}
updateBootstrap = AppUtil.fastDownload(url, updateTmpJar, new HttpDownCallback() {
@Override
public void onDone(HttpDownBootstrap httpDownBootstrap) {
File updateBakJar = new File(updateTmpJar.getParent() + File.separator + "proxyee-down-main.jar.bak");
updateTmpJar.renameTo(updateBakJar);
}
@Override
public void onError(HttpDownBootstrap httpDownBootstrap) {
File file = new File(path);
if (file.exists()) {
file.delete();
}
httpDownBootstrap.close();
}
});
} catch (Exception e) {
throw e;
}
return new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
}
Aggregations