2 * © 2008 INA Service GmbH
4 package net.pterodactylus.util.fcp;
7 * A “ClientPut” requests inserts a single file into freenet, either uploading
8 * it directly with this messge ({@link UploadFrom#direct}), uploading it from
9 * disk ({@link UploadFrom#disk}) or by creating a redirect to another URI ({@link UploadFrom#redirect}).
11 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
14 public class ClientPut extends FcpMessage {
17 * Creates a new “ClientPut” message that inserts a file to the given URI.
18 * The file data <em>has</em> to be supplied to this message using
19 * {@link #setPayloadInputStream(java.io.InputStream)}!
21 * Using this constructor is the same as using
22 * {@link #ClientPut(String, String, UploadFrom)} with
23 * {@link UploadFrom#direct} as third parameter.
26 * The URI to insert the file to
28 * The identifier of the request
30 public ClientPut(String uri, String identifier) {
31 this(uri, identifier, UploadFrom.direct);
35 * Creates a new “ClientPut” message that inserts a file to the given URI.
36 * Depending on <code>uploadFrom</code> the file data has to be supplied
39 * If <code>uploadFrom</code> is {@link UploadFrom#direct}, use
40 * {@link #setPayloadInputStream(java.io.InputStream)} to supply the input
43 * If <code>uploadFrom</code> is {@link UploadFrom#disk}, use
44 * {@link #setFilename(String)} to supply the file to upload. You have to
45 * test your direct-disk access (see {@link TestDDARequest},
46 * {@link TestDDAReply}, {@link TestDDAResponse}, {@link TestDDAComplete})
47 * before using this option!
49 * If <code>uploadFrom</code> is {@link UploadFrom#redirect}, use
50 * {@link #setTargetURI(String)} to set the target URI of the redirect.
53 * The URI to insert to
55 * The identifier of the insert
57 * The source of the upload
59 public ClientPut(String uri, String identifier, UploadFrom uploadFrom) {
62 setField("Identifier", identifier);
63 setField("UploadFrom", String.valueOf(uploadFrom));
67 * The MIME type of the content.
69 * @param metadataContentType
70 * The MIME type of the content
72 public void setMetadataContentType(String metadataContentType) {
73 setField("Metadata.ContentType", metadataContentType);
77 * The verbosity of the request. Depending on this parameter you will
78 * received only the bare minimum of messages for the request (i.e. “it
79 * completed”) or a whole lot more.
83 * The verbosity of the request
85 public void setVerbosity(Verbosity verbosity) {
86 setField("Verbosity", String.valueOf(verbosity));
90 * The number of retries for a request if the initial try failed.
93 * The maximum number of retries after failure, or
94 * <code>-1</code> to retry forever.
96 public void setMaxRetries(int maxRetries) {
97 setField("MaxRetries", String.valueOf(maxRetries));
101 * Sets the priority of the request.
104 * The priority of the request
106 public void setPriority(Priority priority) {
107 setField("PriorityClass", String.valueOf(priority));
111 * Determines whether the node should really insert the data or generate the
115 * <code>true</code> to generate the final CHK only,
116 * <code>false</code> to really insert the data
118 public void setGetCHKOnly(boolean getCHKOnly) {
119 setField("GetCHKOnly", String.valueOf(getCHKOnly));
123 * Determines whether this request appears on the global queue.
126 * <code>true</code> to put the request on the global queue,
127 * <code>false</code> for the client-local queue.
129 public void setGlobal(boolean global) {
130 setField("Global", String.valueOf(global));
134 * Determines whether the node should skip compression because the file has
135 * already been compressed.
137 * @param dontCompress
138 * <code>true</code> to skip compression of the data in the
139 * node, <code>false</code> to allow compression
141 public void setDontCompress(boolean dontCompress) {
142 setField("DontCompress", String.valueOf(dontCompress));
146 * Sets an optional client token. This client token is mentioned in progress
147 * and other request-related messages and can be used to identify this
153 public void setClientToken(String clientToken) {
154 setField("ClientToken", clientToken);
158 * Sets the persistence of this request.
161 * The persistence of this request
163 public void setPersistence(Persistence persistence) {
164 setField("Persistence", String.valueOf(persistence));
168 * Sets the target filename of the inserted file. This value is ignored for
169 * all inserts that do not have “CHK@” as a target.
171 * @param targetFilename
172 * The filename of the target
174 public void setTargetFilename(String targetFilename) {
175 setField("TargetFilename", targetFilename);
179 * Determines whether to encode the complete file early in the life of the
183 * <code>true</code> to generate the final key long before the
184 * file is completely fetchable
186 public void setEarlyEncode(boolean earlyEncode) {
187 setField("EarlyEncode", String.valueOf(earlyEncode));
191 * Sets the length of the data that will be transferred after this message
192 * if <code>uploadFrom</code> is {@link UploadFrom#direct} is used.
195 * The length of the data
197 public void setDataLength(long dataLength) {
198 setField("DataLength", String.valueOf(dataLength));
202 * Sets the name of the file to upload the data from.
205 * The filename to upload
207 public void setFilename(String filename) {
208 setField("Filename", filename);
212 * If <code>uploadFrom</code> is {@link UploadFrom#redirect}, use this
213 * method to determine that target of the redirect.
216 * The target URI to redirect to
218 public void setTargetURI(String targetURI) {
219 setField("TargetURI", targetURI);