84faa540b2e66a07771d7cc6e863ff73cb6d536d
[jFCPlib.git] / src / net / pterodactylus / fcp / FCPPluginReply.java
1 /*
2  * jSite2 - FCPPluginReply.java -
3  * Copyright © 2008 David Roden
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 package net.pterodactylus.fcp;
21
22 import java.io.InputStream;
23
24 /**
25  * The “FCPPluginReply” is sent by a plugin as a response to a
26  * {@link FCPPluginMessage} message.
27  * 
28  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
29  */
30 public class FCPPluginReply extends BaseMessage {
31
32         /** The payload input stream. */
33         private final InputStream payloadInputStream;
34
35         /**
36          * Creates a new “FCPPluginReply” message that wraps the received message.
37          * 
38          * @param receivedMessage
39          *            The received message
40          * @param payloadInputStream
41          *            The optional input stream for the payload
42          */
43         FCPPluginReply(FcpMessage receivedMessage, InputStream payloadInputStream) {
44                 super(receivedMessage);
45                 this.payloadInputStream = payloadInputStream;
46         }
47
48         /**
49          * Returns the name of the plugin.
50          * 
51          * @return The name of the plugin
52          */
53         public String getPluginName() {
54                 return getField("PluginName");
55         }
56
57         /**
58          * Returns the identifier of the request.
59          * 
60          * @return The identifier of the request
61          */
62         public String getIdentifier() {
63                 return getField("Identifier");
64         }
65
66         /**
67          * Returns the length of the optional payload.
68          * 
69          * @return The length of the payload, or <code>-1</code> if there is no
70          *         payload or the length could not be parsed
71          */
72         public long getDataLength() {
73                 return FcpUtils.safeParseLong(getField("DataLength"));
74         }
75
76         /**
77          * Returns a reply from the plugin.
78          * 
79          * @param key
80          *            The name of the reply
81          * @return The value of the reply
82          */
83         public String getReply(String key) {
84                 return getField("Replies." + key);
85         }
86
87         /**
88          * Returns the optional payload.
89          * 
90          * @return The payload of the reply, or <code>null</code> if there is no
91          *         payload
92          */
93         public InputStream getPayloadInputStream() {
94                 return payloadInputStream;
95         }
96
97 }