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