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