|
@@ -34,6 +34,20 @@ public class ZipUtil {
|
34
|
34
|
return LocalDateTime.now(ZoneId.of("Asia/Shanghai")).format(formatter);
|
35
|
35
|
}
|
36
|
36
|
|
|
37
|
+ private void zipStream(List<RFile> files, OutputStream outputStream) throws IOException {
|
|
38
|
+ ZipOutputStream zos = new ZipOutputStream(outputStream);
|
|
39
|
+ ZipParameters zipParameters = new ZipParameters();
|
|
40
|
+
|
|
41
|
+ for (RFile f : files) {
|
|
42
|
+ zipParameters.setFileNameInZip(f.getName());
|
|
43
|
+ zos.putNextEntry(zipParameters);
|
|
44
|
+ byte[] data = httpUtils.download(f.getUrl());
|
|
45
|
+ zos.write(data);
|
|
46
|
+ zos.closeEntry();
|
|
47
|
+ }
|
|
48
|
+ zos.close();
|
|
49
|
+ }
|
|
50
|
+
|
37
|
51
|
public void flush(HttpServletResponse response, List<RFile> files) throws IOException {
|
38
|
52
|
try {
|
39
|
53
|
if (files == null || files.size() < 1) {
|
|
@@ -44,18 +58,7 @@ public class ZipUtil {
|
44
|
58
|
response.setContentType("application/zip");
|
45
|
59
|
response.setCharacterEncoding("utf-8");
|
46
|
60
|
response.setHeader("Content-disposition", "attachment;filename="+StringUtils.urlEncode(fileName));
|
47
|
|
-
|
48
|
|
- ZipOutputStream zos = new ZipOutputStream(response.getOutputStream());
|
49
|
|
- ZipParameters zipParameters = new ZipParameters();
|
50
|
|
-
|
51
|
|
- for (RFile f : files) {
|
52
|
|
- zipParameters.setFileNameInZip(f.getName());
|
53
|
|
- zos.putNextEntry(zipParameters);
|
54
|
|
- byte[] data = httpUtils.download(f.getUrl());
|
55
|
|
- zos.write(data);
|
56
|
|
- zos.closeEntry();
|
57
|
|
- }
|
58
|
|
- zos.close();
|
|
61
|
+ zipStream(files, response.getOutputStream());
|
59
|
62
|
response.flushBuffer();
|
60
|
63
|
} catch (Exception e) {
|
61
|
64
|
e.printStackTrace();
|