Search in sources :

Example 1 with HttpDownCallback

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);
}
Also used : HttpDownCallback(org.pdown.core.dispatch.HttpDownCallback) HttpDownBootstrap(org.pdown.core.boot.HttpDownBootstrap) File(java.io.File) IOException(java.io.IOException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 HttpDownBootstrap (org.pdown.core.boot.HttpDownBootstrap)1 HttpDownCallback (org.pdown.core.dispatch.HttpDownCallback)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1