76a57fe9814eb7500f8c778e76bc11b12e9c8a63
[jFCPlib.git] / src / main / java / net / pterodactylus / fcp / PersistentGet.java
1 /*
2  * jFCPlib - PersistentGet.java - Copyright © 2008 David Roden
3  *
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.
8  *
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.
13  *
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.
17  */
18
19 package net.pterodactylus.fcp;
20
21 /**
22  * The “PersistentGet” message is sent to the client to inform it about a
23  * persistent download, either in the client-local queue or in the global queue.
24  *
25  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
26  */
27 public class PersistentGet extends BaseMessage implements Identifiable {
28
29         /**
30          * Creates a new “PersistentGet” message that wraps the received message.
31          *
32          * @param receivedMessage
33          *            The received message
34          */
35         PersistentGet(FcpMessage receivedMessage) {
36                 super(receivedMessage);
37         }
38
39         /**
40          * Returns the identifier of the request.
41          *
42          * @return The identifier of the request
43          */
44         public String getIdentifier() {
45                 return getField("Identifier");
46         }
47
48         /**
49          * Returns the URI of the request.
50          *
51          * @return The URI of the request
52          */
53         public String getURI() {
54                 return getField("URI");
55         }
56
57         /**
58          * Returns the verbosity of the request.
59          *
60          * @return The verbosity of the request
61          */
62         public Verbosity getVerbosity() {
63                 return Verbosity.valueOf(getField("Verbosity"));
64         }
65
66         /**
67          * Returns the return type of the request.
68          *
69          * @return The return type of the request
70          */
71         public ReturnType getReturnType() {
72                 try {
73                         return ReturnType.valueOf(getField("ReturnType"));
74                 } catch (IllegalArgumentException iae1) {
75                         return ReturnType.unknown;
76                 }
77         }
78
79         /**
80          * Returns the name of the file the data is downloaded to. This field will
81          * only be set if {@link #getReturnType()} is {@link ReturnType#disk}.
82          *
83          * @return The name of the file the data is downloaded to
84          */
85         public String getFilename() {
86                 return getField("Filename");
87         }
88
89         /**
90          * Returns the name of the temporary file. This field will only be set if
91          * {@link #getReturnType()} is {@link ReturnType#disk}.
92          *
93          * @return The name of the temporary file
94          */
95         public String getTempFilename() {
96                 return getField("TempFilename");
97         }
98
99         /**
100          * Returns the client token of the request.
101          *
102          * @return The client token of the request
103          */
104         public String getClientToken() {
105                 return getField("ClientToken");
106         }
107
108         /**
109          * Returns the priority of the request.
110          *
111          * @return The priority of the request
112          */
113         public Priority getPriority() {
114                 return Priority.values()[FcpUtils.safeParseInt(getField("PriorityClass"), Priority.unknown.ordinal())];
115         }
116
117         /**
118          * Returns the persistence of the request.
119          *
120          * @return The persistence of the request, or {@link Persistence#unknown} if
121          *         the persistence could not be parsed
122          */
123         public Persistence getPersistence() {
124                 try {
125                         return Persistence.valueOf(getField("Persistence"));
126                 } catch (IllegalArgumentException iae1) {
127                         return Persistence.unknown;
128                 }
129         }
130
131         /**
132          * Returns whether this request is on the global queue or on the
133          * client-local queue.
134          *
135          * @return <code>true</code> if the request is on the global queue,
136          *         <code>false</code> if the request is on the client-local queue
137          */
138         public boolean isGlobal() {
139                 return Boolean.valueOf(getField("Global"));
140         }
141
142         /**
143          * Returns the maximum number of retries for a failed block.
144          *
145          * @return The maximum number of retries for a failed block, <code>-1</code>
146          *         for endless retries, <code>-2</code> if the number could not be
147          *         parsed
148          */
149         public int getMaxRetries() {
150                 return FcpUtils.safeParseInt(getField("MaxRetries"), -2);
151         }
152
153 }