2 * jSite - DirectFileEntry.java - Copyright © 2006–2012 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 de.todesbaum.util.freenet.fcp2;
21 import java.io.ByteArrayInputStream;
22 import java.io.InputStream;
25 * A {@link FileEntry} that sends its payload directly to the node, using the
26 * existing FCP connection.
28 * @author David Roden <droden@gmail.com>
31 public class DirectFileEntry extends FileEntry {
33 /** The input stream to read the data for this file from. */
34 private final InputStream dataInputStream;
36 /** The length of the data. */
37 private final long dataLength;
40 * Creates a new FileEntry with the specified name and content type that
41 * gets its data from the specified byte array.
44 * The name of the file
46 * The content type of the file
48 * The content of the file
50 public DirectFileEntry(String filename, String contentType, byte[] dataBytes) {
51 this(filename, contentType, new ByteArrayInputStream(dataBytes), dataBytes.length);
55 * Creates a new FileEntry with the specified name and content type that
56 * gets its data from the specified input stream.
59 * The name of the file
61 * The content type of the file
62 * @param dataInputStream
63 * The input stream to read the content from
65 * The length of the data input stream
67 public DirectFileEntry(String filename, String contentType, InputStream dataInputStream, long dataLength) {
68 super(filename, contentType);
69 this.dataInputStream = dataInputStream;
70 this.dataLength = dataLength;
77 public String getName() {
82 * Returns the input stream for the file's content.
84 * @return The input stream for the file's content
86 public InputStream getDataInputStream() {
87 return dataInputStream;
91 * Returns the length of this file's content.
93 * @return The length of this file's content
95 public long getDataLength() {