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>
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
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.
63 * The URI to insert to
65 * The identifier of the insert
67 * The source of the upload
69 public ClientPut(String uri, String identifier, UploadFrom uploadFrom) {
72 setField("Identifier", identifier);
73 setField("UploadFrom", String.valueOf(uploadFrom));
77 * The MIME type of the content.
79 * @param metadataContentType
80 * The MIME type of the content
82 public void setMetadataContentType(String metadataContentType) {
83 setField("Metadata.ContentType", metadataContentType);
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.
93 * The verbosity of the request
95 public void setVerbosity(Verbosity verbosity) {
96 setField("Verbosity", String.valueOf(verbosity));
100 * The number of retries for a request if the initial try failed.
103 * The maximum number of retries after failure, or
104 * <code>-1</code> to retry forever.
106 public void setMaxRetries(int maxRetries) {
107 setField("MaxRetries", String.valueOf(maxRetries));
111 * Sets the priority of the request.
114 * The priority of the request
116 public void setPriority(Priority priority) {
117 setField("PriorityClass", String.valueOf(priority));
121 * Determines whether the node should really insert the data or generate the
125 * <code>true</code> to generate the final CHK only,
126 * <code>false</code> to really insert the data
128 public void setGetCHKOnly(boolean getCHKOnly) {
129 setField("GetCHKOnly", String.valueOf(getCHKOnly));
133 * Determines whether this request appears on the global queue.
136 * <code>true</code> to put the request on the global queue,
137 * <code>false</code> for the client-local queue.
139 public void setGlobal(boolean global) {
140 setField("Global", String.valueOf(global));
144 * Determines whether the node should skip compression because the file has
145 * already been compressed.
147 * @param dontCompress
148 * <code>true</code> to skip compression of the data in the
149 * node, <code>false</code> to allow compression
151 public void setDontCompress(boolean dontCompress) {
152 setField("DontCompress", String.valueOf(dontCompress));
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
163 public void setClientToken(String clientToken) {
164 setField("ClientToken", clientToken);
168 * Sets the persistence of this request.
171 * The persistence of this request
173 public void setPersistence(Persistence persistence) {
174 setField("Persistence", String.valueOf(persistence));
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.
181 * @param targetFilename
182 * The filename of the target
184 public void setTargetFilename(String targetFilename) {
185 setField("TargetFilename", targetFilename);
189 * Determines whether to encode the complete file early in the life of the
193 * <code>true</code> to generate the final key long before the
194 * file is completely fetchable
196 public void setEarlyEncode(boolean earlyEncode) {
197 setField("EarlyEncode", String.valueOf(earlyEncode));
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.
205 * The length of the data
207 public void setDataLength(long dataLength) {
208 setField("DataLength", String.valueOf(dataLength));
212 * Sets the name of the file to upload the data from.
215 * The filename to upload
217 public void setFilename(String filename) {
218 setField("Filename", filename);
222 * If <code>uploadFrom</code> is {@link UploadFrom#redirect}, use this
223 * method to determine that target of the redirect.
226 * The target URI to redirect to
228 public void setTargetURI(String targetURI) {
229 setField("TargetURI", targetURI);