From 7a8de58e4d6f82f7f3f52f32f571c07499f622ca Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Tue, 27 Nov 2018 13:31:02 -0800 Subject: [PATCH] Egads, don't share a download buffer. Fragile assumptions, they plague us. Fixes #166 --- .../getdown/net/DownloadAbortedException.java | 15 --------------- .../com/threerings/getdown/net/Downloader.java | 3 --- .../threerings/getdown/net/HTTPDownloader.java | 5 +++-- 3 files changed, 3 insertions(+), 20 deletions(-) delete mode 100644 core/src/main/java/com/threerings/getdown/net/DownloadAbortedException.java diff --git a/core/src/main/java/com/threerings/getdown/net/DownloadAbortedException.java b/core/src/main/java/com/threerings/getdown/net/DownloadAbortedException.java deleted file mode 100644 index 77760df..0000000 --- a/core/src/main/java/com/threerings/getdown/net/DownloadAbortedException.java +++ /dev/null @@ -1,15 +0,0 @@ -// -// Getdown - application installer, patcher and launcher -// Copyright (C) 2004-2016 Getdown authors -// https://github.com/threerings/getdown/blob/master/LICENSE - -package com.threerings.getdown.net; - -import java.io.IOException; - -/** - * Used to terminate the download process in its midst. - */ -public class DownloadAbortedException extends IOException -{ -} diff --git a/core/src/main/java/com/threerings/getdown/net/Downloader.java b/core/src/main/java/com/threerings/getdown/net/Downloader.java index 277478f..f5a8c36 100644 --- a/core/src/main/java/com/threerings/getdown/net/Downloader.java +++ b/core/src/main/java/com/threerings/getdown/net/Downloader.java @@ -211,9 +211,6 @@ public abstract class Downloader /** The bytes downloaded for each resource. */ protected Map _downloaded = new HashMap<>(); - /** Used while downloading. */ - protected byte[] _buffer = new byte[4096]; - /** The time at which the file transfer began. */ protected long _start; diff --git a/core/src/main/java/com/threerings/getdown/net/HTTPDownloader.java b/core/src/main/java/com/threerings/getdown/net/HTTPDownloader.java index acd78c0..9f3be58 100644 --- a/core/src/main/java/com/threerings/getdown/net/HTTPDownloader.java +++ b/core/src/main/java/com/threerings/getdown/net/HTTPDownloader.java @@ -69,6 +69,7 @@ public class HTTPDownloader extends Downloader long actualSize = conn.getContentLength(); log.info("Downloading resource", "url", rsrc.getRemote(), "size", actualSize); long currentSize = 0L; + byte[] buffer = new byte[4*4096]; try (InputStream in = conn.getInputStream(); FileOutputStream out = new FileOutputStream(rsrc.getLocalNew())) { @@ -78,13 +79,13 @@ public class HTTPDownloader extends Downloader // read in the file data int read; - while ((read = in.read(_buffer)) != -1) { + while ((read = in.read(buffer)) != -1) { // abort the download if the downloader is aborted if (_state == State.ABORTED) { break; } // write it out to our local copy - out.write(_buffer, 0, read); + out.write(buffer, 0, read); // note that we've downloaded some data currentSize += read; reportProgress(rsrc, currentSize, actualSize);