Egads, don't share a download buffer.
Fragile assumptions, they plague us. Fixes #166
This commit is contained in:
@@ -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. */
|
/** The bytes downloaded for each resource. */
|
||||||
protected Map<Resource, Long> _downloaded = new HashMap<>();
|
protected Map<Resource, Long> _downloaded = new HashMap<>();
|
||||||
|
|
||||||
/** Used while downloading. */
|
|
||||||
protected byte[] _buffer = new byte[4096];
|
|
||||||
|
|
||||||
/** The time at which the file transfer began. */
|
/** The time at which the file transfer began. */
|
||||||
protected long _start;
|
protected long _start;
|
||||||
|
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ public class HTTPDownloader extends Downloader
|
|||||||
long actualSize = conn.getContentLength();
|
long actualSize = conn.getContentLength();
|
||||||
log.info("Downloading resource", "url", rsrc.getRemote(), "size", actualSize);
|
log.info("Downloading resource", "url", rsrc.getRemote(), "size", actualSize);
|
||||||
long currentSize = 0L;
|
long currentSize = 0L;
|
||||||
|
byte[] buffer = new byte[4*4096];
|
||||||
try (InputStream in = conn.getInputStream();
|
try (InputStream in = conn.getInputStream();
|
||||||
FileOutputStream out = new FileOutputStream(rsrc.getLocalNew())) {
|
FileOutputStream out = new FileOutputStream(rsrc.getLocalNew())) {
|
||||||
|
|
||||||
@@ -78,13 +79,13 @@ public class HTTPDownloader extends Downloader
|
|||||||
|
|
||||||
// read in the file data
|
// read in the file data
|
||||||
int read;
|
int read;
|
||||||
while ((read = in.read(_buffer)) != -1) {
|
while ((read = in.read(buffer)) != -1) {
|
||||||
// abort the download if the downloader is aborted
|
// abort the download if the downloader is aborted
|
||||||
if (_state == State.ABORTED) {
|
if (_state == State.ABORTED) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// write it out to our local copy
|
// write it out to our local copy
|
||||||
out.write(_buffer, 0, read);
|
out.write(buffer, 0, read);
|
||||||
// note that we've downloaded some data
|
// note that we've downloaded some data
|
||||||
currentSize += read;
|
currentSize += read;
|
||||||
reportProgress(rsrc, currentSize, actualSize);
|
reportProgress(rsrc, currentSize, actualSize);
|
||||||
|
|||||||
Reference in New Issue
Block a user