import net.pterodactylus.irc.event.ChannelJoined;
import net.pterodactylus.irc.event.ChannelMessageReceived;
import net.pterodactylus.irc.event.ConnectionEstablished;
+import net.pterodactylus.irc.event.DccDownloadFailed;
import net.pterodactylus.irc.event.DccDownloadFinished;
import net.pterodactylus.irc.event.DccSendReceived;
import net.pterodactylus.irc.util.MessageCleaner;
import net.pterodactylus.irc.util.RandomNickname;
import net.pterodactylus.xdcc.core.event.BotAdded;
import net.pterodactylus.xdcc.core.event.CoreStarted;
+import net.pterodactylus.xdcc.core.event.DownloadFailed;
import net.pterodactylus.xdcc.core.event.DownloadFinished;
import net.pterodactylus.xdcc.core.event.DownloadStarted;
import net.pterodactylus.xdcc.data.Bot;
import com.google.common.collect.Table;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
+import com.google.common.io.Closeables;
import com.google.common.util.concurrent.AbstractIdleService;
import com.google.inject.Inject;
}
}
+ /**
+ * Closes the output stream and notifies all listeners of the failure.
+ *
+ * @param dccDownloadFailed
+ * The DCC download failed event
+ */
+ @Subscribe
+ public void dccDownloadFailed(DccDownloadFailed dccDownloadFailed) {
+ Download download = downloads.get(dccDownloadFailed.dccReceiver().filename());
+ if (download == null) {
+ /* probably shouldn’t happen. */
+ return;
+ }
+
+ try {
+ Closeables.close(download.outputStream(), true);
+ eventBus.post(new DownloadFailed(download));
+ } catch (IOException ioe1) {
+ /* swallow silently. */
+ }
+ }
+
//
// PRIVATE METHODS
//
--- /dev/null
+/*
+ * XdccDownloader - DownloadFailed.java - Copyright © 2013 David Roden
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.xdcc.core.event;
+
+import net.pterodactylus.xdcc.data.Download;
+
+/**
+ * Notifies a listener that a {@link Download} has failed.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class DownloadFailed extends AbstractDownloadEvent {
+
+ /**
+ * Creates a new download finished event.
+ *
+ * @param download
+ * The download that finished
+ */
+ public DownloadFailed(Download download) {
+ super(download);
+ }
+
+}