Egads, don't share a download buffer.

Fragile assumptions, they plague us.

Fixes #166
This commit is contained in:
Michael Bayne
2018-11-27 13:31:02 -08:00
parent 8017dcc359
commit 7a8de58e4d
3 changed files with 3 additions and 20 deletions
@@ -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
{
}
@@ -211,9 +211,6 @@ public abstract class Downloader
/** The bytes downloaded for each resource. */
protected Map<Resource, Long> _downloaded = new HashMap<>();
/** Used while downloading. */
protected byte[] _buffer = new byte[4096];
/** The time at which the file transfer began. */
protected long _start;
@@ -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);