2 * jFCPlib - FCPPluginReply.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.io.InputStream;
22 import java.util.HashMap;
24 import java.util.Map.Entry;
27 * The “FCPPluginReply” is sent by a plugin as a response to a
28 * {@link FCPPluginMessage} message.
30 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
32 public class FCPPluginReply extends BaseMessage implements Identifiable {
34 /** The payload input stream. */
35 private final InputStream payloadInputStream;
38 * Creates a new “FCPPluginReply” message that wraps the received message.
40 * @param receivedMessage
41 * The received message
42 * @param payloadInputStream
43 * The optional input stream for the payload
45 public FCPPluginReply(FcpMessage receivedMessage, InputStream payloadInputStream) {
46 super(receivedMessage);
47 this.payloadInputStream = payloadInputStream;
51 * Returns the name of the plugin.
53 * @return The name of the plugin
55 public String getPluginName() {
56 return getField("PluginName");
60 * Returns the identifier of the request.
62 * @return The identifier of the request
65 public String getIdentifier() {
66 return getField("Identifier");
70 * Returns the length of the optional payload.
72 * @return The length of the payload, or <code>-1</code> if there is no
73 * payload or the length could not be parsed
75 public long getDataLength() {
76 return FcpUtils.safeParseLong(getField("DataLength"));
80 * Returns a reply from the plugin.
83 * The name of the reply
84 * @return The value of the reply
86 public String getReply(String key) {
87 return getField("Replies." + key);
91 * Returns all replies from the plugin. The plugin sends replies as normal
92 * message fields prefixed by “Replies.”. The keys of the returned map do
93 * not contain this prefix!
95 * @return All replies from the plugin
97 public Map<String, String> getReplies() {
98 Map<String, String> fields = getFields();
99 Map<String, String> replies = new HashMap<String, String>();
100 for (Entry<String, String> field : fields.entrySet()) {
101 if (field.getKey().startsWith("Replies.")) {
102 replies.put(field.getKey().substring(8), field.getValue());
109 * Returns the optional payload.
111 * @return The payload of the reply, or <code>null</code> if there is no
114 public InputStream getPayloadInputStream() {
115 return payloadInputStream;