import java.util.logging.Level;
import java.util.logging.Logger;
+import net.pterodactylus.irc.event.DccDownloadFailed;
+import net.pterodactylus.irc.event.DccDownloadFinished;
import net.pterodactylus.irc.event.DccSendReceived;
import net.pterodactylus.xdcc.util.io.BandwidthCountingInputStream;
+import com.google.common.eventbus.EventBus;
import com.google.common.io.Closeables;
import com.google.common.util.concurrent.AbstractExecutionThreadService;
/** The logger. */
private static final Logger logger = Logger.getLogger(DccReceiver.class.getName());
+ /** The event bus. */
+ private final EventBus eventBus;
+
/** The address to connect to. */
private final InetAddress inetAddress;
* @param outputStream
* The output stream to write the file to
*/
- public DccReceiver(InetAddress inetAddress, int port, String filename, long size, OutputStream outputStream) {
+ public DccReceiver(EventBus eventBus, InetAddress inetAddress, int port, String filename, long size, OutputStream outputStream) {
+ this.eventBus = eventBus;
this.inetAddress = inetAddress;
this.port = port;
this.filename = filename;
progress += r;
}
outputStream.flush();
+ eventBus.post(new DccDownloadFinished(this));
} catch (IOException ioe1) {
logger.log(Level.WARNING, "I/O error while receiving DCC!", ioe1);
+ eventBus.post(new DccDownloadFailed(this, ioe1));
} finally {
Closeables.close(inputStream, true);
socket.close();
logger.info(String.format("Starting download of %s.", dccSendReceived.filename()));
try {
OutputStream fileOutputStream = new FileOutputStream(new File("/home/bombe/Temp", dccSendReceived.filename()));
- DccReceiver dccReceiver = new DccReceiver(dccSendReceived.inetAddress(), dccSendReceived.port(), dccSendReceived.filename(), dccSendReceived.filesize(), fileOutputStream);
+ DccReceiver dccReceiver = new DccReceiver(eventBus, dccSendReceived.inetAddress(), dccSendReceived.port(), dccSendReceived.filename(), dccSendReceived.filesize(), fileOutputStream);
dccReceivers.add(dccReceiver);
dccReceiver.start();
} catch (FileNotFoundException fnfe1) {