| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
|
| 22 |
|
|
| 23 |
|
|
| 24 |
|
|
| 25 |
|
|
| 26 |
|
|
| 27 |
|
|
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
|
| 32 |
|
package net.sourceforge.pebble.web.view; |
| 33 |
|
|
| 34 |
|
import net.sourceforge.pebble.domain.FileMetaData; |
| 35 |
|
|
| 36 |
|
import javax.servlet.ServletContext; |
| 37 |
|
import javax.servlet.ServletException; |
| 38 |
|
import javax.servlet.http.HttpServletRequest; |
| 39 |
|
import javax.servlet.http.HttpServletResponse; |
| 40 |
|
import java.io.BufferedOutputStream; |
| 41 |
|
import java.io.FileInputStream; |
| 42 |
|
import java.io.IOException; |
| 43 |
|
import java.util.Iterator; |
| 44 |
|
import java.util.List; |
| 45 |
|
import java.util.zip.ZipEntry; |
| 46 |
|
import java.util.zip.ZipOutputStream; |
| 47 |
|
|
| 48 |
|
|
| 49 |
|
|
| 50 |
|
|
| 51 |
|
@author |
| 52 |
|
|
|
|
|
| 0% |
Uncovered Elements: 32 (32) |
Complexity: 8 |
Complexity Density: 0,36 |
|
| 53 |
|
public class ZipView extends BinaryView { |
| 54 |
|
|
| 55 |
|
private List files; |
| 56 |
|
private String filename; |
| 57 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
| 58 |
0
|
public ZipView(List files, String filename) {... |
| 59 |
0
|
this.files = files; |
| 60 |
0
|
this.filename = filename; |
| 61 |
|
} |
| 62 |
|
|
| 63 |
|
|
| 64 |
|
|
| 65 |
|
|
| 66 |
|
@return |
| 67 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 68 |
0
|
public String getContentType() {... |
| 69 |
0
|
return "application/zip"; |
| 70 |
|
} |
| 71 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 72 |
0
|
public long getContentLength() {... |
| 73 |
0
|
return 0; |
| 74 |
|
} |
| 75 |
|
|
| 76 |
|
|
| 77 |
|
|
| 78 |
|
|
| 79 |
|
@param |
| 80 |
|
@param |
| 81 |
|
@param |
| 82 |
|
|
|
|
|
| 0% |
Uncovered Elements: 24 (24) |
Complexity: 5 |
Complexity Density: 0,28 |
|
| 83 |
0
|
public void dispatch(HttpServletRequest request, HttpServletResponse response, ServletContext context) throws ServletException {... |
| 84 |
0
|
try { |
| 85 |
0
|
response.setHeader("Content-Disposition", "filename=" + filename); |
| 86 |
0
|
byte[] buf = new byte[1024]; |
| 87 |
0
|
ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(response.getOutputStream())); |
| 88 |
0
|
Iterator it = files.iterator(); |
| 89 |
0
|
while (it.hasNext()) { |
| 90 |
0
|
FileMetaData file = (FileMetaData)it.next(); |
| 91 |
0
|
if (file.isDirectory()) { |
| 92 |
0
|
continue; |
| 93 |
|
} |
| 94 |
|
|
| 95 |
0
|
FileInputStream in = new FileInputStream(file.getFile()); |
| 96 |
0
|
out.putNextEntry(new ZipEntry(file.getAbsolutePath().substring(1))); |
| 97 |
0
|
int len; |
| 98 |
0
|
while ((len = in.read(buf)) > 0) { |
| 99 |
0
|
out.write(buf, 0, len); |
| 100 |
|
} |
| 101 |
0
|
out.closeEntry(); |
| 102 |
0
|
in.close(); |
| 103 |
|
} |
| 104 |
|
|
| 105 |
0
|
out.close(); |
| 106 |
|
} catch (IOException ioe) { |
| 107 |
0
|
throw new ServletException(ioe); |
| 108 |
|
} |
| 109 |
|
} |
| 110 |
|
|
| 111 |
|
} |