4121 |
22 Sep 16 |
nicklas |
1 |
package net.sf.basedb.opengrid.filetransfer; |
4121 |
22 Sep 16 |
nicklas |
2 |
|
4121 |
22 Sep 16 |
nicklas |
3 |
import java.io.ByteArrayInputStream; |
4121 |
22 Sep 16 |
nicklas |
4 |
import java.io.InputStream; |
4121 |
22 Sep 16 |
nicklas |
5 |
|
4121 |
22 Sep 16 |
nicklas |
6 |
|
4121 |
22 Sep 16 |
nicklas |
7 |
/** |
4121 |
22 Sep 16 |
nicklas |
Upload source implementation for uploading the contents |
4121 |
22 Sep 16 |
nicklas |
of a string to a file on a remote server. |
4121 |
22 Sep 16 |
nicklas |
10 |
|
4121 |
22 Sep 16 |
nicklas |
@author nicklas |
4121 |
22 Sep 16 |
nicklas |
@since 1.0 |
4121 |
22 Sep 16 |
nicklas |
13 |
*/ |
4121 |
22 Sep 16 |
nicklas |
14 |
public class ByteArrayUploadSource |
4124 |
23 Sep 16 |
nicklas |
15 |
extends AbstractFileTransfer |
4121 |
22 Sep 16 |
nicklas |
16 |
implements UploadSource |
4121 |
22 Sep 16 |
nicklas |
17 |
{ |
4121 |
22 Sep 16 |
nicklas |
18 |
|
4121 |
22 Sep 16 |
nicklas |
19 |
private final byte[] data; |
4121 |
22 Sep 16 |
nicklas |
20 |
|
4121 |
22 Sep 16 |
nicklas |
21 |
/** |
4121 |
22 Sep 16 |
nicklas |
Create a new source file from a byte[]. |
4121 |
22 Sep 16 |
nicklas |
23 |
|
4121 |
22 Sep 16 |
nicklas |
@param name The name of the "file" |
4121 |
22 Sep 16 |
nicklas |
@param data The contents of the file |
4121 |
22 Sep 16 |
nicklas |
26 |
*/ |
4121 |
22 Sep 16 |
nicklas |
27 |
public ByteArrayUploadSource(String name, byte[] data) |
4121 |
22 Sep 16 |
nicklas |
28 |
{ |
4124 |
23 Sep 16 |
nicklas |
29 |
super(name); |
4121 |
22 Sep 16 |
nicklas |
30 |
this.data = data; |
4121 |
22 Sep 16 |
nicklas |
31 |
} |
4121 |
22 Sep 16 |
nicklas |
32 |
|
4121 |
22 Sep 16 |
nicklas |
33 |
@Override |
4124 |
23 Sep 16 |
nicklas |
34 |
protected void initMetadata(FileMetaData metadata) |
4121 |
22 Sep 16 |
nicklas |
35 |
{ |
4124 |
23 Sep 16 |
nicklas |
36 |
long time = System.currentTimeMillis(); |
4124 |
23 Sep 16 |
nicklas |
37 |
metadata.setLastModifiedTime(time); |
4124 |
23 Sep 16 |
nicklas |
38 |
metadata.setLastModifiedTime(time); |
4124 |
23 Sep 16 |
nicklas |
39 |
metadata.setSize(data.length); |
4121 |
22 Sep 16 |
nicklas |
40 |
} |
4124 |
23 Sep 16 |
nicklas |
41 |
|
4121 |
22 Sep 16 |
nicklas |
42 |
/** |
4121 |
22 Sep 16 |
nicklas |
Get the file data. |
4121 |
22 Sep 16 |
nicklas |
44 |
*/ |
4121 |
22 Sep 16 |
nicklas |
45 |
@Override |
4121 |
22 Sep 16 |
nicklas |
46 |
public InputStream getInputStream() |
4121 |
22 Sep 16 |
nicklas |
47 |
{ |
4121 |
22 Sep 16 |
nicklas |
48 |
return new ByteArrayInputStream(data); |
4121 |
22 Sep 16 |
nicklas |
49 |
} |
4121 |
22 Sep 16 |
nicklas |
50 |
|
4121 |
22 Sep 16 |
nicklas |
51 |
} |