X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Firc%2FDccReceiver.java;h=be4f1453aeffbfac0f8f6875d08a5c6ea6e93531;hb=7b59d18363cde726bd18d80571054442671d1a34;hp=56a3853da7aa3b4913ba44599fef2ee9b030eb2b;hpb=907f0d44b3905788e3984f4d19d79a444eafe9f2;p=xudocci.git diff --git a/src/main/java/net/pterodactylus/irc/DccReceiver.java b/src/main/java/net/pterodactylus/irc/DccReceiver.java index 56a3853..be4f145 100644 --- a/src/main/java/net/pterodactylus/irc/DccReceiver.java +++ b/src/main/java/net/pterodactylus/irc/DccReceiver.java @@ -85,10 +85,32 @@ public class DccReceiver extends AbstractExecutionThreadService { * The output stream to write the file to */ public DccReceiver(EventBus eventBus, InetAddress inetAddress, int port, String filename, long size, OutputStream outputStream) { + this(eventBus, inetAddress, port, filename, 0, size, outputStream); + } + + /** + * Creates a new DCC receiver. + * + * @param inetAddress + * The address to connect to + * @param port + * The port number to connect to + * @param filename + * The name of the file being downloaded + * @param startOffset + * The offset at which the download starts in case of a resume + * @param size + * The size of the file being downloaded, or {@code -1} if the size is not + * known + * @param outputStream + * The output stream to write the file to + */ + public DccReceiver(EventBus eventBus, InetAddress inetAddress, int port, String filename, long startOffset, long size, OutputStream outputStream) { this.eventBus = eventBus; this.inetAddress = inetAddress; this.port = port; this.filename = filename; + this.progress = startOffset; this.size = size; this.outputStream = outputStream; } @@ -133,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; } /** @@ -142,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; } // @@ -173,7 +195,9 @@ public class DccReceiver extends AbstractExecutionThreadService { eventBus.post(new DccDownloadFailed(this, ioe1)); } finally { Closeables.close(inputStream, true); - socket.close(); + if (socket != null) { + socket.close(); + } } }