--- /dev/null
+/*
+ * jSite2 - FCPPluginReply.java -
+ * Copyright © 2008 David Roden
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+package net.pterodactylus.util.fcp;
+
+import java.io.InputStream;
+
+/**
+ * The “FCPPluginReply” is sent by a plugin as a response to a
+ * {@link FCPPluginMessage} message.
+ *
+ * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
+ * @version $Id$
+ */
+public class FCPPluginReply extends BaseMessage {
+
+ /** The payload input stream. */
+ private final InputStream payloadInputStream;
+
+ /**
+ * Creates a new “FCPPluginReply” message that wraps the received message.
+ *
+ * @param receivedMessage
+ * The received message
+ * @param payloadInputStream
+ * The optional input stream for the payload
+ */
+ FCPPluginReply(FcpMessage receivedMessage, InputStream payloadInputStream) {
+ super(receivedMessage);
+ this.payloadInputStream = payloadInputStream;
+ }
+
+ /**
+ * Returns the name of the plugin.
+ *
+ * @return The name of the plugin
+ */
+ public String getPluginName() {
+ return getField("PluginName");
+ }
+
+ /**
+ * Returns the identifier of the request.
+ *
+ * @return The identifier of the request
+ */
+ public String getIdentifier() {
+ return getField("Identifier");
+ }
+
+ /**
+ * Returns the length of the optional payload.
+ *
+ * @return The length of the payload, or <code>-1</code> if there is no
+ * payload or the length could not be parsed
+ */
+ public long getDataLength() {
+ return FcpUtils.safeParseLong(getField("DataLength"));
+ }
+
+ /**
+ * Returns a reply from the plugin.
+ *
+ * @param key
+ * The name of the reply
+ * @return The value of the reply
+ */
+ public String getReply(String key) {
+ return getField("Replies." + key);
+ }
+
+ /**
+ * Returns the optional payload.
+ *
+ * @return The payload of the reply, or <code>null</code> if there is no
+ * payload
+ */
+ public InputStream getPayloadInputStream() {
+ return payloadInputStream;
+ }
+
+}
}
/**
+ * Notifies all listeners that an “FCPPluginReply” message was received.
+ *
+ * @param fcpPluginReply
+ * The “FCPPluginReply” message
+ */
+ private void fireReceivedFCPPluginReply(FCPPluginReply fcpPluginReply) {
+ for (FcpListener fcpListener: fcpListeners) {
+ fcpListener.receivedFCPPluginReply(this, fcpPluginReply);
+ }
+ }
+
+ /**
* Notifies all listeners that a “ProtocolError” message was received.
*
* @param protocolError
fireReceivedUnknownPeerNoteType(new UnknownPeerNoteType(fcpMessage));
} else if ("UnknownNodeIdentifier".equals(messageName)) {
fireReceivedUnknownNodeIdentifier(new UnknownNodeIdentifier(fcpMessage));
+ } else if ("FCPPluginReply".equals(messageName)) {
+ LimitedInputStream payloadInputStream = getInputStream(FcpUtils.safeParseLong(fcpMessage.getField("DataLength")));
+ fireReceivedFCPPluginReply(new FCPPluginReply(fcpMessage, payloadInputStream));
+ try {
+ payloadInputStream.consume();
+ } catch (IOException ioe1) {
+ /* ignore. */
+ }
} else if ("PluginInfo".equals(messageName)) {
fireReceivedPluginInfo(new PluginInfo(fcpMessage));
} else if ("NodeData".equals(messageName)) {