2 * jFCPlib - AllData.java - Copyright © 2008 David Roden
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 package net.pterodactylus.fcp;
21 import java.io.InputStream;
24 * The “AllData” message carries the payload of a successful {@link ClientGet}
25 * request. You will only received this message if the {@link ClientGet}
26 * request was started with a return type of {@link ReturnType#direct}. If you
27 * get this message and decide that the data is for you, call
28 * {@link #getPayloadInputStream()} to get the data. If an AllData message
29 * passes through all registered {@link FcpListener}s without the payload being
30 * consumed, the payload is discarded!
32 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
34 public class AllData extends BaseMessage implements Identifiable {
37 private InputStream payloadInputStream;
40 * Creates an “AllData” message that wraps the received message.
42 * @param receivedMessage
43 * The received message
44 * @param payloadInputStream
47 public AllData(FcpMessage receivedMessage, InputStream payloadInputStream) {
48 super(receivedMessage);
49 this.payloadInputStream = payloadInputStream;
53 * Returns the identifier of the request.
55 * @return The identifier of the request
58 public String getIdentifier() {
59 return getField("Identifier");
63 * Returns the length of the data.
65 * @return The length of the data, or <code>-1</code> if the length could
68 public long getDataLength() {
69 return FcpUtils.safeParseLong(getField("DataLength"));
73 * Returns the startup time of the request.
75 * @return The startup time of the request (in milliseconds since Jan 1,
76 * 1970 UTC), or <code>-1</code> if the time could not be parsed
78 public long getStartupTime() {
79 return FcpUtils.safeParseLong(getField("StartupTime"));
83 * Returns the completion time of the request.
85 * @return The completion time of the request (in milliseconds since Jan 1,
86 * 1970 UTC), or <code>-1</code> if the time could not be parsed
88 public long getCompletionTime() {
89 return FcpUtils.safeParseLong(getField("CompletionTime"));
93 * Returns the payload input stream. You <strong>have</strong> consume the
94 * input stream before returning from the
95 * {@link FcpListener#receivedAllData(FcpConnection, AllData)} method!
99 public InputStream getPayloadInputStream() {
100 return payloadInputStream;
104 * Returns the content type of the found file.
106 * @return The content type
108 public String getContentType() {
109 return getField("Metadata.ContentType");