2 * jFCPlib - GetFailed.java - Copyright © 2008 David Roden
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.
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.
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.
19 package net.pterodactylus.fcp;
21 import java.util.ArrayList;
22 import java.util.List;
24 import java.util.Map.Entry;
27 * The “PutFailed” message signals the client that a {@link ClientPut} request
28 * has failed. This also means that no further progress messages for that
29 * request will be sent.
31 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
33 public class PutFailed extends BaseMessage implements Identifiable {
36 * Creates a new “PutFailed” message that wraps the received message.
38 * @param receivedMessage
39 * The received message
41 public PutFailed(FcpMessage receivedMessage) {
42 super(receivedMessage);
46 * Returns the code of the error.
48 * @return The code of the error, or <code>-1</code> if the error code
51 public int getCode() {
52 return FcpUtils.safeParseInt(getField("Code"));
56 * Returns the identifier of the request.
58 * @return The identifier of the request
61 public String getIdentifier() {
62 return getField("Identifier");
66 * Returns whether the request is on the global queue.
68 * @return <code>true</code> if the request is on the global queue,
69 * <code>false</code> if it is on the client-local queue
71 public boolean isGlobal() {
72 return Boolean.valueOf(getField("Global"));
76 * Returns the description of the error code.
78 * @return The description of the error code
80 public String getCodeDescription() {
81 return getField("CodeDescription");
85 * Returns the extra description of the error.
87 * @return The extra description of the error
89 public String getExtraDescription() {
90 return getField("ExtraDescription");
94 * Returns the short description of the error.
96 * @return The short description of the error
98 public String getShortCodeDescription() {
99 return getField("ShortCodeDescription");
103 * Returns the expected URI of the request.
105 * @return The expected URI
107 public String getExpectedURI() {
108 return getField("ExpectedURI");
112 * Returns whether the request failed fatally. If a request fails fatally
113 * it can never complete, even with inifinite retries.
115 * @return <code>true</code> if the request failed fatally,
116 * <code>false</code> otherwise
118 public boolean isFatal() {
119 return Boolean.valueOf(getField("Fatal"));
123 * Returns a list of complex error codes with the message. Use
124 * {@link #getComplexErrorDescription(int)} and
125 * {@link #getComplexErrorCount(int)} to get details.
127 * @return A list of complex error codes
129 public int[] getComplexErrorCodes() {
130 Map<String, String> allFields = getFields();
131 List<Integer> errorCodeList = new ArrayList<Integer>();
132 for (Entry<String, String> field : allFields.entrySet()) {
133 String fieldKey = field.getKey();
134 if (fieldKey.startsWith("Errors.")) {
135 int nextDot = fieldKey.indexOf('.', 7);
137 int errorCode = FcpUtils.safeParseInt(fieldKey.substring(7, nextDot));
138 if (errorCode != -1) {
139 errorCodeList.add(errorCode);
144 int[] errorCodes = new int[errorCodeList.size()];
146 for (int errorCode : errorCodeList) {
147 errorCodes[errorIndex++] = errorCode;
153 * Returns the description of the complex error. You should only hand it
154 * error codes you got from {@link #getComplexErrorCodes()}!
158 * @return The description of the complex error
160 public String getComplexErrorDescription(int errorCode) {
161 return getField("Errors." + errorCode + ".Description");
165 * Returns the count of the complex error. You should only hand it error
166 * codes you got from {@link #getComplexErrorCodes()}!
170 * @return The count of the complex error, or <code>-1</code> if the count
171 * could not be parsed
173 public int getComplexErrorCount(int errorCode) {
174 return FcpUtils.safeParseInt(getField("Errors." + errorCode + ".Count"));