3 * Copyright (C) 2006 David Roden
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.
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.
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.
20 package de.todesbaum.util.freenet.fcp2;
22 import java.io.ByteArrayInputStream;
23 import java.io.InputStream;
26 * A {@link FileEntry} that sends its payload directly to the node, using the
27 * existing FCP connection.
29 * @author David Roden <droden@gmail.com>
32 public class DirectFileEntry extends FileEntry {
34 /** The input stream to read the data for this file from. */
35 private final InputStream dataInputStream;
37 /** The length of the data. */
38 private final long dataLength;
41 * Creates a new FileEntry with the specified name and content type that
42 * gets its data from the specified byte array.
45 * The name of the file
47 * The content type of the file
49 * The content of the file
51 public DirectFileEntry(String filename, String contentType, byte[] dataBytes) {
52 this(filename, contentType, new ByteArrayInputStream(dataBytes), dataBytes.length);
56 * Creates a new FileEntry with the specified name and content type that
57 * gets its data from the specified input stream.
60 * The name of the file
62 * The content type of the file
63 * @param dataInputStream
64 * The input stream to read the content from
66 * The length of the data input stream
68 public DirectFileEntry(String filename, String contentType, InputStream dataInputStream, long dataLength) {
69 super(filename, contentType);
70 this.dataInputStream = dataInputStream;
71 this.dataLength = dataLength;
78 public String getName() {
83 * Returns the input stream for the file's content.
85 * @return The input stream for the file's content
87 public InputStream getDataInputStream() {
88 return dataInputStream;
92 * Returns the length of this file's content.
94 * @return The length of this file's content
96 public long getDataLength() {