Search in sources :

Example 1 with HttpDownBootstrap

use of org.pdown.core.boot.HttpDownBootstrap in project proxyee-down by monkeyWie.

the class AppUtil method fastDownload.

/**
 * 使用pdown-core多连接下载http资源
 */
public static HttpDownBootstrap fastDownload(String url, File file, HttpDownCallback callback) throws IOException {
    HttpDownBootstrap httpDownBootstrap = new URLHttpDownBootstrapBuilder(url, null, null).callback(callback).downConfig(new HttpDownConfigInfo().setFilePath(file.getParent()).setConnections(64)).response(new HttpResponseInfo().setFileName(file.getName())).proxyConfig(PDownConfigContent.getInstance().get().getProxyConfig()).build();
    httpDownBootstrap.start();
    return httpDownBootstrap;
}
Also used : HttpResponseInfo(org.pdown.core.entity.HttpResponseInfo) URLHttpDownBootstrapBuilder(org.pdown.core.boot.URLHttpDownBootstrapBuilder) HttpDownBootstrap(org.pdown.core.boot.HttpDownBootstrap) HttpDownConfigInfo(org.pdown.core.entity.HttpDownConfigInfo)

Example 2 with HttpDownBootstrap

use of org.pdown.core.boot.HttpDownBootstrap 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

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