* @return The current rate of the download, in bytes/second
*/
public long currentRate() {
- return inputStream.getCurrentRate();
+ return (inputStream != null) ? inputStream.getCurrentRate() : 0;
}
/**
* @return The overall rate of the download, in bytes/second
*/
public long overallRate() {
- return inputStream.getOverallRate();
+ return (inputStream != null) ? inputStream.getOverallRate() : 0;
}
//
Socket socket = null;
try {
socket = new Socket(inetAddress, port);
+ socket.setSoTimeout((int) TimeUnit.MINUTES.toMillis(3));
InputStream socketInputStream = socket.getInputStream();
inputStream = new BandwidthCountingInputStream(socketInputStream, 5, TimeUnit.SECONDS);
byte[] buffer = new byte[65536];
progress += r;
}
outputStream.flush();
- eventBus.post(new DccDownloadFinished(this));
+ if ((size == -1) || (progress == size)) {
+ eventBus.post(new DccDownloadFinished(this));
+ } else {
+ eventBus.post(new DccDownloadFailed(this, new IOException("Download aborted.")));
+ }
} catch (IOException ioe1) {
logger.log(Level.WARNING, "I/O error while receiving DCC!", ioe1);
eventBus.post(new DccDownloadFailed(this, ioe1));