优化下载图片

master
gongzhenkun 2 years ago
parent a3226b3ebe
commit 8b019a4f44

@ -117,23 +117,20 @@ public class FileUtils
*/ */
public static void urlResourceWriteBytes(List<Map<String,Object>> filePathList, OutputStream os) throws IOException public static void urlResourceWriteBytes(List<Map<String,Object>> filePathList, OutputStream os) throws IOException
{ {
// InputStream fis = null; BufferedInputStream bufIn = null;
BufferedInputStream buf = null;
ZipEntry zipEntry = null; ZipEntry zipEntry = null;
ZipOutputStream zipOutputStream = new ZipOutputStream(os); ZipOutputStream zipOutputStream = new ZipOutputStream(os);
try try
{ {
for(Map<String,Object> filePath:filePathList){ for(Map<String,Object> filePath:filePathList){
URL file = new URL(filePath.get("urlPath").toString()); URL file = new URL(filePath.get("urlPath").toString());
// fis = file.openStream(); bufIn = new BufferedInputStream(file.openStream());
buf = new BufferedInputStream(file.openStream());
zipEntry = new ZipEntry(filePath.get("downloadPath").toString()); zipEntry = new ZipEntry(filePath.get("downloadPath").toString());
zipOutputStream.putNextEntry(zipEntry); zipOutputStream.putNextEntry(zipEntry);
byte[] b = new byte[1024]; int length = 0;
int length; while ((length = bufIn.read()) != -1)
while ((length = buf.read(b)) > 0)
{ {
zipOutputStream.write(b, 0, length); zipOutputStream.write(length);
} }
} }
} }
@ -145,8 +142,8 @@ public class FileUtils
{ {
zipOutputStream.closeEntry(); zipOutputStream.closeEntry();
IOUtils.close(zipOutputStream); IOUtils.close(zipOutputStream);
IOUtils.close(bufIn);
IOUtils.close(os); IOUtils.close(os);
IOUtils.close(buf);
} }
} }

Loading…
Cancel
Save