3 * Copyright (C) 2006 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 de.todesbaum.util.freenet.fcp2;
22 import java.io.IOException;
23 import java.io.Writer;
26 * Abstract base class for all put requests. It contains all parameters that put
27 * requests have in common.
29 * @author David Roden <droden@gmail.com>
32 public abstract class ClientPut extends Command {
34 /** The URI of this request. */
35 protected final String uri;
37 /** The client token of this request. */
38 protected String clientToken = null;
40 /** Whether this request should only create a CHK. */
41 protected boolean getCHKOnly = false;
43 /** Whether this request is a global request. */
44 protected boolean global = false;
46 /** Whether the node should not try to compress the file. */
47 protected boolean dontCompress = false;
49 /** The maximum number of retries of this command. */
50 protected int maxRetries = 0;
52 /** Whether to generate the keys early. */
53 protected boolean earlyEncode = false;
55 /** The persistence of this request. */
56 protected Persistence persistence = Persistence.CONNECTION;
58 /** The priority class of this request. */
59 protected PriorityClass priorityClass = PriorityClass.INTERACTIVE;
61 /** The verbosiry of this request. */
62 protected Verbosity verbosity = Verbosity.NONE;
65 * Creates a new put request with the specified name, identifier and URI.
68 * The name of this request
70 * The identifier of this request
72 * The URI of this request
74 protected ClientPut(String name, String identifier, String uri) {
75 super(name, identifier);
80 * Returns whether the node should not try to compress the data.
82 * @return <code>true</code> if the node should <strong>not</strong> try
83 * to compress the data
85 public boolean isDontCompress() {
90 * Sets whether the node should not try to compress the data. A client might
91 * set this hint on data that is clearly not compressible, like MPEG audio
92 * files, JPEG or PNG images, highly compressed movies, or compressed
93 * archives like ZIP files. Otherwise the node will try to compress the file
94 * which -- depending on the size of the data -- might take a lot of time
98 * <code>true</code> if the node should <strong>not</strong>
99 * try to compress the data
101 public void setDontCompress(boolean dontCompress) {
102 this.dontCompress = dontCompress;
106 * Returns whether this request should only return the CHK of the data.
107 * @return Whether this request should only return the CHK of the data
109 public boolean isGetCHKOnly() {
114 * Sets whether this request should only return the CHK of the data.
116 * <code>true</code> if this request should only return the CHK of the data
118 public void setGetCHKOnly(boolean getCHKOnly) {
119 this.getCHKOnly = getCHKOnly;
123 * Returns whether this request is a global request.
124 * @return <code>true</code> if this request is a global request, <code>false</code> otherwise
126 public boolean isGlobal() {
131 * Sets whether this request is a global request.
133 * <code>true</code> if this request is a global request, <code>false</code> otherwise
135 public void setGlobal(boolean global) {
136 this.global = global;
140 * Returns the maximum number of retries of this request.
141 * @return The maximum number of retries of this request
143 public int getMaxRetries() {
148 * Sets the maximum number of retries of this request
150 * The maximum number of retries of this request
152 public void setMaxRetries(int maxRetries) {
153 this.maxRetries = maxRetries;
157 * Returns whether the data should be encoded early to generate the final
158 * key as fast as possible.
160 * @return {@code true} if the key should be generated early, {@code false}
163 public boolean isEarlyEncode() {
168 * Sets whether the data should be encoded early to generate the final key
169 * as fast as possible.
172 * {@code true} if the key should be generated early, {@code
175 public void setEarlyEncode(boolean earlyEncode) {
176 this.earlyEncode = earlyEncode;
180 * Returns the priority class of this request.
181 * @return The priority class of this request
183 public PriorityClass getPriorityClass() {
184 return priorityClass;
188 * Sets the priority class of this request.
189 * @param priorityClass
190 * The priority class of this request
192 public void setPriorityClass(PriorityClass priorityClass) {
193 this.priorityClass = priorityClass;
197 * Returns the verbosity of this request.
198 * @return The verbosity of this request
200 public Verbosity getVerbosity() {
205 * Sets the verbosity of this request.
207 * The verbosity of this request
209 public void setVerbosity(Verbosity verbosity) {
210 this.verbosity = verbosity;
214 * Returns the URI of this request
215 * @return The URI of this request.
217 public String getUri() {
225 protected void write(Writer writer) throws IOException {
227 writer.write("URI=" + uri + LINEFEED);
228 if (verbosity != null)
229 writer.write("Verbosity=" + verbosity.getValue() + LINEFEED);
231 writer.write("MaxRetries=" + maxRetries + LINEFEED);
232 writer.write("EarlyEncode=" + earlyEncode);
233 if (priorityClass != null)
234 writer.write("PriorityClass=" + priorityClass.getValue() + LINEFEED);
235 writer.write("GetCHKOnly=" + getCHKOnly + LINEFEED);
236 writer.write("Global=" + global + LINEFEED);
237 writer.write("DontCompress=" + dontCompress + LINEFEED);
238 if (clientToken != null)
239 writer.write("ClientToken=" + clientToken + LINEFEED);
240 if (persistence != null)
241 writer.write("Persistence=" + persistence.getName() + LINEFEED);