rename fcplib to jFCPlib
[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  * @version $Id$
27  */
28 public class ClientGet extends FcpMessage {
29
30         /**
31          * Creates a new “ClientGet” request.
32          * 
33          * @param uri
34          *            The URI to get
35          * @param identifier
36          *            The identifier of the request
37          */
38         public ClientGet(String uri, String identifier) {
39                 this(uri, identifier, ReturnType.direct);
40         }
41
42         /**
43          * Creates a new “ClientGet” request.
44          * 
45          * @param uri
46          *            The URI to get
47          * @param identifier
48          *            The identifier of the request
49          * @param returnType
50          *            The return type of the request
51          */
52         public ClientGet(String uri, String identifier, ReturnType returnType) {
53                 super("ClientGet");
54                 setField("URI", uri);
55                 setField("Identifier", identifier);
56                 setField("ReturnType", String.valueOf(returnType));
57         }
58
59         /**
60          * Sets whether the local data store should be ignored when searching for a
61          * key.
62          * 
63          * @param ignoreDataStore
64          *            <code>true</code> to ignore the local data store,
65          *            <code>false</code> to include it
66          */
67         public void setIgnoreDataStore(boolean ignoreDataStore) {
68                 setField("IgnoreDS", String.valueOf(ignoreDataStore));
69         }
70
71         /**
72          * Sets whether the search for the key should be restricted to the local
73          * data store only.
74          * 
75          * @param dsOnly
76          *            <code>true</code> to restrict the search to the local data
77          *            store, <code>false</code> to search on other nodes, too
78          */
79         public void setDataStoreOnly(boolean dsOnly) {
80                 setField("DSonly", String.valueOf(dsOnly));
81         }
82
83         /**
84          * Sets the verbosity of the request.
85          * 
86          * @param verbosity
87          *            The verbosity of the request
88          */
89         public void setVerbosity(Verbosity verbosity) {
90                 setField("Verbosity", String.valueOf(verbosity));
91         }
92
93         /**
94          * Sets the maximum size of the file to retrieve. If the file is larger than
95          * this size the request will fail!
96          * 
97          * @param maxSize
98          *            The maximum size of the file to retrieve
99          */
100         public void setMaxSize(long maxSize) {
101                 setField("MaxSize", String.valueOf(maxSize));
102         }
103
104         /**
105          * Sets the maximum size of temporary files created by the node. If a
106          * temporary file is larger than this size the request will fail!
107          * 
108          * @param maxTempSize
109          *            The maximum size of temporary files
110          */
111         public void setMaxTempSize(long maxTempSize) {
112                 setField("MaxTempSize", String.valueOf(maxTempSize));
113         }
114
115         /**
116          * The maximum number of retries in case a block can not be retrieved.
117          * 
118          * @param maxRetries
119          *            The maximum number of retries for failed blocks,
120          *            <code>-1</code> to try forever
121          */
122         public void setMaxRetries(int maxRetries) {
123                 setField("MaxRetries", String.valueOf(maxRetries));
124         }
125
126         /**
127          * Sets the priority of the request.
128          * 
129          * @param priority
130          *            The priority of the request
131          */
132         public void setPriority(Priority priority) {
133                 setField("PriorityClass", String.valueOf(priority));
134         }
135
136         /**
137          * Sets the persistence of the request.
138          * 
139          * @param persistence
140          *            The persistence of the request
141          */
142         public void setPersistence(Persistence persistence) {
143                 setField("Persistence", String.valueOf(persistence));
144         }
145
146         /**
147          * Sets the client token of the request.
148          * 
149          * @param clientToken
150          *            The client token of the request
151          */
152         public void setClientToken(String clientToken) {
153                 setField("ClientToken", clientToken);
154         }
155
156         /**
157          * Sets whether the request should be visible on the global queue.
158          * 
159          * @param global
160          *            <code>true</code> to make the request visible on the global
161          *            queue, <code>false</code> for client-local queue only
162          */
163         public void setGlobal(boolean global) {
164                 setField("Global", String.valueOf(global));
165         }
166
167         /**
168          * Sets whether to request the “binary blob” for a key.
169          * 
170          * @param binaryBlob
171          *            <code>true</code> to request the binary blob,
172          *            <code>false</code> to get the “real thing”
173          */
174         public void setBinaryBlob(boolean binaryBlob) {
175                 setField("BinaryBlob", String.valueOf(binaryBlob));
176         }
177
178         /**
179          * Sets the allowed MIME types of the requested file. If the MIME type of
180          * the file does not match one of the given MIME types the request will
181          * fail!
182          * 
183          * @param allowedMimeTypes
184          *            The allowed MIME types
185          */
186         public void setAllowedMimeTypes(String... allowedMimeTypes) {
187                 setField("AllowedMIMETypes", FcpUtils.encodeMultiStringField(allowedMimeTypes));
188         }
189
190         /**
191          * Sets the filename to download the file to. You should only call this
192          * method if your return type is {@link ReturnType#disk}!
193          * 
194          * @param filename
195          *            The filename to download the file to
196          */
197         public void setFilename(String filename) {
198                 setField("Filename", filename);
199         }
200
201         /**
202          * Sets the name for the temporary file. You should only call this method if
203          * your return type is {@link ReturnType#disk}!
204          * 
205          * @param tempFilename
206          *            The name of the temporary file
207          */
208         public void setTempFilename(String tempFilename) {
209                 setField("TempFilename", tempFilename);
210         }
211
212 }