From d06fcafdc70835fe59db1b6216932dfd5851fb2c Mon Sep 17 00:00:00 2001 From: zaxar163 Date: Fri, 8 Mar 2019 16:39:27 +0300 Subject: [PATCH] =?UTF-8?q?[FEATURE]=20=D0=93=D0=BE=D1=82=D0=BE=D0=B2=20Do?= =?UTF-8?q?wnloader.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fileserver/FileServerHandler.java | 16 --------- .../gravit/utils/downloader/Downloader.java | 8 +++++ .../utils/downloader/DownloadingThread.java | 34 ------------------- 3 files changed, 8 insertions(+), 50 deletions(-) delete mode 100644 libLauncher/src/main/java/ru/gravit/utils/downloader/DownloadingThread.java diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/fileserver/FileServerHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/fileserver/FileServerHandler.java index 3b78e8ad..8d6165d1 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/fileserver/FileServerHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/fileserver/FileServerHandler.java @@ -130,22 +130,6 @@ public void channelRead0(ChannelHandlerContext ctx, FullHttpRequest request) thr lastContentFuture = sendFileFuture; } - sendFileFuture.addListener(new ChannelProgressiveFutureListener() { - @Override - public void operationProgressed(ChannelProgressiveFuture future, long progress, long total) { - if (total < 0) { // total unknown - System.err.println(future.channel() + " Transfer progress: " + progress); - } else { - System.err.println(future.channel() + " Transfer progress: " + progress + " / " + total); - } - } - - @Override - public void operationComplete(ChannelProgressiveFuture future) { - System.err.println(future.channel() + " Transfer complete."); - } - }); - // Decide whether to close the connection or not. if (!HttpUtil.isKeepAlive(request)) { lastContentFuture.addListener(new ClosingChannelFutureListener(raf)); diff --git a/libLauncher/src/main/java/ru/gravit/utils/downloader/Downloader.java b/libLauncher/src/main/java/ru/gravit/utils/downloader/Downloader.java index 12dfa4c1..9187a1f8 100644 --- a/libLauncher/src/main/java/ru/gravit/utils/downloader/Downloader.java +++ b/libLauncher/src/main/java/ru/gravit/utils/downloader/Downloader.java @@ -39,6 +39,8 @@ public interface Handler { private final int skip; private final Handler handler; + private HttpURLConnection connect = null; + public Downloader(URL url, File file) { this.requestProps = new HashMap<>(requestClient); this.file = file; @@ -128,6 +130,7 @@ public void downloadFile() throws IOException { interrupted.set(false); if (url.getProtocol().equalsIgnoreCase("http")) { HttpURLConnection connect = (HttpURLConnection) (url).openConnection(); + this.connect = connect; if (method != null) connect.setRequestMethod(method); for (Map.Entry ent : requestProps.entrySet()) { connect.setRequestProperty(ent.getKey(), ent.getValue()); @@ -158,6 +161,7 @@ public void downloadFile() throws IOException { } } else { HttpsURLConnection connect = (HttpsURLConnection) (url).openConnection(); + this.connect = connect; if (method != null) connect.setRequestMethod(method); for (Map.Entry ent : requestProps.entrySet()) { connect.setRequestProperty(ent.getKey(), ent.getValue()); @@ -200,5 +204,9 @@ public void run() { this.ex.set(ex); LogHelper.error(ex); } + if (connect != null) + try { + connect.disconnect(); + } catch (Throwable ignored) { } } } diff --git a/libLauncher/src/main/java/ru/gravit/utils/downloader/DownloadingThread.java b/libLauncher/src/main/java/ru/gravit/utils/downloader/DownloadingThread.java deleted file mode 100644 index 01fb2691..00000000 --- a/libLauncher/src/main/java/ru/gravit/utils/downloader/DownloadingThread.java +++ /dev/null @@ -1,34 +0,0 @@ -package ru.gravit.utils.downloader; - -import java.io.File; -import java.net.URL; - -public class DownloadingThread extends Thread { - private final Downloader runnable; - - public DownloadingThread(File file, URL url, String name) { - super(name); - runnable = new Downloader(url, file); - } - - public Downloader getDownloader() { - return runnable; - } - - @Override - public void interrupt() { - runnable.interrupt.set(true); - while (!runnable.interrupted.get()) { - } - super.interrupt(); - } - - public void hardInterrupt() { - super.interrupt(); - } - - @Override - public void run() { - runnable.run(); - } -}