rename fcplib to jFCPlib
[jFCPlib.git] / src / net / pterodactylus / fcp / AllData.java
1 /*
2  * jSite2 - AllData.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 “AllData” message carries the payload of a successful {@link ClientGet}
26  * request. You will only received this message if the {@link ClientGet} request
27  * was started with a return type of {@link ReturnType#direct}. If you get this
28  * message and decide that the data is for you, call
29  * {@link #getPayloadInputStream()} to get the data. If an AllData message
30  * passes through all registered {@link FcpListener}s without the payload being
31  * consumed, the payload is discarded!
32  * 
33  * @author <a href="mailto:dr@ina-germany.de">David Roden</a>
34  * @version $Id$
35  */
36 public class AllData extends BaseMessage {
37
38         /** The payload. */
39         private InputStream payloadInputStream;
40
41         /**
42          * Creates an “AllData” message that wraps the received message.
43          * 
44          * @param receivedMessage
45          *            The received message
46          * @param payloadInputStream
47          *            The payload
48          */
49         AllData(FcpMessage receivedMessage, InputStream payloadInputStream) {
50                 super(receivedMessage);
51                 this.payloadInputStream = payloadInputStream;
52         }
53
54         /**
55          * Returns the identifier of the request.
56          * 
57          * @return The identifier of the request
58          */
59         public String getIdentifier() {
60                 return getField("Identifier");
61         }
62
63         /**
64          * Returns the length of the data.
65          * 
66          * @return The length of the data, or <code>-1</code> if the length could
67          *         not be parsed
68          */
69         public long getDataLength() {
70                 return FcpUtils.safeParseLong(getField("DataLength"));
71         }
72
73         /**
74          * Returns the startup time of the request.
75          * 
76          * @return The startup time of the request (in milliseconds since Jan 1,
77          *         1970 UTC), or <code>-1</code> if the time could not be parsed
78          */
79         public long getStartupTime() {
80                 return FcpUtils.safeParseLong(getField("StartupTime"));
81         }
82
83         /**
84          * Returns the completion time of the request.
85          * 
86          * @return The completion time of the request (in milliseconds since Jan 1,
87          *         1970 UTC), or <code>-1</code> if the time could not be parsed
88          */
89         public long getCompletionTime() {
90                 return FcpUtils.safeParseLong(getField("CompletionTime"));
91         }
92
93         /**
94          * Returns the payload input stream.
95          * 
96          * @return The payload
97          */
98         public InputStream getPayloadInputStream() {
99                 return payloadInputStream;
100         }
101
102 }