implement node addition and removal events
[jSite2.git] / src / net / pterodactylus / util / fcp / AllData.java
1 /**
2  * © 2008 INA Service GmbH
3  */
4 package net.pterodactylus.util.fcp;
5
6 import java.io.InputStream;
7
8 /**
9  * The “AllData” message carries the payload of a successful {@link ClientGet}
10  * request. You will only received this message if the {@link ClientGet} request
11  * was started with a return type of {@link ReturnType#direct}. If you get this
12  * message and decide that the data is for you, call
13  * {@link #getPayloadInputStream()} to get the data. If an AllData message
14  * passes through all registered {@link FcpListener}s without the payload being
15  * consumed, the payload is discarded!
16  * 
17  * @author <a href="mailto:dr@ina-germany.de">David Roden</a>
18  * @version $Id$
19  */
20 public class AllData extends BaseMessage {
21
22         /** The payload. */
23         private InputStream payloadInputStream;
24
25         /**
26          * Creates an “AllData” message that wraps the received message.
27          * 
28          * @param receivedMessage
29          *            The received message
30          * @param payloadInputStream
31          *            The payload
32          */
33         AllData(FcpMessage receivedMessage, InputStream payloadInputStream) {
34                 super(receivedMessage);
35                 this.payloadInputStream = payloadInputStream;
36         }
37
38         /**
39          * Returns the identifier of the request.
40          * 
41          * @return The identifier of the request
42          */
43         public String getIdentifier() {
44                 return getField("Identifier");
45         }
46
47         /**
48          * Returns the length of the data.
49          * 
50          * @return The length of the data, or <code>-1</code> if the length could
51          *         not be parsed
52          */
53         public long getDataLength() {
54                 return FcpUtils.safeParseLong(getField("DataLength"));
55         }
56
57         /**
58          * Returns the startup time of the request.
59          * 
60          * @return The startup time of the request (in milliseconds since Jan 1,
61          *         1970 UTC), or <code>-1</code> if the time could not be parsed
62          */
63         public long getStartupTime() {
64                 return FcpUtils.safeParseLong(getField("StartupTime"));
65         }
66
67         /**
68          * Returns the completion time of the request.
69          * 
70          * @return The completion time of the request (in milliseconds since Jan 1,
71          *         1970 UTC), or <code>-1</code> if the time could not be parsed
72          */
73         public long getCompletionTime() {
74                 return FcpUtils.safeParseLong(getField("CompletionTime"));
75         }
76
77         /**
78          * Returns the payload input stream.
79          * 
80          * @return The payload
81          */
82         public InputStream getPayloadInputStream() {
83                 return payloadInputStream;
84         }
85
86 }