rename fcplib to jFCPlib
[jFCPlib.git] / src / net / pterodactylus / fcp / FCPPluginReply.java
diff --git a/src/net/pterodactylus/fcp/FCPPluginReply.java b/src/net/pterodactylus/fcp/FCPPluginReply.java
new file mode 100644 (file)
index 0000000..271b8d7
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+ * 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.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;
+       }
+
+}