271b8d73fb2e3aa4a7ecbc13af70dc31e6e07188
[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  * @version $Id$
30  */
31 public class FCPPluginReply extends BaseMessage {
32
33         /** The payload input stream. */
34         private final InputStream payloadInputStream;
35
36         /**
37          * Creates a new “FCPPluginReply” message that wraps the received message.
38          * 
39          * @param receivedMessage
40          *            The received message
41          * @param payloadInputStream
42          *            The optional input stream for the payload
43          */
44         FCPPluginReply(FcpMessage receivedMessage, InputStream payloadInputStream) {
45                 super(receivedMessage);
46                 this.payloadInputStream = payloadInputStream;
47         }
48
49         /**
50          * Returns the name of the plugin.
51          * 
52          * @return The name of the plugin
53          */
54         public String getPluginName() {
55                 return getField("PluginName");
56         }
57
58         /**
59          * Returns the identifier of the request.
60          * 
61          * @return The identifier of the request
62          */
63         public String getIdentifier() {
64                 return getField("Identifier");
65         }
66
67         /**
68          * Returns the length of the optional payload.
69          * 
70          * @return The length of the payload, or <code>-1</code> if there is no
71          *         payload or the length could not be parsed
72          */
73         public long getDataLength() {
74                 return FcpUtils.safeParseLong(getField("DataLength"));
75         }
76
77         /**
78          * Returns a reply from the plugin.
79          * 
80          * @param key
81          *            The name of the reply
82          * @return The value of the reply
83          */
84         public String getReply(String key) {
85                 return getField("Replies." + key);
86         }
87
88         /**
89          * Returns the optional payload.
90          * 
91          * @return The payload of the reply, or <code>null</code> if there is no
92          *         payload
93          */
94         public InputStream getPayloadInputStream() {
95                 return payloadInputStream;
96         }
97
98 }