jSite: First commit : verion 4.0 (written by Bombe)
[jSite.git] / src / de / todesbaum / util / freenet / fcp2 / DirectFileEntry.java
1 /*
2  * todesbaum-lib - 
3  * Copyright (C) 2006 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 de.todesbaum.util.freenet.fcp2;
21
22 import java.io.ByteArrayInputStream;
23 import java.io.InputStream;
24
25 /**
26  * A {@link FileEntry} that sends its payload directly to the node, using the
27  * existing FCP connection.
28  * 
29  * @author David Roden <droden@gmail.com>
30  * @version $Id: DirectFileEntry.java 413 2006-03-29 12:22:31Z bombe $
31  */
32 public class DirectFileEntry extends FileEntry {
33
34         /** The input stream to read the data for this file from. */
35         private final InputStream dataInputStream;
36
37         /** The length of the data. */
38         private final long dataLength;
39
40         /**
41          * Creates a new FileEntry with the specified name and content type that
42          * gets its data from the specified byte array.
43          * 
44          * @param filename
45          *            The name of the file
46          * @param contentType
47          *            The content type of the file
48          * @param dataBytes
49          *            The content of the file
50          */
51         public DirectFileEntry(String filename, String contentType, byte[] dataBytes) {
52                 this(filename, contentType, new ByteArrayInputStream(dataBytes), dataBytes.length);
53         }
54
55         /**
56          * Creates a new FileEntry with the specified name and content type that
57          * gets its data from the specified input stream.
58          * 
59          * @param filename
60          *            The name of the file
61          * @param contentType
62          *            The content type of the file
63          * @param dataInputStream
64          *            The input stream to read the content from
65          * @param dataLength
66          *            The length of the data input stream
67          */
68         public DirectFileEntry(String filename, String contentType, InputStream dataInputStream, long dataLength) {
69                 super(filename, contentType);
70                 this.dataInputStream = dataInputStream;
71                 this.dataLength = dataLength;
72         }
73
74         /**
75          * {@inheritDoc}
76          */
77         @Override
78         public String getName() {
79                 return "direct";
80         }
81
82         /**
83          * Returns the input stream for the file's content.
84          * 
85          * @return The input stream for the file's content
86          */
87         public InputStream getDataInputStream() {
88                 return dataInputStream;
89         }
90
91         /**
92          * Returns the length of this file's content.
93          * 
94          * @return The length of this file's content
95          */
96         public long getDataLength() {
97                 return dataLength;
98         }
99
100 }