Expose lots of constructors and accessors
[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
24  * queue.
25  *
26  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
27  */
28 public class PersistentGet extends BaseMessage implements Identifiable {
29
30         /**
31          * Creates a new “PersistentGet” message that wraps the received message.
32          *
33          * @param receivedMessage
34          *            The received message
35          */
36         public PersistentGet(FcpMessage receivedMessage) {
37                 super(receivedMessage);
38         }
39
40         /**
41          * Returns the identifier of the request.
42          *
43          * @return The identifier of the request
44          */
45         @Override
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}
123          *         if 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,
148          *         <code>-1</code> for endless retries, <code>-2</code> if the
149          *         number could not be parsed
150          */
151         public int getMaxRetries() {
152                 return FcpUtils.safeParseInt(getField("MaxRetries"), -2);
153         }
154
155 }