2 * jFCPlib - ClientPut.java - Copyright © 2008 David Roden
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.
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.
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.
19 package net.pterodactylus.fcp;
22 * A “ClientPut” requests inserts a single file into freenet, either uploading
23 * it directly with this messge ({@link UploadFrom#direct}), uploading it from
24 * disk ({@link UploadFrom#disk}) or by creating a redirect to another URI (
25 * {@link UploadFrom#redirect}).
27 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
29 public class ClientPut extends FcpMessage {
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.
40 * The URI to insert the file to
42 * The identifier of the request
44 public ClientPut(String uri, String identifier) {
45 this(uri, identifier, UploadFrom.direct);
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 in
51 * different ways: If <code>uploadFrom</code> is {@link UploadFrom#direct},
52 * use {@link #setPayloadInputStream(java.io.InputStream)} to supply the
53 * input data. If <code>uploadFrom</code> is {@link UploadFrom#disk}, use
54 * {@link #setFilename(String)} to supply the file to upload. You have to
55 * test your direct-disk access (see {@link TestDDARequest},
56 * {@link TestDDAReply}, {@link TestDDAResponse}, {@link TestDDAComplete})
57 * before using this option! If <code>uploadFrom</code> is
58 * {@link UploadFrom#redirect}, use {@link #setTargetURI(String)} to set the
59 * target URI of the redirect.
62 * The URI to insert to
64 * The identifier of the insert
66 * The source of the upload
68 public ClientPut(String uri, String identifier, UploadFrom uploadFrom) {
71 setField("Identifier", identifier);
72 setField("UploadFrom", String.valueOf(uploadFrom));
76 * The MIME type of the content.
78 * @param metadataContentType
79 * The MIME type of the content
81 public void setMetadataContentType(String metadataContentType) {
82 setField("Metadata.ContentType", metadataContentType);
86 * The verbosity of the request. Depending on this parameter you will
87 * received only the bare minimum of messages for the request (i.e. “it
88 * completed”) or a whole lot more.
92 * The verbosity of the request
94 public void setVerbosity(Verbosity verbosity) {
95 setField("Verbosity", String.valueOf(verbosity));
99 * The number of retries for a request if the initial try failed.
102 * The maximum number of retries after failure, or
103 * <code>-1</code> to retry forever.
105 public void setMaxRetries(int maxRetries) {
106 setField("MaxRetries", String.valueOf(maxRetries));
110 * Sets the priority of the request.
113 * The priority of the request
115 public void setPriority(Priority priority) {
116 setField("PriorityClass", String.valueOf(priority));
120 * Determines whether the node should really insert the data or generate the
124 * <code>true</code> to generate the final CHK only,
125 * <code>false</code> to really insert the data
127 public void setGetCHKOnly(boolean getCHKOnly) {
128 setField("GetCHKOnly", String.valueOf(getCHKOnly));
132 * Sets whether an insert request should be forked when it is cached.
134 * @param forkOnCacheable
135 * {@code true} to fork the insert when it is cached, {@code
138 public void setForkOnCacheable(boolean forkOnCacheable) {
139 setField("ForkOnCacheable", String.valueOf(forkOnCacheable));
143 * Sets the number of additional inserts of single blocks.
145 * @param extraInsertsSingleBlock
146 * The number of additional inserts
148 public void setExtraInsertsSingleBlock(int extraInsertsSingleBlock) {
149 setField("ExtraInsertsSingleBlock", String.valueOf(extraInsertsSingleBlock));
153 * Sets the number of additional inserts of splitfile header blocks.
155 * @param extraInsertsSplitfileHeaderBlock
156 * The number of additional inserts
158 public void setExtraInsertsSplitfileHeaderBlock(int extraInsertsSplitfileHeaderBlock) {
159 setField("ExtraInsertsSplitfileHeaderBlock", String.valueOf(extraInsertsSplitfileHeaderBlock));
163 * Determines whether this request appears on the global queue.
166 * <code>true</code> to put the request on the global queue,
167 * <code>false</code> for the client-local queue.
169 public void setGlobal(boolean global) {
170 setField("Global", String.valueOf(global));
174 * Determines whether the node should skip compression because the file has
175 * already been compressed.
177 * @param dontCompress
178 * <code>true</code> to skip compression of the data in the node,
179 * <code>false</code> to allow compression
181 public void setDontCompress(boolean dontCompress) {
182 setField("DontCompress", String.valueOf(dontCompress));
186 * Sets an optional client token. This client token is mentioned in progress
187 * and other request-related messages and can be used to identify this
193 public void setClientToken(String clientToken) {
194 setField("ClientToken", clientToken);
198 * Sets the persistence of this request.
201 * The persistence of this request
203 public void setPersistence(Persistence persistence) {
204 setField("Persistence", String.valueOf(persistence));
208 * Sets the target filename of the inserted file. This value is ignored for
209 * all inserts that do not have “CHK@” as a target.
211 * @param targetFilename
212 * The filename of the target
214 public void setTargetFilename(String targetFilename) {
215 setField("TargetFilename", targetFilename);
219 * Determines whether to encode the complete file early in the life of the
223 * <code>true</code> to generate the final key long before the
224 * file is completely fetchable
226 public void setEarlyEncode(boolean earlyEncode) {
227 setField("EarlyEncode", String.valueOf(earlyEncode));
231 * Sets the length of the data that will be transferred after this message
232 * if <code>uploadFrom</code> is {@link UploadFrom#direct} is used.
235 * The length of the data
237 public void setDataLength(long dataLength) {
238 setField("DataLength", String.valueOf(dataLength));
242 * Sets the name of the file to upload the data from.
245 * The filename to upload
247 public void setFilename(String filename) {
248 setField("Filename", filename);
252 * If <code>uploadFrom</code> is {@link UploadFrom#redirect}, use this
253 * method to determine that target of the redirect.
256 * The target URI to redirect to
258 public void setTargetURI(String targetURI) {
259 setField("TargetURI", targetURI);