Add setter for real-time flag
[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
93          * than 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         public void setRealTimeFlag(boolean realTimeFlag) {
135                 setField("RealTimeFlag", String.valueOf(realTimeFlag));
136         }
137
138         /**
139          * Sets the persistence of the request.
140          *
141          * @param persistence
142          *            The persistence of the request
143          */
144         public void setPersistence(Persistence persistence) {
145                 setField("Persistence", String.valueOf(persistence));
146         }
147
148         /**
149          * Sets the client token of the request.
150          *
151          * @param clientToken
152          *            The client token of the request
153          */
154         public void setClientToken(String clientToken) {
155                 setField("ClientToken", clientToken);
156         }
157
158         /**
159          * Sets whether the request should be visible on the global queue.
160          *
161          * @param global
162          *            <code>true</code> to make the request visible on the global
163          *            queue, <code>false</code> for client-local queue only
164          */
165         public void setGlobal(boolean global) {
166                 setField("Global", String.valueOf(global));
167         }
168
169         /**
170          * Sets whether to request the “binary blob” for a key.
171          *
172          * @param binaryBlob
173          *            <code>true</code> to request the binary blob,
174          *            <code>false</code> to get the “real thing”
175          */
176         public void setBinaryBlob(boolean binaryBlob) {
177                 setField("BinaryBlob", String.valueOf(binaryBlob));
178         }
179
180         /**
181          * Sets whether to filter the fetched content.
182          *
183          * @param filterData
184          *            {@code true} to filter content, {@code false} otherwise
185          */
186         public void setFilterData(boolean filterData) {
187                 setField("FilterData", String.valueOf(filterData));
188         }
189
190         /**
191          * Sets the allowed MIME types of the requested file. If the MIME type of
192          * the file does not match one of the given MIME types the request will
193          * fail!
194          *
195          * @param allowedMimeTypes
196          *            The allowed MIME types
197          */
198         public void setAllowedMimeTypes(String... allowedMimeTypes) {
199                 setField("AllowedMIMETypes", FcpUtils.encodeMultiStringField(allowedMimeTypes));
200         }
201
202         /**
203          * Sets the filename to download the file to. You should only call this
204          * method if your return type is {@link ReturnType#disk}!
205          *
206          * @param filename
207          *            The filename to download the file to
208          */
209         public void setFilename(String filename) {
210                 setField("Filename", filename);
211         }
212
213         /**
214          * Sets the name for the temporary file. You should only call this method
215          * if your return type is {@link ReturnType#disk}!
216          *
217          * @param tempFilename
218          *            The name of the temporary file
219          */
220         public void setTempFilename(String tempFilename) {
221                 setField("TempFilename", tempFilename);
222         }
223
224 }