package com.;
import java.io.file;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URLEncoder;
import java.u;
import java.u;
import java.u;
import javax.;
import javax.;
import org.a;
import org.a;
import org.;
import org.Factory;
public class DownloadUtil {
private static Logger logger = LoggerFac);
/**
* 页面传压缩的多个文件
* @param pdfs 文件列表
* @param response
* @throws IOException
*/
public static void exportZIP(List<File> pdfs, String zipFileName, HttpServletResponse response) throws IOException {
if(null == pdfs || 0 == ())
return;
ServletOutputStream os = null;
ZipOutputStream zipOS = null;
try {
os = getOutputStream(zipFileName, response);
zipOS = new ZipOutputStream(os);
for (File file : pdfs) {// 将pdf文件发送到客户端
ZipEntry entry = new ZipEntry());
zi(entry);
try(FileInputStream fis = new FileInputStream(file)){
IOU(fis, zipOS);
}
}
zi();
} catch (Exception e) {
logger.error(), e);
} finally {
if (null != zipOS)
zi();
if (null != os)
os.close();
}
}
/**
* 打开response输出流
* @param string
* @param response
* @return
* @throws IOException
*/
public static ServletOutputStream getOutputStream(String fileName, HttpServletResponse response) throws IOException {
re("Content-Disposition",
S("attachment;filename=", URLEncoder.encode(fileName, "UTF-8")));
re("Connection", "close");
re("Content-Type", "application/octet-stream");
return re();
}
}