2 * jFCPlib - PersistentPutDir.java - Copyright © 2008 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 net.pterodactylus.fcp;
22 * A “PersistentPutDir” is the response to a {@link ClientPutDiskDir} message.
23 * It is also sent as a possible response to a {@link ListPersistentRequests}
26 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
28 public class PersistentPutDir extends BaseMessage implements Identifiable {
31 * Creates a new “PersistentPutDir” message that wraps the received
34 * @param receivedMessage
35 * The received message
37 public PersistentPutDir(FcpMessage receivedMessage) {
38 super(receivedMessage);
42 * Returns the identifier of the request.
44 * @return The identifier of the request
47 public String getIdentifier() {
48 return getField("Identifier");
52 * Returns the URI of the request.
54 * @return The URI of the request
56 public String getURI() {
57 return getField("URI");
61 * Returns the verbosity of the request.
63 * @return The verbosity of the request
65 public Verbosity getVerbosity() {
66 return Verbosity.valueOf(getField("Verbosity"));
70 * Returns the priority of the request.
72 * @return The priority of the request
74 public Priority getPriority() {
75 return Priority.values()[FcpUtils.safeParseInt(getField("PriorityClass"), Priority.unknown.ordinal())];
79 * Returns whether the request is on the global queue.
81 * @return <code>true</code> if the request is on the global queue,
82 * <code>false</code> if it is on the client-local queue
84 public boolean isGlobal() {
85 return Boolean.valueOf(getField("Global"));
89 * Returns the maximum number of retries for failed blocks.
91 * @return The maximum number of retries, or <code>-1</code> for endless
92 * retries, or <code>-2</code> if the number could not be parsed
94 public int getMaxRetries() {
95 return FcpUtils.safeParseInt(getField("MaxRetries"), -2);
99 * Returns the number of files in the request.
101 * @return The number of files in the request
103 public int getFileCount() {
105 while (getField("Files." + ++fileCount + ".UploadFrom") != null) {
112 * Returns the name of the file at the given index. The index is counted
113 * from <code>0</code>.
116 * The index of the file
117 * @return The name of the file at the given index
119 public String getFileName(int fileIndex) {
120 return getField("Files." + fileIndex + ".Name");
124 * Returns the length of the file at the given index. The index is counted
125 * from <code>0</code>.
128 * The index of the file
129 * @return The length of the file at the given index
131 public long getFileDataLength(int fileIndex) {
132 return FcpUtils.safeParseLong(getField("Files." + fileIndex + ".DataLength"));
136 * Returns the upload source of the file at the given index. The index is
137 * counted from <code>0</code>.
140 * The index of the file
141 * @return The upload source of the file at the given index
143 public UploadFrom getFileUploadFrom(int fileIndex) {
144 return UploadFrom.valueOf(getField("Files." + fileIndex + ".UploadFrom"));
148 * Returns the content type of the file at the given index. The index is
149 * counted from <code>0</code>.
152 * The index of the file
153 * @return The content type of the file at the given index
155 public String getFileMetadataContentType(int fileIndex) {
156 return getField("Files." + fileIndex + ".Metadata.ContentType");
160 * Returns the filename of the file at the given index. This value is only
161 * returned if {@link #getFileUploadFrom(int)} is returning
162 * {@link UploadFrom#disk}. The index is counted from <code>0</code>.
165 * The index of the file
166 * @return The filename of the file at the given index
168 public String getFileFilename(int fileIndex) {
169 return getField("Files." + fileIndex + ".Filename");