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