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