2 * jSite - ClientPut.java - Copyright © 2006–2012 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 de.todesbaum.util.freenet.fcp2;
21 import java.io.IOException;
22 import java.io.Writer;
25 * Abstract base class for all put requests. It contains all parameters that put
26 * requests have in common.
28 * @author David Roden <droden@gmail.com>
31 public abstract class ClientPut extends Command {
33 /** The URI of this request. */
34 protected final String uri;
36 /** The client token of this request. */
37 protected String clientToken = null;
39 /** Whether this request should only create a CHK. */
40 protected boolean getCHKOnly = false;
42 /** Whether this request is a global request. */
43 protected boolean global = false;
45 /** Whether the node should not try to compress the file. */
46 protected boolean dontCompress = false;
48 /** The maximum number of retries of this command. */
49 protected int maxRetries = 0;
51 /** Whether to generate the keys early. */
52 protected boolean earlyEncode = false;
54 /** The persistence of this request. */
55 protected Persistence persistence = Persistence.CONNECTION;
57 /** The priority class of this request. */
58 protected PriorityClass priorityClass = PriorityClass.INTERACTIVE;
60 /** The verbosiry of this request. */
61 protected Verbosity verbosity = Verbosity.NONE;
64 * Creates a new put request with the specified name, identifier and URI.
67 * The name of this request
69 * The identifier of this request
71 * The URI of this request
73 protected ClientPut(String name, String identifier, String uri) {
74 super(name, identifier);
79 * Returns whether the node should not try to compress the data.
81 * @return <code>true</code> if the node should <strong>not</strong> try
82 * to compress the data
84 public boolean isDontCompress() {
89 * Sets whether the node should not try to compress the data. A client might
90 * set this hint on data that is clearly not compressible, like MPEG audio
91 * files, JPEG or PNG images, highly compressed movies, or compressed
92 * archives like ZIP files. Otherwise the node will try to compress the file
93 * which -- depending on the size of the data -- might take a lot of time
97 * <code>true</code> if the node should <strong>not</strong>
98 * try to compress the data
100 public void setDontCompress(boolean dontCompress) {
101 this.dontCompress = dontCompress;
105 * Returns whether this request should only return the CHK of the data.
106 * @return Whether this request should only return the CHK of the data
108 public boolean isGetCHKOnly() {
113 * Sets whether this request should only return the CHK of the data.
115 * <code>true</code> if this request should only return the CHK of the data
117 public void setGetCHKOnly(boolean getCHKOnly) {
118 this.getCHKOnly = getCHKOnly;
122 * Returns whether this request is a global request.
123 * @return <code>true</code> if this request is a global request, <code>false</code> otherwise
125 public boolean isGlobal() {
130 * Sets whether this request is a global request.
132 * <code>true</code> if this request is a global request, <code>false</code> otherwise
134 public void setGlobal(boolean global) {
135 this.global = global;
139 * Returns the maximum number of retries of this request.
140 * @return The maximum number of retries of this request
142 public int getMaxRetries() {
147 * Sets the maximum number of retries of this request
149 * The maximum number of retries of this request
151 public void setMaxRetries(int maxRetries) {
152 this.maxRetries = maxRetries;
156 * Returns whether the data should be encoded early to generate the final
157 * key as fast as possible.
159 * @return {@code true} if the key should be generated early, {@code false}
162 public boolean isEarlyEncode() {
167 * Sets whether the data should be encoded early to generate the final key
168 * as fast as possible.
171 * {@code true} if the key should be generated early, {@code
174 public void setEarlyEncode(boolean earlyEncode) {
175 this.earlyEncode = earlyEncode;
179 * Returns the priority class of this request.
180 * @return The priority class of this request
182 public PriorityClass getPriorityClass() {
183 return priorityClass;
187 * Sets the priority class of this request.
188 * @param priorityClass
189 * The priority class of this request
191 public void setPriorityClass(PriorityClass priorityClass) {
192 this.priorityClass = priorityClass;
196 * Returns the verbosity of this request.
197 * @return The verbosity of this request
199 public Verbosity getVerbosity() {
204 * Sets the verbosity of this request.
206 * The verbosity of this request
208 public void setVerbosity(Verbosity verbosity) {
209 this.verbosity = verbosity;
213 * Returns the URI of this request
214 * @return The URI of this request.
216 public String getUri() {
224 protected void write(Writer writer) throws IOException {
226 writer.write("URI=" + uri + LINEFEED);
227 if (verbosity != null)
228 writer.write("Verbosity=" + verbosity.getValue() + LINEFEED);
230 writer.write("MaxRetries=" + maxRetries + LINEFEED);
231 writer.write("EarlyEncode=" + earlyEncode);
232 if (priorityClass != null)
233 writer.write("PriorityClass=" + priorityClass.getValue() + LINEFEED);
234 writer.write("GetCHKOnly=" + getCHKOnly + LINEFEED);
235 writer.write("Global=" + global + LINEFEED);
236 writer.write("DontCompress=" + dontCompress + LINEFEED);
237 if (clientToken != null)
238 writer.write("ClientToken=" + clientToken + LINEFEED);
239 if (persistence != null)
240 writer.write("Persistence=" + persistence.getName() + LINEFEED);