Whitespace fixes.
[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  */
29 public class PersistentPutDir extends BaseMessage {
30
31         /**
32          * Creates a new “PersistentPutDir” message that wraps the received message.
33          *
34          * @param receivedMessage
35          *            The received message
36          */
37         PersistentPutDir(FcpMessage receivedMessage) {
38                 super(receivedMessage);
39         }
40
41         /**
42          * Returns the identifier of the request.
43          *
44          * @return The identifier of the request
45          */
46         public String getIdentifier() {
47                 return getField("Identifier");
48         }
49
50         /**
51          * Returns the URI of the request.
52          *
53          * @return The URI of the request
54          */
55         public String getURI() {
56                 return getField("URI");
57         }
58
59         /**
60          * Returns the verbosity of the request.
61          *
62          * @return The verbosity of the request
63          */
64         public Verbosity getVerbosity() {
65                 return Verbosity.valueOf(getField("Verbosity"));
66         }
67
68         /**
69          * Returns the priority of the request.
70          *
71          * @return The priority of the request
72          */
73         public Priority getPriority() {
74                 return Priority.values()[FcpUtils.safeParseInt(getField("PriorityClass"), Priority.unknown.ordinal())];
75         }
76
77         /**
78          * Returns whether the request is on the global queue.
79          *
80          * @return <code>true</code> if the request is on the global queue,
81          *         <code>false</code> if it is on the client-local queue
82          */
83         public boolean isGlobal() {
84                 return Boolean.valueOf(getField("Global"));
85         }
86
87         /**
88          * Returns the maximum number of retries for failed blocks.
89          *
90          * @return The maximum number of retries, or <code>-1</code> for endless
91          *         retries, or <code>-2</code> if the number could not be parsed
92          */
93         public int getMaxRetries() {
94                 return FcpUtils.safeParseInt(getField("MaxRetries"), -2);
95         }
96
97         /**
98          * Returns the number of files in the request.
99          *
100          * @return The number of files in the request
101          */
102         public int getFileCount() {
103                 int fileCount = -1;
104                 while (getField("Files." + ++fileCount + ".UploadFrom") != null) { /*
105                                                                                                                                                          * do
106                                                                                                                                                          * nothing.
107                                                                                                                                                          */
108                 }
109                 return fileCount;
110         }
111
112         /**
113          * Returns the name of the file at the given index. The index is counted
114          * from <code>0</code>.
115          *
116          * @param fileIndex
117          *            The index of the file
118          * @return The name of the file at the given index
119          */
120         public String getFileName(int fileIndex) {
121                 return getField("Files." + fileIndex + ".Name");
122         }
123
124         /**
125          * Returns the length of the file at the given index. The index is counted
126          * from <code>0</code>.
127          *
128          * @param fileIndex
129          *            The index of the file
130          * @return The length of the file at the given index
131          */
132         public long getFileDataLength(int fileIndex) {
133                 return FcpUtils.safeParseLong(getField("Files." + fileIndex + ".DataLength"));
134         }
135
136         /**
137          * Returns the upload source of the file at the given index. The index is
138          * counted from <code>0</code>.
139          *
140          * @param fileIndex
141          *            The index of the file
142          * @return The upload source of the file at the given index
143          */
144         public UploadFrom getFileUploadFrom(int fileIndex) {
145                 return UploadFrom.valueOf(getField("Files." + fileIndex + ".UploadFrom"));
146         }
147
148         /**
149          * Returns the content type of the file at the given index. The index is
150          * counted from <code>0</code>.
151          *
152          * @param fileIndex
153          *            The index of the file
154          * @return The content type of the file at the given index
155          */
156         public String getFileMetadataContentType(int fileIndex) {
157                 return getField("Files." + fileIndex + ".Metadata.ContentType");
158         }
159
160         /**
161          * Returns the filename of the file at the given index. This value is only
162          * returned if {@link #getFileUploadFrom(int)} is returning
163          * {@link UploadFrom#disk}. The index is counted from <code>0</code>.
164          *
165          * @param fileIndex
166          *            The index of the file
167          * @return The filename of the file at the given index
168          */
169         public String getFileFilename(int fileIndex) {
170                 return getField("Files." + fileIndex + ".Filename");
171         }
172
173 }