196c6697b4a00a0498bc44a1a73b1f177d852223
[jFCPlib.git] / src / net / pterodactylus / fcp / PersistentGet.java
1 /*
2  * jSite2 - PersistentGet.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 /**
24  * The “PersistentGet” message is sent to the client to inform it about a
25  * persistent download, either in the client-local queue or in the global queue.
26  * 
27  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
28  */
29 public class PersistentGet extends BaseMessage {
30
31         /**
32          * Creates a new “PersistentGet” message that wraps the received message.
33          * 
34          * @param receivedMessage
35          *            The received message
36          */
37         PersistentGet(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 return type of the request.
70          * 
71          * @return The return type of the request
72          */
73         public ReturnType getReturnType() {
74                 try {
75                         return ReturnType.valueOf(getField("ReturnType"));
76                 } catch (IllegalArgumentException iae1) {
77                         return ReturnType.unknown;
78                 }
79         }
80
81         /**
82          * Returns the name of the file the data is downloaded to. This field will
83          * only be set if {@link #getReturnType()} is {@link ReturnType#disk}.
84          * 
85          * @return The name of the file the data is downloaded to
86          */
87         public String getFilename() {
88                 return getField("Filename");
89         }
90
91         /**
92          * Returns the name of the temporary file. This field will only be set if
93          * {@link #getReturnType()} is {@link ReturnType#disk}.
94          * 
95          * @return The name of the temporary file
96          */
97         public String getTempFilename() {
98                 return getField("TempFilename");
99         }
100
101         /**
102          * Returns the client token of the request.
103          * 
104          * @return The client token of the request
105          */
106         public String getClientToken() {
107                 return getField("ClientToken");
108         }
109
110         /**
111          * Returns the priority of the request.
112          * 
113          * @return The priority of the request
114          */
115         public Priority getPriority() {
116                 return Priority.values()[FcpUtils.safeParseInt(getField("PriorityClass"), Priority.unknown.ordinal())];
117         }
118
119         /**
120          * Returns the persistence of the request.
121          * 
122          * @return The persistence of the request, or {@link Persistence#unknown} if
123          *         the persistence could not be parsed
124          */
125         public Persistence getPersistence() {
126                 try {
127                         return Persistence.valueOf(getField("Persistence"));
128                 } catch (IllegalArgumentException iae1) {
129                         return Persistence.unknown;
130                 }
131         }
132
133         /**
134          * Returns whether this request is on the global queue or on the
135          * client-local queue.
136          * 
137          * @return <code>true</code> if the request is on the global queue,
138          *         <code>false</code> if the request is on the client-local queue
139          */
140         public boolean isGlobal() {
141                 return Boolean.valueOf(getField("Global"));
142         }
143
144         /**
145          * Returns the maximum number of retries for a failed block.
146          * 
147          * @return The maximum number of retries for a failed block, <code>-1</code>
148          *         for endless retries, <code>-2</code> if the number could not be
149          *         parsed
150          */
151         public int getMaxRetries() {
152                 return FcpUtils.safeParseInt(getField("MaxRetries"), -2);
153         }
154
155 }