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(); - } -}