5185deb7b4f08b95418100fcdbcbd7f94e11751e
[jFCPlib.git] / src / net / pterodactylus / fcp / ClientPut.java
1 /*
2  * jSite2 - ClientPut.java -
3  * Copyright © 2008 David Roden
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 package net.pterodactylus.fcp;
21
22 /**
23  * A “ClientPut” requests inserts a single file into freenet, either uploading
24  * it directly with this messge ({@link UploadFrom#direct}), uploading it from
25  * disk ({@link UploadFrom#disk}) or by creating a redirect to another URI ({@link UploadFrom#redirect}).
26  * 
27  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
28  */
29 public class ClientPut extends FcpMessage {
30
31         /**
32          * Creates a new “ClientPut” message that inserts a file to the given URI.
33          * The file data <em>has</em> to be supplied to this message using
34          * {@link #setPayloadInputStream(java.io.InputStream)}! Using this
35          * constructor is the same as using
36          * {@link #ClientPut(String, String, UploadFrom)} with
37          * {@link UploadFrom#direct} as third parameter.
38          * 
39          * @param uri
40          *            The URI to insert the file to
41          * @param identifier
42          *            The identifier of the request
43          */
44         public ClientPut(String uri, String identifier) {
45                 this(uri, identifier, UploadFrom.direct);
46         }
47
48         /**
49          * Creates a new “ClientPut” message that inserts a file to the given URI.
50          * Depending on <code>uploadFrom</code> the file data has to be supplied
51          * in different ways: If <code>uploadFrom</code> is
52          * {@link UploadFrom#direct}, use
53          * {@link #setPayloadInputStream(java.io.InputStream)} to supply the input
54          * data. If <code>uploadFrom</code> is {@link UploadFrom#disk}, use
55          * {@link #setFilename(String)} to supply the file to upload. You have to
56          * test your direct-disk access (see {@link TestDDARequest},
57          * {@link TestDDAReply}, {@link TestDDAResponse}, {@link TestDDAComplete})
58          * before using this option! If <code>uploadFrom</code> is
59          * {@link UploadFrom#redirect}, use {@link #setTargetURI(String)} to set
60          * the target URI of the redirect.
61          * 
62          * @param uri
63          *            The URI to insert to
64          * @param identifier
65          *            The identifier of the insert
66          * @param uploadFrom
67          *            The source of the upload
68          */
69         public ClientPut(String uri, String identifier, UploadFrom uploadFrom) {
70                 super("ClientPut");
71                 setField("URI", uri);
72                 setField("Identifier", identifier);
73                 setField("UploadFrom", String.valueOf(uploadFrom));
74         }
75
76         /**
77          * The MIME type of the content.
78          * 
79          * @param metadataContentType
80          *            The MIME type of the content
81          */
82         public void setMetadataContentType(String metadataContentType) {
83                 setField("Metadata.ContentType", metadataContentType);
84         }
85
86         /**
87          * The verbosity of the request. Depending on this parameter you will
88          * received only the bare minimum of messages for the request (i.e. “it
89          * completed”) or a whole lot more.
90          * 
91          * @see Verbosity
92          * @param verbosity
93          *            The verbosity of the request
94          */
95         public void setVerbosity(Verbosity verbosity) {
96                 setField("Verbosity", String.valueOf(verbosity));
97         }
98
99         /**
100          * The number of retries for a request if the initial try failed.
101          * 
102          * @param maxRetries
103          *            The maximum number of retries after failure, or
104          *            <code>-1</code> to retry 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          * Determines whether the node should really insert the data or generate the
122          * final CHK only.
123          * 
124          * @param getCHKOnly
125          *            <code>true</code> to generate the final CHK only,
126          *            <code>false</code> to really insert the data
127          */
128         public void setGetCHKOnly(boolean getCHKOnly) {
129                 setField("GetCHKOnly", String.valueOf(getCHKOnly));
130         }
131
132         /**
133          * Determines whether this request appears on the global queue.
134          * 
135          * @param global
136          *            <code>true</code> to put the request on the global queue,
137          *            <code>false</code> for the client-local queue.
138          */
139         public void setGlobal(boolean global) {
140                 setField("Global", String.valueOf(global));
141         }
142
143         /**
144          * Determines whether the node should skip compression because the file has
145          * already been compressed.
146          * 
147          * @param dontCompress
148          *            <code>true</code> to skip compression of the data in the
149          *            node, <code>false</code> to allow compression
150          */
151         public void setDontCompress(boolean dontCompress) {
152                 setField("DontCompress", String.valueOf(dontCompress));
153         }
154
155         /**
156          * Sets an optional client token. This client token is mentioned in progress
157          * and other request-related messages and can be used to identify this
158          * request.
159          * 
160          * @param clientToken
161          *            The client token
162          */
163         public void setClientToken(String clientToken) {
164                 setField("ClientToken", clientToken);
165         }
166
167         /**
168          * Sets the persistence of this request.
169          * 
170          * @param persistence
171          *            The persistence of this request
172          */
173         public void setPersistence(Persistence persistence) {
174                 setField("Persistence", String.valueOf(persistence));
175         }
176
177         /**
178          * Sets the target filename of the inserted file. This value is ignored for
179          * all inserts that do not have “CHK@” as a target.
180          * 
181          * @param targetFilename
182          *            The filename of the target
183          */
184         public void setTargetFilename(String targetFilename) {
185                 setField("TargetFilename", targetFilename);
186         }
187
188         /**
189          * Determines whether to encode the complete file early in the life of the
190          * request.
191          * 
192          * @param earlyEncode
193          *            <code>true</code> to generate the final key long before the
194          *            file is completely fetchable
195          */
196         public void setEarlyEncode(boolean earlyEncode) {
197                 setField("EarlyEncode", String.valueOf(earlyEncode));
198         }
199
200         /**
201          * Sets the length of the data that will be transferred after this message
202          * if <code>uploadFrom</code> is {@link UploadFrom#direct} is used.
203          * 
204          * @param dataLength
205          *            The length of the data
206          */
207         public void setDataLength(long dataLength) {
208                 setField("DataLength", String.valueOf(dataLength));
209         }
210
211         /**
212          * Sets the name of the file to upload the data from.
213          * 
214          * @param filename
215          *            The filename to upload
216          */
217         public void setFilename(String filename) {
218                 setField("Filename", filename);
219         }
220
221         /**
222          * If <code>uploadFrom</code> is {@link UploadFrom#redirect}, use this
223          * method to determine that target of the redirect.
224          * 
225          * @param targetURI
226          *            The target URI to redirect to
227          */
228         public void setTargetURI(String targetURI) {
229                 setField("TargetURI", targetURI);
230         }
231
232 }