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 * Determines whether this request appears on the global queue.
135 * <code>true</code> to put the request on the global queue,
136 * <code>false</code> for the client-local queue.
138 public void setGlobal(boolean global) {
139 setField("Global", String.valueOf(global));
143 * Determines whether the node should skip compression because the file has
144 * already been compressed.
146 * @param dontCompress
147 * <code>true</code> to skip compression of the data in the node,
148 * <code>false</code> to allow compression
150 public void setDontCompress(boolean dontCompress) {
151 setField("DontCompress", String.valueOf(dontCompress));
155 * Sets an optional client token. This client token is mentioned in progress
156 * and other request-related messages and can be used to identify this
162 public void setClientToken(String clientToken) {
163 setField("ClientToken", clientToken);
167 * Sets the persistence of this request.
170 * The persistence of this request
172 public void setPersistence(Persistence persistence) {
173 setField("Persistence", String.valueOf(persistence));
177 * Sets the target filename of the inserted file. This value is ignored for
178 * all inserts that do not have “CHK@” as a target.
180 * @param targetFilename
181 * The filename of the target
183 public void setTargetFilename(String targetFilename) {
184 setField("TargetFilename", targetFilename);
188 * Determines whether to encode the complete file early in the life of the
192 * <code>true</code> to generate the final key long before the
193 * file is completely fetchable
195 public void setEarlyEncode(boolean earlyEncode) {
196 setField("EarlyEncode", String.valueOf(earlyEncode));
200 * Sets the length of the data that will be transferred after this message
201 * if <code>uploadFrom</code> is {@link UploadFrom#direct} is used.
204 * The length of the data
206 public void setDataLength(long dataLength) {
207 setField("DataLength", String.valueOf(dataLength));
211 * Sets the name of the file to upload the data from.
214 * The filename to upload
216 public void setFilename(String filename) {
217 setField("Filename", filename);
221 * If <code>uploadFrom</code> is {@link UploadFrom#redirect}, use this
222 * method to determine that target of the redirect.
225 * The target URI to redirect to
227 public void setTargetURI(String targetURI) {
228 setField("TargetURI", targetURI);