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