2 * jFCPlib - AllData.java - Copyright © 2008–2016 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 3 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, see <http://www.gnu.org/licenses/>.
18 package net.pterodactylus.fcp;
20 import java.io.InputStream;
23 * The “AllData” message carries the payload of a successful {@link ClientGet}
24 * request. You will only received this message if the {@link ClientGet}
25 * request was started with a return type of {@link ReturnType#direct}. If you
26 * get this message and decide that the data is for you, call
27 * {@link #getPayloadInputStream()} to get the data. If an AllData message
28 * passes through all registered {@link FcpListener}s without the payload being
29 * consumed, the payload is discarded!
31 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
33 public class AllData extends BaseMessage implements Identifiable {
36 private InputStream payloadInputStream;
39 * Creates an “AllData” message that wraps the received message.
41 * @param receivedMessage
42 * The received message
43 * @param payloadInputStream
46 public AllData(FcpMessage receivedMessage, InputStream payloadInputStream) {
47 super(receivedMessage);
48 this.payloadInputStream = payloadInputStream;
52 * Returns the identifier of the request.
54 * @return The identifier of the request
57 public String getIdentifier() {
58 return getField("Identifier");
62 * Returns the length of the data.
64 * @return The length of the data, or <code>-1</code> if the length could
67 public long getDataLength() {
68 return FcpUtils.safeParseLong(getField("DataLength"));
72 * Returns the startup time of the request.
74 * @return The startup time of the request (in milliseconds since Jan 1,
75 * 1970 UTC), or <code>-1</code> if the time could not be parsed
77 public long getStartupTime() {
78 return FcpUtils.safeParseLong(getField("StartupTime"));
82 * Returns the completion time of the request.
84 * @return The completion time of the request (in milliseconds since Jan 1,
85 * 1970 UTC), or <code>-1</code> if the time could not be parsed
87 public long getCompletionTime() {
88 return FcpUtils.safeParseLong(getField("CompletionTime"));
92 * Returns the payload input stream. You <strong>have</strong> consume the
93 * input stream before returning from the
94 * {@link FcpListener#receivedAllData(FcpConnection, AllData)} method!
98 public InputStream getPayloadInputStream() {
99 return payloadInputStream;
103 * Returns the content type of the found file.
105 * @return The content type
107 public String getContentType() {
108 return getField("Metadata.ContentType");