rename fcplib to jFCPlib
[jFCPlib.git] / src / net / pterodactylus / fcp / PersistentPutDir.java
1 /*
2  * jSite2 - PersistentPutDir.java -
3  * Copyright © 2008 David Roden
4  *
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.
9  *
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.
14  *
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.
18  */
19
20 package net.pterodactylus.fcp;
21
22 /**
23  * A “PersistentPutDir” is the response to a {@link ClientPutDiskDir} message.
24  * It is also sent as a possible response to a {@link ListPersistentRequests}
25  * message.
26  * 
27  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
28  * @version $Id$
29  */
30 public class PersistentPutDir extends BaseMessage {
31
32         /**
33          * Creates a new “PersistentPutDir” message that wraps the received message.
34          * 
35          * @param receivedMessage
36          *            The received message
37          */
38         PersistentPutDir(FcpMessage receivedMessage) {
39                 super(receivedMessage);
40         }
41
42         /**
43          * Returns the identifier of the request.
44          * 
45          * @return The identifier of the request
46          */
47         public String getIdentifier() {
48                 return getField("Identifier");
49         }
50
51         /**
52          * Returns the URI of the request.
53          * 
54          * @return The URI of the request
55          */
56         public String getURI() {
57                 return getField("URI");
58         }
59
60         /**
61          * Returns the verbosity of the request.
62          * 
63          * @return The verbosity of the request
64          */
65         public Verbosity getVerbosity() {
66                 return Verbosity.valueOf(getField("Verbosity"));
67         }
68
69         /**
70          * Returns the priority of the request.
71          * 
72          * @return The priority of the request
73          */
74         public Priority getPriority() {
75                 return Priority.valueOf(getField("PriorityClass"));
76         }
77
78         /**
79          * Returns whether the request is on the global queue.
80          * 
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
83          */
84         public boolean isGlobal() {
85                 return Boolean.valueOf(getField("Global"));
86         }
87
88         /**
89          * Returns the maximum number of retries for failed blocks.
90          * 
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
93          */
94         public int getMaxRetries() {
95                 return FcpUtils.safeParseInt(getField("MaxRetries"), -2);
96         }
97
98         /**
99          * Returns the number of files in the request.
100          * 
101          * @return The number of files in the request
102          */
103         public int getFileCount() {
104                 int fileCount = -1;
105                 while (getField("Files." + ++fileCount + ".UploadFrom") != null) { /*
106                                                                                                                                                          * do
107                                                                                                                                                          * nothing.
108                                                                                                                                                          */
109                 }
110                 return fileCount;
111         }
112
113         /**
114          * Returns the name of the file at the given index. The index is counted
115          * from <code>0</code>.
116          * 
117          * @param fileIndex
118          *            The index of the file
119          * @return The name of the file at the given index
120          */
121         public String getFileName(int fileIndex) {
122                 return getField("Files." + fileIndex + ".Name");
123         }
124
125         /**
126          * Returns the length of the file at the given index. The index is counted
127          * from <code>0</code>.
128          * 
129          * @param fileIndex
130          *            The index of the file
131          * @return The length of the file at the given index
132          */
133         public long getFileDataLength(int fileIndex) {
134                 return FcpUtils.safeParseLong(getField("Files." + fileIndex + ".DataLength"));
135         }
136
137         /**
138          * Returns the upload source of the file at the given index. The index is
139          * counted from <code>0</code>.
140          * 
141          * @param fileIndex
142          *            The index of the file
143          * @return The upload source of the file at the given index
144          */
145         public UploadFrom getFileUploadFrom(int fileIndex) {
146                 return UploadFrom.valueOf(getField("Files." + fileIndex + ".UploadFrom"));
147         }
148
149         /**
150          * Returns the content type of the file at the given index. The index is
151          * counted from <code>0</code>.
152          * 
153          * @param fileIndex
154          *            The index of the file
155          * @return The content type of the file at the given index
156          */
157         public String getFileMetadataContentType(int fileIndex) {
158                 return getField("Files." + fileIndex + ".Metadata.ContentType");
159         }
160
161         /**
162          * Returns the filename of the file at the given index. This value is only
163          * returned if {@link #getFileUploadFrom(int)} is returning
164          * {@link UploadFrom#disk}. The index is counted from <code>0</code>.
165          * 
166          * @param fileIndex
167          *            The index of the file
168          * @return The filename of the file at the given index
169          */
170         public String getFileFilename(int fileIndex) {
171                 return getField("Files." + fileIndex + ".Filename");
172         }
173
174 }