4122 |
22 Sep 16 |
nicklas |
1 |
package net.sf.basedb.opengrid.filetransfer; |
4122 |
22 Sep 16 |
nicklas |
2 |
|
4122 |
22 Sep 16 |
nicklas |
3 |
/** |
4124 |
23 Sep 16 |
nicklas |
Abstract base implementation that is suitable when implementing |
4124 |
23 Sep 16 |
nicklas |
both file upload and download. This class provides functionality |
4124 |
23 Sep 16 |
nicklas |
that is common to both the {@link DownloadTarget} and {@link UploadSource} |
4124 |
23 Sep 16 |
nicklas |
interfaces, eg. the name and file metdata information. |
4124 |
23 Sep 16 |
nicklas |
8 |
|
4124 |
23 Sep 16 |
nicklas |
{@link DownloadTarget} implementations only need to extend this class and |
4124 |
23 Sep 16 |
nicklas |
implement the {@link DownloadTarget#getOutputStream()} method. File metadata |
4124 |
23 Sep 16 |
nicklas |
about the remote file should be available in the {@link #getMetadata()} |
4124 |
23 Sep 16 |
nicklas |
instance when the {@link DownloadTarget#getOutputStream()} method is called. |
4124 |
23 Sep 16 |
nicklas |
13 |
|
4124 |
23 Sep 16 |
nicklas |
{@link UploadSource} implementations that are extending this class |
4124 |
23 Sep 16 |
nicklas |
need to implement the {@link UploadSource#getInputStream()} method. |
4124 |
23 Sep 16 |
nicklas |
If file metadata is important the implementation should call |
4124 |
23 Sep 16 |
nicklas |
{@link #getMetadata()} and initialize the information before the |
4124 |
23 Sep 16 |
nicklas |
{@link UploadSource#getInputStream()} method is called. |
4122 |
22 Sep 16 |
nicklas |
19 |
|
4122 |
22 Sep 16 |
nicklas |
@author nicklas |
4122 |
22 Sep 16 |
nicklas |
@since 1.0 |
4122 |
22 Sep 16 |
nicklas |
22 |
*/ |
4124 |
23 Sep 16 |
nicklas |
23 |
public abstract class AbstractFileTransfer |
4122 |
22 Sep 16 |
nicklas |
24 |
{ |
4122 |
22 Sep 16 |
nicklas |
25 |
|
4122 |
22 Sep 16 |
nicklas |
26 |
private final String name; |
4124 |
23 Sep 16 |
nicklas |
27 |
private FileMetaData metadata; |
4122 |
22 Sep 16 |
nicklas |
28 |
|
4124 |
23 Sep 16 |
nicklas |
29 |
protected AbstractFileTransfer(String name) |
4122 |
22 Sep 16 |
nicklas |
30 |
{ |
4122 |
22 Sep 16 |
nicklas |
31 |
this.name = name; |
4122 |
22 Sep 16 |
nicklas |
32 |
} |
4122 |
22 Sep 16 |
nicklas |
33 |
|
4124 |
23 Sep 16 |
nicklas |
34 |
/** |
4124 |
23 Sep 16 |
nicklas |
Get the name of the file. |
4124 |
23 Sep 16 |
nicklas |
@see UploadSource#getName() |
4124 |
23 Sep 16 |
nicklas |
@see DownloadTarget#getName() |
4124 |
23 Sep 16 |
nicklas |
38 |
*/ |
4122 |
22 Sep 16 |
nicklas |
39 |
public String getName() |
4122 |
22 Sep 16 |
nicklas |
40 |
{ |
4122 |
22 Sep 16 |
nicklas |
41 |
return name; |
4122 |
22 Sep 16 |
nicklas |
42 |
} |
4122 |
22 Sep 16 |
nicklas |
43 |
|
4122 |
22 Sep 16 |
nicklas |
44 |
/** |
4124 |
23 Sep 16 |
nicklas |
Get metadata about the local file or receive metadata for |
4124 |
23 Sep 16 |
nicklas |
the remote file. |
4124 |
23 Sep 16 |
nicklas |
@see UploadSource#getMetadata() |
4124 |
23 Sep 16 |
nicklas |
@see DownloadTarget#getMetadata() |
4122 |
22 Sep 16 |
nicklas |
49 |
*/ |
4124 |
23 Sep 16 |
nicklas |
50 |
public FileMetaData getMetadata() |
4122 |
22 Sep 16 |
nicklas |
51 |
{ |
4124 |
23 Sep 16 |
nicklas |
52 |
if (metadata == null) |
4124 |
23 Sep 16 |
nicklas |
53 |
{ |
4124 |
23 Sep 16 |
nicklas |
54 |
metadata = new FileMetaData(); |
4124 |
23 Sep 16 |
nicklas |
55 |
initMetadata(metadata); |
4124 |
23 Sep 16 |
nicklas |
56 |
} |
4124 |
23 Sep 16 |
nicklas |
57 |
return metadata; |
4122 |
22 Sep 16 |
nicklas |
58 |
} |
4122 |
22 Sep 16 |
nicklas |
59 |
|
4122 |
22 Sep 16 |
nicklas |
60 |
/** |
4124 |
23 Sep 16 |
nicklas |
Subclasses that are implementing the {@link UploadSource} |
4124 |
23 Sep 16 |
nicklas |
interface should override this method and initialize the |
4124 |
23 Sep 16 |
nicklas |
metadata instance with information about the loca file. |
4124 |
23 Sep 16 |
nicklas |
64 |
|
4124 |
23 Sep 16 |
nicklas |
This method is called also for {@link DownloadTarget} |
4124 |
23 Sep 16 |
nicklas |
implementations but can typically be ignored since |
4124 |
23 Sep 16 |
nicklas |
the metadata will be overwritten with information from |
4124 |
23 Sep 16 |
nicklas |
the remote server. |
4122 |
22 Sep 16 |
nicklas |
69 |
*/ |
4124 |
23 Sep 16 |
nicklas |
70 |
protected void initMetadata(FileMetaData metadata) |
4124 |
23 Sep 16 |
nicklas |
71 |
{} |
4124 |
23 Sep 16 |
nicklas |
72 |
|
4122 |
22 Sep 16 |
nicklas |
73 |
} |