Update license to GPLv3, fix header comments
[jFCPlib.git] / src / main / java / net / pterodactylus / fcp / ClientPut.java
1 /*
2  * jFCPlib - ClientPut.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 “ClientPut” requests inserts a single file into freenet, either uploading
22  * it directly with this messge ({@link UploadFrom#direct}), uploading it from
23  * disk ({@link UploadFrom#disk}) or by creating a redirect to another URI (
24  * {@link UploadFrom#redirect}).
25  *
26  * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
27  */
28 public class ClientPut extends FcpMessage {
29
30         /**
31          * Creates a new “ClientPut” message that inserts a file to the given URI.
32          * The file data <em>has</em> to be supplied to this message using
33          * {@link #setPayloadInputStream(java.io.InputStream)}! Using this
34          * constructor is the same as using
35          * {@link #ClientPut(String, String, UploadFrom)} with
36          * {@link UploadFrom#direct} as third parameter.
37          *
38          * @param uri
39          *            The URI to insert the file to
40          * @param identifier
41          *            The identifier of the request
42          */
43         public ClientPut(String uri, String identifier) {
44                 this(uri, identifier, UploadFrom.direct);
45         }
46
47         /**
48          * Creates a new “ClientPut” message that inserts a file to the given URI.
49          * Depending on <code>uploadFrom</code> the file data has to be supplied in
50          * different ways: If <code>uploadFrom</code> is {@link UploadFrom#direct},
51          * use {@link #setPayloadInputStream(java.io.InputStream)} to supply the
52          * input data. If <code>uploadFrom</code> is {@link UploadFrom#disk}, use
53          * {@link #setFilename(String)} to supply the file to upload. You have to
54          * test your direct-disk access (see {@link TestDDARequest},
55          * {@link TestDDAReply}, {@link TestDDAResponse}, {@link TestDDAComplete})
56          * before using this option! If <code>uploadFrom</code> is
57          * {@link UploadFrom#redirect}, use {@link #setTargetURI(String)} to set
58          * the target URI of the redirect.
59          *
60          * @param uri
61          *            The URI to insert to
62          * @param identifier
63          *            The identifier of the insert
64          * @param uploadFrom
65          *            The source of the upload
66          */
67         public ClientPut(String uri, String identifier, UploadFrom uploadFrom) {
68                 super("ClientPut");
69                 setField("URI", uri);
70                 setField("Identifier", identifier);
71                 setField("UploadFrom", String.valueOf(uploadFrom));
72         }
73
74         /**
75          * The MIME type of the content.
76          *
77          * @param metadataContentType
78          *            The MIME type of the content
79          */
80         public void setMetadataContentType(String metadataContentType) {
81                 setField("Metadata.ContentType", metadataContentType);
82         }
83
84         /**
85          * The verbosity of the request. Depending on this parameter you will
86          * received only the bare minimum of messages for the request (i.e. “it
87          * completed”) or a whole lot more.
88          *
89          * @see Verbosity
90          * @param verbosity
91          *            The verbosity of the request
92          */
93         public void setVerbosity(Verbosity verbosity) {
94                 setField("Verbosity", String.valueOf(verbosity));
95         }
96
97         /**
98          * The number of retries for a request if the initial try failed.
99          *
100          * @param maxRetries
101          *            The maximum number of retries after failure, or
102          *            <code>-1</code> to retry forever.
103          */
104         public void setMaxRetries(int maxRetries) {
105                 setField("MaxRetries", String.valueOf(maxRetries));
106         }
107
108         /**
109          * Sets the priority of the request.
110          *
111          * @param priority
112          *            The priority of the request
113          */
114         public void setPriority(Priority priority) {
115                 setField("PriorityClass", String.valueOf(priority));
116         }
117
118         /**
119          * Determines whether the node should really insert the data or generate
120          * the final CHK only.
121          *
122          * @param getCHKOnly
123          *            <code>true</code> to generate the final CHK only,
124          *            <code>false</code> to really insert the data
125          */
126         public void setGetCHKOnly(boolean getCHKOnly) {
127                 setField("GetCHKOnly", String.valueOf(getCHKOnly));
128         }
129
130         /**
131          * Sets whether an insert request should be forked when it is cached.
132          *
133          * @param forkOnCacheable
134          *            {@code true} to fork the insert when it is cached,
135          *            {@code false} otherwise
136          */
137         public void setForkOnCacheable(boolean forkOnCacheable) {
138                 setField("ForkOnCacheable", String.valueOf(forkOnCacheable));
139         }
140
141         /**
142          * Sets the number of additional inserts of single blocks.
143          *
144          * @param extraInsertsSingleBlock
145          *            The number of additional inserts
146          */
147         public void setExtraInsertsSingleBlock(int extraInsertsSingleBlock) {
148                 setField("ExtraInsertsSingleBlock", String.valueOf(extraInsertsSingleBlock));
149         }
150
151         /**
152          * Sets the number of additional inserts of splitfile header blocks.
153          *
154          * @param extraInsertsSplitfileHeaderBlock
155          *            The number of additional inserts
156          */
157         public void setExtraInsertsSplitfileHeaderBlock(int extraInsertsSplitfileHeaderBlock) {
158                 setField("ExtraInsertsSplitfileHeaderBlock", String.valueOf(extraInsertsSplitfileHeaderBlock));
159         }
160
161         /**
162          * Determines whether this request appears on the global queue.
163          *
164          * @param global
165          *            <code>true</code> to put the request on the global queue,
166          *            <code>false</code> for the client-local queue.
167          */
168         public void setGlobal(boolean global) {
169                 setField("Global", String.valueOf(global));
170         }
171
172         /**
173          * Determines whether the node should skip compression because the file has
174          * already been compressed.
175          *
176          * @param dontCompress
177          *            <code>true</code> to skip compression of the data in the
178          *            node, <code>false</code> to allow compression
179          */
180         public void setDontCompress(boolean dontCompress) {
181                 setField("DontCompress", String.valueOf(dontCompress));
182         }
183
184         /**
185          * Sets an optional client token. This client token is mentioned in
186          * progress and other request-related messages and can be used to identify
187          * this request.
188          *
189          * @param clientToken
190          *            The client token
191          */
192         public void setClientToken(String clientToken) {
193                 setField("ClientToken", clientToken);
194         }
195
196         /**
197          * Sets the persistence of this request.
198          *
199          * @param persistence
200          *            The persistence of this request
201          */
202         public void setPersistence(Persistence persistence) {
203                 setField("Persistence", String.valueOf(persistence));
204         }
205
206         /**
207          * Sets the target filename of the inserted file. This value is ignored for
208          * all inserts that do not have “CHK@” as a target.
209          *
210          * @param targetFilename
211          *            The filename of the target
212          */
213         public void setTargetFilename(String targetFilename) {
214                 setField("TargetFilename", targetFilename);
215         }
216
217         /**
218          * Determines whether to encode the complete file early in the life of the
219          * request.
220          *
221          * @param earlyEncode
222          *            <code>true</code> to generate the final key long before the
223          *            file is completely fetchable
224          */
225         public void setEarlyEncode(boolean earlyEncode) {
226                 setField("EarlyEncode", String.valueOf(earlyEncode));
227         }
228
229         /**
230          * Sets the length of the data that will be transferred after this message
231          * if <code>uploadFrom</code> is {@link UploadFrom#direct} is used.
232          *
233          * @param dataLength
234          *            The length of the data
235          */
236         public void setDataLength(long dataLength) {
237                 setField("DataLength", String.valueOf(dataLength));
238         }
239
240         /**
241          * Sets the name of the file to upload the data from.
242          *
243          * @param filename
244          *            The filename to upload
245          */
246         public void setFilename(String filename) {
247                 setField("Filename", filename);
248         }
249
250         /**
251          * If <code>uploadFrom</code> is {@link UploadFrom#redirect}, use this
252          * method to determine that target of the redirect.
253          *
254          * @param targetURI
255          *            The target URI to redirect to
256          */
257         public void setTargetURI(String targetURI) {
258                 setField("TargetURI", targetURI);
259         }
260
261 }