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