Send download failed event if we received less bytes than expected.
[xudocci.git] / src / main / java / net / pterodactylus / irc / DccReceiver.java
index 9ddca13..ed59c69 100644 (file)
@@ -155,7 +155,7 @@ public class DccReceiver extends AbstractExecutionThreadService {
         * @return The current rate of the download, in bytes/second
         */
        public long currentRate() {
-               return inputStream.getCurrentRate();
+               return (inputStream != null) ? inputStream.getCurrentRate() : 0;
        }
 
        /**
@@ -164,7 +164,7 @@ public class DccReceiver extends AbstractExecutionThreadService {
         * @return The overall rate of the download, in bytes/second
         */
        public long overallRate() {
-               return inputStream.getOverallRate();
+               return (inputStream != null) ? inputStream.getOverallRate() : 0;
        }
 
        //
@@ -189,7 +189,11 @@ public class DccReceiver extends AbstractExecutionThreadService {
                                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));