c2ead161b1b22b245380ed6978b7356c84f6b268
[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         public 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                 try {
55                         return Long.valueOf(getField("DataLength"));
56                 } catch (NumberFormatException nfe1) {
57                         return -1;
58                 }
59         }
60
61         /**
62          * Returns the startup time of the request.
63          * 
64          * @return The startup time of the request (in milliseconds since Jan 1,
65          *         1970 UTC), or <code>-1</code> if the time could not be parsed
66          */
67         public long getStartupTime() {
68                 try {
69                         return Long.valueOf(getField("StartupTime"));
70                 } catch (NumberFormatException nfe1) {
71                         return -1;
72                 }
73         }
74
75         /**
76          * Returns the completion time of the request.
77          * 
78          * @return The completion time of the request (in milliseconds since Jan 1,
79          *         1970 UTC), or <code>-1</code> if the time could not be parsed
80          */
81         public long getCompletionTime() {
82                 try {
83                         return Long.valueOf(getField("CompletionTime"));
84                 } catch (NumberFormatException nfe1) {
85                         return -1;
86                 }
87         }
88
89         /**
90          * Returns the payload input stream.
91          * 
92          * @return The payload
93          */
94         public InputStream getPayloadInputStream() {
95                 return payloadInputStream;
96         }
97
98 }