2 * jSite2 - ClientPut.java -
3 * Copyright © 2008 David Roden
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.
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.
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.
20 package net.pterodactylus.fcp;
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}).
27 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
30 public class ClientPut extends FcpMessage {
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.
41 * The URI to insert the file to
43 * The identifier of the request
45 public ClientPut(String uri, String identifier) {
46 this(uri, identifier, UploadFrom.direct);
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.
64 * The URI to insert to
66 * The identifier of the insert
68 * The source of the upload
70 public ClientPut(String uri, String identifier, UploadFrom uploadFrom) {
73 setField("Identifier", identifier);
74 setField("UploadFrom", String.valueOf(uploadFrom));
78 * The MIME type of the content.
80 * @param metadataContentType
81 * The MIME type of the content
83 public void setMetadataContentType(String metadataContentType) {
84 setField("Metadata.ContentType", metadataContentType);
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.
94 * The verbosity of the request
96 public void setVerbosity(Verbosity verbosity) {
97 setField("Verbosity", String.valueOf(verbosity));
101 * The number of retries for a request if the initial try failed.
104 * The maximum number of retries after failure, or
105 * <code>-1</code> to retry forever.
107 public void setMaxRetries(int maxRetries) {
108 setField("MaxRetries", String.valueOf(maxRetries));
112 * Sets the priority of the request.
115 * The priority of the request
117 public void setPriority(Priority priority) {
118 setField("PriorityClass", String.valueOf(priority));
122 * Determines whether the node should really insert the data or generate the
126 * <code>true</code> to generate the final CHK only,
127 * <code>false</code> to really insert the data
129 public void setGetCHKOnly(boolean getCHKOnly) {
130 setField("GetCHKOnly", String.valueOf(getCHKOnly));
134 * Determines whether this request appears on the global queue.
137 * <code>true</code> to put the request on the global queue,
138 * <code>false</code> for the client-local queue.
140 public void setGlobal(boolean global) {
141 setField("Global", String.valueOf(global));
145 * Determines whether the node should skip compression because the file has
146 * already been compressed.
148 * @param dontCompress
149 * <code>true</code> to skip compression of the data in the
150 * node, <code>false</code> to allow compression
152 public void setDontCompress(boolean dontCompress) {
153 setField("DontCompress", String.valueOf(dontCompress));
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
164 public void setClientToken(String clientToken) {
165 setField("ClientToken", clientToken);
169 * Sets the persistence of this request.
172 * The persistence of this request
174 public void setPersistence(Persistence persistence) {
175 setField("Persistence", String.valueOf(persistence));
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.
182 * @param targetFilename
183 * The filename of the target
185 public void setTargetFilename(String targetFilename) {
186 setField("TargetFilename", targetFilename);
190 * Determines whether to encode the complete file early in the life of the
194 * <code>true</code> to generate the final key long before the
195 * file is completely fetchable
197 public void setEarlyEncode(boolean earlyEncode) {
198 setField("EarlyEncode", String.valueOf(earlyEncode));
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.
206 * The length of the data
208 public void setDataLength(long dataLength) {
209 setField("DataLength", String.valueOf(dataLength));
213 * Sets the name of the file to upload the data from.
216 * The filename to upload
218 public void setFilename(String filename) {
219 setField("Filename", filename);
223 * If <code>uploadFrom</code> is {@link UploadFrom#redirect}, use this
224 * method to determine that target of the redirect.
227 * The target URI to redirect to
229 public void setTargetURI(String targetURI) {
230 setField("TargetURI", targetURI);