Update license to GPLv3, fix header comments
[jFCPlib.git] / src / main / java / net / pterodactylus / fcp / PersistentPut.java
1 /*
2  * jFCPlib - PersistentPut.java - Copyright © 2008–2016 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 3 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, see <http://www.gnu.org/licenses/>.
16  */
17
18 package net.pterodactylus.fcp;
19
20 /**
21  * A “PersistentPut” message notifies a client about a persistent
22  * {@link ClientPut} request.
23  *
24  * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
25  */
26 public class PersistentPut extends BaseMessage implements Identifiable {
27
28         /**
29          * Creates a new “PersistentPut” message that wraps the received message.
30          *
31          * @param receivedMessage
32          *            The received message
33          */
34         public PersistentPut(FcpMessage receivedMessage) {
35                 super(receivedMessage);
36         }
37
38         /**
39          * Returns the client token of the request.
40          *
41          * @return The client token of the request
42          */
43         public String getClientToken() {
44                 return getField("ClientToken");
45         }
46
47         /**
48          * Returns the data length of the request.
49          *
50          * @return The data length of the request, or <code>-1</code> if the length
51          *         could not be parsed
52          */
53         public long getDataLength() {
54                 return FcpUtils.safeParseLong(getField("DataLength"));
55         }
56
57         /**
58          * Returns whether the request is on the global queue.
59          *
60          * @return <code>true</code> if the request is on the global queue,
61          *         <code>false</code> otherwise
62          */
63         public boolean isGlobal() {
64                 return Boolean.valueOf(getField("Global"));
65         }
66
67         /**
68          * Returns the identifier of the request.
69          *
70          * @return The identifier of the request
71          */
72         @Override
73         public String getIdentifier() {
74                 return getField("Identifier");
75         }
76
77         /**
78          * Returns the maximum number of retries for failed blocks. When
79          * <code>-1</code> is returned each block is tried forever.
80          *
81          * @return The maximum number of retries for failed blocks, or
82          *         <code>-1</code> for unlimited retries, or <code>-2</code> if the
83          *         number of retries could not be parsed
84          */
85         public int getMaxRetries() {
86                 return FcpUtils.safeParseInt(getField("MaxRetries"));
87         }
88
89         /**
90          * Returns the content type of the data.
91          *
92          * @return The content type
93          */
94         public String getMetadataContentType() {
95                 return getField("Metadata.ContentType");
96         }
97
98         /**
99          * Returns the persistence of the request.
100          *
101          * @return The persistence of the request
102          */
103         public Persistence getPersistence() {
104                 return Persistence.valueOf(getField("Persistence"));
105         }
106
107         /**
108          * Returns the priority of the request.
109          *
110          * @return The priority of the request, or {@link Priority#unknown} if the
111          *         priority could not be parsed
112          */
113         public Priority getPriority() {
114                 return Priority.values()[FcpUtils.safeParseInt(getField("PriorityClass"), Priority.unknown.ordinal())];
115         }
116
117         /**
118          * Returns whether this request has started.
119          *
120          * @return <code>true</code> if the request has started, <code>false</code>
121          *         otherwise
122          */
123         public boolean isStarted() {
124                 return Boolean.valueOf(getField("Started"));
125         }
126
127         /**
128          * Returns the target filename of the request.
129          *
130          * @return The target filename of the request
131          */
132         public String getTargetFilename() {
133                 return getField("TargetFilename");
134         }
135
136         /**
137          * Returns the upload source of the request.
138          *
139          * @return The upload source of the request
140          */
141         public UploadFrom getUploadFrom() {
142                 return UploadFrom.valueOf(getField("UploadFrom"));
143         }
144
145         /**
146          * Returns the target URI of the request.
147          *
148          * @return The target URI of the request
149          */
150         public String getURI() {
151                 return getField("URI");
152         }
153
154         /**
155          * Returns the verbosity of the request.
156          *
157          * @return The verbosity of the request
158          */
159         public Verbosity getVerbosity() {
160                 return Verbosity.valueOf(getField("Verbosity"));
161         }
162
163 }