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 /** The persistence of this request. */
53 protected Persistence persistence = Persistence.CONNECTION;
55 /** The priority class of this request. */
56 protected PriorityClass priorityClass = PriorityClass.INTERACTIVE;
58 /** The verbosiry of this request. */
59 protected Verbosity verbosity = Verbosity.NONE;
62 * Creates a new put request with the specified name, identifier and URI.
65 * The name of this request
67 * The identifier of this request
69 * The URI of this request
71 protected ClientPut(String name, String identifier, String uri) {
72 super(name, identifier);
77 * Returns whether the node should not try to compress the data.
79 * @return <code>true</code> if the node should <strong>not</strong> try
80 * to compress the data
82 public boolean isDontCompress() {
87 * Sets whether the node should not try to compress the data. A client might
88 * set this hint on data that is clearly not compressible, like MPEG audio
89 * files, JPEG or PNG images, highly compressed movies, or compressed
90 * archives like ZIP files. Otherwise the node will try to compress the file
91 * which -- depending on the size of the data -- might take a lot of time
95 * <code>true</code> if the node should <strong>not</strong>
96 * try to compress the data
98 public void setDontCompress(boolean dontCompress) {
99 this.dontCompress = dontCompress;
103 * Returns whether this request should only return the CHK of the data.
104 * @return Whether this request should only return the CHK of the data
106 public boolean isGetCHKOnly() {
111 * Sets whether this request should only return the CHK of the data.
113 * <code>true</code> if this request should only return the CHK of the data
115 public void setGetCHKOnly(boolean getCHKOnly) {
116 this.getCHKOnly = getCHKOnly;
120 * Returns whether this request is a global request.
121 * @return <code>true</code> if this request is a global request, <code>false</code> otherwise
123 public boolean isGlobal() {
128 * Sets whether this request is a global request.
130 * <code>true</code> if this request is a global request, <code>false</code> otherwise
132 public void setGlobal(boolean global) {
133 this.global = global;
137 * Returns the maximum number of retries of this request.
138 * @return The maximum number of retries of this request
140 public int getMaxRetries() {
145 * Sets the maximum number of retries of this request
147 * The maximum number of retries of this request
149 public void setMaxRetries(int maxRetries) {
150 this.maxRetries = maxRetries;
154 * Returns the priority class of this request.
155 * @return The priority class of this request
157 public PriorityClass getPriorityClass() {
158 return priorityClass;
162 * Sets the priority class of this request.
163 * @param priorityClass
164 * The priority class of this request
166 public void setPriorityClass(PriorityClass priorityClass) {
167 this.priorityClass = priorityClass;
171 * Returns the verbosity of this request.
172 * @return The verbosity of this request
174 public Verbosity getVerbosity() {
179 * Sets the verbosity of this request.
181 * The verbosity of this request
183 public void setVerbosity(Verbosity verbosity) {
184 this.verbosity = verbosity;
188 * Returns the URI of this request
189 * @return The URI of this request.
191 public String getUri() {
199 protected void write(Writer writer) throws IOException {
201 writer.write("URI=" + uri + LINEFEED);
202 if (verbosity != null)
203 writer.write("Verbosity=" + verbosity.getValue() + LINEFEED);
205 writer.write("MaxRetries=" + maxRetries + LINEFEED);
206 if (priorityClass != null)
207 writer.write("PriorityClass=" + priorityClass.getValue() + LINEFEED);
208 writer.write("GetCHKOnly=" + getCHKOnly + LINEFEED);
209 writer.write("Global=" + global + LINEFEED);
210 writer.write("DontCompress=" + dontCompress + LINEFEED);
211 if (clientToken != null)
212 writer.write("ClientToken=" + clientToken + LINEFEED);
213 if (persistence != null)
214 writer.write("Persistence=" + persistence.getName() + LINEFEED);