2 * jFCPlib - ClientPut.java - Copyright © 2008–2016 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 3 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, see <http://www.gnu.org/licenses/>.
18 package net.pterodactylus.fcp;
21 * A “ClientPut” requests inserts a single file into freenet, either uploading
22 * it directly with this messge ({@link UploadFrom#direct}), uploading it from
23 * disk ({@link UploadFrom#disk}) or by creating a redirect to another URI (
24 * {@link UploadFrom#redirect}).
26 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
28 public class ClientPut extends FcpMessage {
31 * Creates a new “ClientPut” message that inserts a file to the given URI.
32 * The file data <em>has</em> to be supplied to this message using
33 * {@link #setPayloadInputStream(java.io.InputStream)}! Using this
34 * constructor is the same as using
35 * {@link #ClientPut(String, String, UploadFrom)} with
36 * {@link UploadFrom#direct} as third parameter.
39 * The URI to insert the file to
41 * The identifier of the request
43 public ClientPut(String uri, String identifier) {
44 this(uri, identifier, UploadFrom.direct);
48 * Creates a new “ClientPut” message that inserts a file to the given URI.
49 * Depending on <code>uploadFrom</code> the file data has to be supplied in
50 * different ways: If <code>uploadFrom</code> is {@link UploadFrom#direct},
51 * use {@link #setPayloadInputStream(java.io.InputStream)} to supply the
52 * input data. If <code>uploadFrom</code> is {@link UploadFrom#disk}, use
53 * {@link #setFilename(String)} to supply the file to upload. You have to
54 * test your direct-disk access (see {@link TestDDARequest},
55 * {@link TestDDAReply}, {@link TestDDAResponse}, {@link TestDDAComplete})
56 * before using this option! If <code>uploadFrom</code> is
57 * {@link UploadFrom#redirect}, use {@link #setTargetURI(String)} to set
58 * the target URI of the redirect.
61 * The URI to insert to
63 * The identifier of the insert
65 * The source of the upload
67 public ClientPut(String uri, String identifier, UploadFrom uploadFrom) {
70 setField("Identifier", identifier);
71 setField("UploadFrom", String.valueOf(uploadFrom));
75 * The MIME type of the content.
77 * @param metadataContentType
78 * The MIME type of the content
80 public void setMetadataContentType(String metadataContentType) {
81 setField("Metadata.ContentType", metadataContentType);
85 * The verbosity of the request. Depending on this parameter you will
86 * received only the bare minimum of messages for the request (i.e. “it
87 * completed”) or a whole lot more.
91 * The verbosity of the request
93 public void setVerbosity(Verbosity verbosity) {
94 setField("Verbosity", String.valueOf(verbosity));
98 * The number of retries for a request if the initial try failed.
101 * The maximum number of retries after failure, or
102 * <code>-1</code> to retry forever.
104 public void setMaxRetries(int maxRetries) {
105 setField("MaxRetries", String.valueOf(maxRetries));
109 * Sets the priority of the request.
112 * The priority of the request
114 public void setPriority(Priority priority) {
115 setField("PriorityClass", String.valueOf(priority));
119 * Determines whether the node should really insert the data or generate
120 * the final CHK only.
123 * <code>true</code> to generate the final CHK only,
124 * <code>false</code> to really insert the data
126 public void setGetCHKOnly(boolean getCHKOnly) {
127 setField("GetCHKOnly", String.valueOf(getCHKOnly));
131 * Sets whether an insert request should be forked when it is cached.
133 * @param forkOnCacheable
134 * {@code true} to fork the insert when it is cached,
135 * {@code false} otherwise
137 public void setForkOnCacheable(boolean forkOnCacheable) {
138 setField("ForkOnCacheable", String.valueOf(forkOnCacheable));
142 * Sets the number of additional inserts of single blocks.
144 * @param extraInsertsSingleBlock
145 * The number of additional inserts
147 public void setExtraInsertsSingleBlock(int extraInsertsSingleBlock) {
148 setField("ExtraInsertsSingleBlock", String.valueOf(extraInsertsSingleBlock));
152 * Sets the number of additional inserts of splitfile header blocks.
154 * @param extraInsertsSplitfileHeaderBlock
155 * The number of additional inserts
157 public void setExtraInsertsSplitfileHeaderBlock(int extraInsertsSplitfileHeaderBlock) {
158 setField("ExtraInsertsSplitfileHeaderBlock", String.valueOf(extraInsertsSplitfileHeaderBlock));
162 * Determines whether this request appears on the global queue.
165 * <code>true</code> to put the request on the global queue,
166 * <code>false</code> for the client-local queue.
168 public void setGlobal(boolean global) {
169 setField("Global", String.valueOf(global));
173 * Determines whether the node should skip compression because the file has
174 * already been compressed.
176 * @param dontCompress
177 * <code>true</code> to skip compression of the data in the
178 * node, <code>false</code> to allow compression
180 public void setDontCompress(boolean dontCompress) {
181 setField("DontCompress", String.valueOf(dontCompress));
185 * Sets an optional client token. This client token is mentioned in
186 * progress and other request-related messages and can be used to identify
192 public void setClientToken(String clientToken) {
193 setField("ClientToken", clientToken);
197 * Sets the persistence of this request.
200 * The persistence of this request
202 public void setPersistence(Persistence persistence) {
203 setField("Persistence", String.valueOf(persistence));
207 * Sets the target filename of the inserted file. This value is ignored for
208 * all inserts that do not have “CHK@” as a target.
210 * @param targetFilename
211 * The filename of the target
213 public void setTargetFilename(String targetFilename) {
214 setField("TargetFilename", targetFilename);
218 * Determines whether to encode the complete file early in the life of the
222 * <code>true</code> to generate the final key long before the
223 * file is completely fetchable
225 public void setEarlyEncode(boolean earlyEncode) {
226 setField("EarlyEncode", String.valueOf(earlyEncode));
230 * Sets the length of the data that will be transferred after this message
231 * if <code>uploadFrom</code> is {@link UploadFrom#direct} is used.
234 * The length of the data
236 public void setDataLength(long dataLength) {
237 setField("DataLength", String.valueOf(dataLength));
241 * Sets the name of the file to upload the data from.
244 * The filename to upload
246 public void setFilename(String filename) {
247 setField("Filename", filename);
251 * If <code>uploadFrom</code> is {@link UploadFrom#redirect}, use this
252 * method to determine that target of the redirect.
255 * The target URI to redirect to
257 public void setTargetURI(String targetURI) {
258 setField("TargetURI", targetURI);