4123 |
22 Sep 16 |
nicklas |
1 |
package net.sf.basedb.opengrid.filetransfer; |
4123 |
22 Sep 16 |
nicklas |
2 |
|
4123 |
22 Sep 16 |
nicklas |
3 |
import java.io.IOException; |
4123 |
22 Sep 16 |
nicklas |
4 |
import java.io.OutputStream; |
4123 |
22 Sep 16 |
nicklas |
5 |
|
4123 |
22 Sep 16 |
nicklas |
6 |
import javax.servlet.http.HttpServletResponse; |
4123 |
22 Sep 16 |
nicklas |
7 |
|
4123 |
22 Sep 16 |
nicklas |
8 |
|
4123 |
22 Sep 16 |
nicklas |
9 |
/** |
4123 |
22 Sep 16 |
nicklas |
Download target implementation that forwards the downloaded remote |
4123 |
22 Sep 16 |
nicklas |
file to the servlet response output stream. With this we can 'pipe' the |
4123 |
22 Sep 16 |
nicklas |
file data directly over the web to the clients computer without |
4123 |
22 Sep 16 |
nicklas |
storing it locally. |
4123 |
22 Sep 16 |
nicklas |
14 |
|
4123 |
22 Sep 16 |
nicklas |
@author nicklas |
4123 |
22 Sep 16 |
nicklas |
@since 1.0 |
4123 |
22 Sep 16 |
nicklas |
17 |
*/ |
4123 |
22 Sep 16 |
nicklas |
18 |
public class ServletResponseDownloadTarget |
4124 |
23 Sep 16 |
nicklas |
19 |
extends AbstractFileTransfer |
4124 |
23 Sep 16 |
nicklas |
20 |
implements DownloadTarget |
4123 |
22 Sep 16 |
nicklas |
21 |
{ |
4123 |
22 Sep 16 |
nicklas |
22 |
|
4123 |
22 Sep 16 |
nicklas |
23 |
private final HttpServletResponse resp; |
4123 |
22 Sep 16 |
nicklas |
24 |
private OutputStream out; |
4123 |
22 Sep 16 |
nicklas |
25 |
|
4123 |
22 Sep 16 |
nicklas |
26 |
public ServletResponseDownloadTarget(HttpServletResponse resp, String name) |
4123 |
22 Sep 16 |
nicklas |
27 |
{ |
4123 |
22 Sep 16 |
nicklas |
28 |
super(name); |
4123 |
22 Sep 16 |
nicklas |
29 |
this.resp = resp; |
4123 |
22 Sep 16 |
nicklas |
30 |
} |
4123 |
22 Sep 16 |
nicklas |
31 |
|
4123 |
22 Sep 16 |
nicklas |
32 |
@Override |
4123 |
22 Sep 16 |
nicklas |
33 |
public OutputStream getOutputStream() |
4123 |
22 Sep 16 |
nicklas |
34 |
throws IOException |
4123 |
22 Sep 16 |
nicklas |
35 |
{ |
4124 |
23 Sep 16 |
nicklas |
36 |
if (out == null) |
4124 |
23 Sep 16 |
nicklas |
37 |
{ |
4124 |
23 Sep 16 |
nicklas |
38 |
FileMetaData metadata = getMetadata(); |
4124 |
23 Sep 16 |
nicklas |
39 |
if (metadata != null) |
4124 |
23 Sep 16 |
nicklas |
40 |
{ |
4124 |
23 Sep 16 |
nicklas |
41 |
resp.setContentLengthLong(metadata.getSize()); |
4124 |
23 Sep 16 |
nicklas |
42 |
resp.setDateHeader("Last-Modified", metadata.getLastModifiedTime()); |
4124 |
23 Sep 16 |
nicklas |
43 |
} |
4124 |
23 Sep 16 |
nicklas |
44 |
out = resp.getOutputStream(); |
4124 |
23 Sep 16 |
nicklas |
45 |
} |
4123 |
22 Sep 16 |
nicklas |
46 |
return out; |
4123 |
22 Sep 16 |
nicklas |
47 |
} |
4123 |
22 Sep 16 |
nicklas |
48 |
|
4123 |
22 Sep 16 |
nicklas |
49 |
} |