2 * XdccDownloader - Download.java - Copyright © 2013 David Roden
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net.pterodactylus.xdcc.data;
20 import static com.google.common.base.Preconditions.checkNotNull;
22 import java.io.OutputStream;
23 import java.net.InetAddress;
25 import net.pterodactylus.irc.DccReceiver;
28 * Information about an ongoing download.
30 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
32 public class Download {
34 /** The bot that is being downloaded from. */
35 private final Bot bot;
37 /** The pack that is being downloaded. */
38 private final Pack pack;
40 /** The name of the file being downloaded. */
41 private String filename;
43 /** The size of the file being downloaded. */
44 private long filesize;
46 /** The remote address. */
47 private InetAddress remoteAddress;
49 /** The output stream. */
50 private OutputStream outputStream;
52 /** The DCC receiver. */
53 private DccReceiver dccReceiver;
56 * Creates a new download.
59 * The bot offering the download
61 * The pack being downloaded
63 public Download(Bot bot, Pack pack) {
64 this.bot = checkNotNull(bot, "bot must not be null");
65 this.pack = checkNotNull(pack, "pack must not be null");
73 * Returns the bot offering the download.
75 * @return The bot offering the download
82 * The pack that is being downloaded.
84 * @return The pack being downloaded
91 * The full name of the file being written.
93 * @return The full name of the file
95 public String filename() {
100 * Returns the size of the file.
102 * @return The size of the file
104 public long filesize() {
109 * Returns the remote address to download from.
111 * @return The remote address to download from
113 public InetAddress remoteAddress() {
114 return remoteAddress;
118 * The output stream that writes to the file.
120 * @return The output stream
122 public OutputStream outputStream() {
127 * The DCC receiver that is downloading the file
129 * @return The DCC receiver
131 public DccReceiver dccReceiver() {
140 * Sets the full name of the file being downloaded.
143 * The full name of the file
144 * @return This download
146 public Download filename(String filename) {
147 this.filename = filename;
152 * Sets the size of the download.
155 * The size of the download
156 * @return This download
158 public Download filesize(long filesize) {
159 this.filesize = filesize;
164 * Sets the remote address of the download.
166 * @param remoteAddress
167 * The remote address of the download
168 * @return This download
170 public Download remoteAddress(InetAddress remoteAddress) {
171 this.remoteAddress = remoteAddress;
176 * Sets the output stream the download is being written to
178 * @param outputStream
180 * @return This download
182 public Download outputStream(OutputStream outputStream) {
183 this.outputStream = outputStream;
188 * Sets the DCC receiver that downloads the file.
192 * @return This download
194 public Download dccReceiver(DccReceiver dccReceiver) {
195 this.dccReceiver = dccReceiver;
204 public boolean equals(Object object) {
205 if (!(object instanceof Download)) {
208 Download download = (Download) object;
209 return bot().equals(download.bot()) && pack().equals(download.pack());
213 public int hashCode() {
214 return bot().hashCode() ^ pack().hashCode();