1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.sys.util;
17
18 import java.io.ByteArrayOutputStream;
19 import java.io.IOException;
20 import java.util.Iterator;
21 import java.util.Map;
22 import java.util.zip.ZipEntry;
23 import java.util.zip.ZipOutputStream;
24
25 import javax.servlet.http.HttpServletResponse;
26
27 public class KfsWebUtils {
28
29
30
31
32
33
34
35
36
37
38 public static void saveMimeZipOutputStreamAsFile(HttpServletResponse response, String contentType, Map<String, ByteArrayOutputStream> outputStreamMap, String zipFileName) throws IOException {
39
40
41 response.setContentType(contentType);
42 response.setHeader("Content-disposition", "attachment; filename=" + zipFileName);
43 response.setHeader("Expires", "0");
44 response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
45 response.setHeader("Pragma", "public");
46
47
48 ZipOutputStream zout = new ZipOutputStream(response.getOutputStream());
49 int totalSize = 0;
50 Iterator<String> fileNames = outputStreamMap.keySet().iterator();
51 while (fileNames.hasNext()) {
52 String fileName = fileNames.next();
53 ByteArrayOutputStream pdfStream = outputStreamMap.get(fileName);
54 totalSize += pdfStream.size();
55 zout.putNextEntry(new ZipEntry(fileName));
56 zout.write(pdfStream.toByteArray());
57 zout.closeEntry();
58 }
59 response.setContentLength(totalSize);
60 zout.flush();
61 zout.close();
62 }
63
64 }