5190ed054faa991c588ebc4274fe35d40023dfff
[xudocci.git] / src / main / java / net / pterodactylus / xdcc / data / Download.java
1 /*
2  * XdccDownloader - Download.java - Copyright © 2013 David Roden
3  *
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.
8  *
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.
13  *
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/>.
16  */
17
18 package net.pterodactylus.xdcc.data;
19
20 import java.io.OutputStream;
21 import java.net.InetAddress;
22
23 import net.pterodactylus.irc.DccReceiver;
24
25 /**
26  * Information about an ongoing download.
27  *
28  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
29  */
30 public class Download {
31
32         /** The bot that is being downloaded from. */
33         private final Bot bot;
34
35         /** The pack that is being downloaded. */
36         private final Pack pack;
37
38         /** The name of the file being downloaded. */
39         private String filename;
40
41         /** The size of the file being downloaded. */
42         private long filesize;
43
44         /** The remote address. */
45         private InetAddress remoteAddress;
46
47         /** The output stream. */
48         private OutputStream outputStream;
49
50         /** The DCC receiver. */
51         private DccReceiver dccReceiver;
52
53         /**
54          * Creates a new download.
55          *
56          * @param bot
57          *              The bot offering the download
58          * @param pack
59          *              The pack being downloaded
60          */
61         public Download(Bot bot, Pack pack) {
62                 this.bot = bot;
63                 this.pack = pack;
64         }
65
66         //
67         // ACCESSORS
68         //
69
70         /**
71          * Returns the bot offering the download.
72          *
73          * @return The bot offering the download
74          */
75         public Bot bot() {
76                 return bot;
77         }
78
79         /**
80          * The pack that is being downloaded.
81          *
82          * @return The pack being downloaded
83          */
84         public Pack pack() {
85                 return pack;
86         }
87
88         /**
89          * The full name of the file being written.
90          *
91          * @return The full name of the file
92          */
93         public String filename() {
94                 return filename;
95         }
96
97         /**
98          * Returns the size of the file.
99          *
100          * @return The size of the file
101          */
102         public long filesize() {
103                 return filesize;
104         }
105
106         /**
107          * Returns the remote address to download from.
108          *
109          * @return The remote address to download from
110          */
111         public InetAddress remoteAddress() {
112                 return remoteAddress;
113         }
114
115         /**
116          * The output stream that writes to the file.
117          *
118          * @return The output stream
119          */
120         public OutputStream outputStream() {
121                 return outputStream;
122         }
123
124         /**
125          * The DCC receiver that is downloading the file
126          *
127          * @return The DCC receiver
128          */
129         public DccReceiver dccReceiver() {
130                 return dccReceiver;
131         }
132
133         //
134         // MUTATORS
135         //
136
137         /**
138          * Sets the full name of the file being downloaded.
139          *
140          * @param filename
141          *              The full name of the file
142          * @return This download
143          */
144         public Download filename(String filename) {
145                 this.filename = filename;
146                 return this;
147         }
148
149         /**
150          * Sets the size of the download.
151          *
152          * @param filesize
153          *              The size of the download
154          * @return This download
155          */
156         public Download filesize(long filesize) {
157                 this.filesize = filesize;
158                 return this;
159         }
160
161         /**
162          * Sets the remote address of the download.
163          *
164          * @param remoteAddress
165          *              The remote address of the download
166          * @return This download
167          */
168         public Download remoteAddress(InetAddress remoteAddress) {
169                 this.remoteAddress = remoteAddress;
170                 return this;
171         }
172
173         /**
174          * Sets the output stream the download is being written to
175          *
176          * @param outputStream
177          *              The output stream
178          * @return This download
179          */
180         public Download outputStream(OutputStream outputStream) {
181                 this.outputStream = outputStream;
182                 return this;
183         }
184
185         /**
186          * Sets the DCC receiver that downloads the file.
187          *
188          * @param dccReceiver
189          *              The DCC receiver
190          * @return This download
191          */
192         public Download dccReceiver(DccReceiver dccReceiver) {
193                 this.dccReceiver = dccReceiver;
194                 return this;
195         }
196
197 }