303569e05a76164f70fc7370b07fbbd2bdb28203
[jFCPlib.git] / src / net / pterodactylus / fcp / ClientGet.java
1 /*
2  * jSite2 - ClientGet.java -
3  * Copyright © 2008 David Roden
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 package net.pterodactylus.fcp;
21
22 /**
23  * A “ClientGet” request is used for download files from the Freenet node.
24  * 
25  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
26  */
27 public class ClientGet extends FcpMessage {
28
29         /**
30          * Creates a new “ClientGet” request.
31          * 
32          * @param uri
33          *            The URI to get
34          * @param identifier
35          *            The identifier of the request
36          */
37         public ClientGet(String uri, String identifier) {
38                 this(uri, identifier, ReturnType.direct);
39         }
40
41         /**
42          * Creates a new “ClientGet” request.
43          * 
44          * @param uri
45          *            The URI to get
46          * @param identifier
47          *            The identifier of the request
48          * @param returnType
49          *            The return type of the request
50          */
51         public ClientGet(String uri, String identifier, ReturnType returnType) {
52                 super("ClientGet");
53                 setField("URI", uri);
54                 setField("Identifier", identifier);
55                 setField("ReturnType", String.valueOf(returnType));
56         }
57
58         /**
59          * Sets whether the local data store should be ignored when searching for a
60          * key.
61          * 
62          * @param ignoreDataStore
63          *            <code>true</code> to ignore the local data store,
64          *            <code>false</code> to include it
65          */
66         public void setIgnoreDataStore(boolean ignoreDataStore) {
67                 setField("IgnoreDS", String.valueOf(ignoreDataStore));
68         }
69
70         /**
71          * Sets whether the search for the key should be restricted to the local
72          * data store only.
73          * 
74          * @param dsOnly
75          *            <code>true</code> to restrict the search to the local data
76          *            store, <code>false</code> to search on other nodes, too
77          */
78         public void setDataStoreOnly(boolean dsOnly) {
79                 setField("DSonly", String.valueOf(dsOnly));
80         }
81
82         /**
83          * Sets the verbosity of the request.
84          * 
85          * @param verbosity
86          *            The verbosity of the request
87          */
88         public void setVerbosity(Verbosity verbosity) {
89                 setField("Verbosity", String.valueOf(verbosity));
90         }
91
92         /**
93          * Sets the maximum size of the file to retrieve. If the file is larger than
94          * this size the request will fail!
95          * 
96          * @param maxSize
97          *            The maximum size of the file to retrieve
98          */
99         public void setMaxSize(long maxSize) {
100                 setField("MaxSize", String.valueOf(maxSize));
101         }
102
103         /**
104          * Sets the maximum size of temporary files created by the node. If a
105          * temporary file is larger than this size the request will fail!
106          * 
107          * @param maxTempSize
108          *            The maximum size of temporary files
109          */
110         public void setMaxTempSize(long maxTempSize) {
111                 setField("MaxTempSize", String.valueOf(maxTempSize));
112         }
113
114         /**
115          * The maximum number of retries in case a block can not be retrieved.
116          * 
117          * @param maxRetries
118          *            The maximum number of retries for failed blocks,
119          *            <code>-1</code> to try forever
120          */
121         public void setMaxRetries(int maxRetries) {
122                 setField("MaxRetries", String.valueOf(maxRetries));
123         }
124
125         /**
126          * Sets the priority of the request.
127          * 
128          * @param priority
129          *            The priority of the request
130          */
131         public void setPriority(Priority priority) {
132                 setField("PriorityClass", String.valueOf(priority));
133         }
134
135         /**
136          * Sets the persistence of the request.
137          * 
138          * @param persistence
139          *            The persistence of the request
140          */
141         public void setPersistence(Persistence persistence) {
142                 setField("Persistence", String.valueOf(persistence));
143         }
144
145         /**
146          * Sets the client token of the request.
147          * 
148          * @param clientToken
149          *            The client token of the request
150          */
151         public void setClientToken(String clientToken) {
152                 setField("ClientToken", clientToken);
153         }
154
155         /**
156          * Sets whether the request should be visible on the global queue.
157          * 
158          * @param global
159          *            <code>true</code> to make the request visible on the global
160          *            queue, <code>false</code> for client-local queue only
161          */
162         public void setGlobal(boolean global) {
163                 setField("Global", String.valueOf(global));
164         }
165
166         /**
167          * Sets whether to request the “binary blob” for a key.
168          * 
169          * @param binaryBlob
170          *            <code>true</code> to request the binary blob,
171          *            <code>false</code> to get the “real thing”
172          */
173         public void setBinaryBlob(boolean binaryBlob) {
174                 setField("BinaryBlob", String.valueOf(binaryBlob));
175         }
176
177         /**
178          * Sets the allowed MIME types of the requested file. If the MIME type of
179          * the file does not match one of the given MIME types the request will
180          * fail!
181          * 
182          * @param allowedMimeTypes
183          *            The allowed MIME types
184          */
185         public void setAllowedMimeTypes(String... allowedMimeTypes) {
186                 setField("AllowedMIMETypes", FcpUtils.encodeMultiStringField(allowedMimeTypes));
187         }
188
189         /**
190          * Sets the filename to download the file to. You should only call this
191          * method if your return type is {@link ReturnType#disk}!
192          * 
193          * @param filename
194          *            The filename to download the file to
195          */
196         public void setFilename(String filename) {
197                 setField("Filename", filename);
198         }
199
200         /**
201          * Sets the name for the temporary file. You should only call this method if
202          * your return type is {@link ReturnType#disk}!
203          * 
204          * @param tempFilename
205          *            The name of the temporary file
206          */
207         public void setTempFilename(String tempFilename) {
208                 setField("TempFilename", tempFilename);
209         }
210
211 }