|
@@ -151,20 +151,24 @@ public class OSSFileService {
|
|
|
ZipOutputStream zos = new ZipOutputStream(csum);
|
|
ZipOutputStream zos = new ZipOutputStream(csum);
|
|
|
|
|
|
|
|
for (String ossfile : keyList) {
|
|
for (String ossfile : keyList) {
|
|
|
- // 获取Object,返回结果为OSSObject对象
|
|
|
|
|
- OSSObject ossObject = ossClient.getObject(bucketName, ossfile);
|
|
|
|
|
- // 读去Object内容 返回
|
|
|
|
|
- InputStream inputStream = ossObject.getObjectContent();
|
|
|
|
|
- // 对于每一个要被存放到压缩包的文件,都必须调用ZipOutputStream对象的putNextEntry()方法,确保压缩包里面文件不同名
|
|
|
|
|
-
|
|
|
|
|
- zos.putNextEntry(new ZipEntry(ossfile.split("/")[ossfile.split("/").length - 1]));
|
|
|
|
|
- int bytesRead = 0;
|
|
|
|
|
- // 向压缩文件中输出数据
|
|
|
|
|
- while ((bytesRead = inputStream.read()) != -1) {
|
|
|
|
|
- zos.write(bytesRead);
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 获取Object,返回结果为OSSObject对象
|
|
|
|
|
+ OSSObject ossObject = ossClient.getObject(bucketName, ossfile);
|
|
|
|
|
+ // 读去Object内容 返回
|
|
|
|
|
+ InputStream inputStream = ossObject.getObjectContent();
|
|
|
|
|
+ // 对于每一个要被存放到压缩包的文件,都必须调用ZipOutputStream对象的putNextEntry()方法,确保压缩包里面文件不同名
|
|
|
|
|
+
|
|
|
|
|
+ zos.putNextEntry(new ZipEntry(ossfile.split("/")[ossfile.split("/").length - 1]));
|
|
|
|
|
+ int bytesRead = 0;
|
|
|
|
|
+ // 向压缩文件中输出数据
|
|
|
|
|
+ while ((bytesRead = inputStream.read()) != -1) {
|
|
|
|
|
+ zos.write(bytesRead);
|
|
|
|
|
+ }
|
|
|
|
|
+ inputStream.close();
|
|
|
|
|
+ zos.closeEntry(); // 当前文件写完,定位为写入下一条项目
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ logger.error("ossfile, 压缩失败", e);
|
|
|
}
|
|
}
|
|
|
- inputStream.close();
|
|
|
|
|
- zos.closeEntry(); // 当前文件写完,定位为写入下一条项目
|
|
|
|
|
}
|
|
}
|
|
|
zos.close();
|
|
zos.close();
|
|
|
String header = request.getHeader("User-Agent").toUpperCase();
|
|
String header = request.getHeader("User-Agent").toUpperCase();
|
|
@@ -200,7 +204,7 @@ public class OSSFileService {
|
|
|
// 删除临时文件
|
|
// 删除临时文件
|
|
|
zipFile.delete();
|
|
zipFile.delete();
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
- logger.error(e);
|
|
|
|
|
|
|
+ logger.error("压缩失败", e);
|
|
|
}
|
|
}
|
|
|
return response;
|
|
return response;
|
|
|
}
|
|
}
|
|
@@ -265,7 +269,7 @@ public class OSSFileService {
|
|
|
|
|
|
|
|
ossClient.shutdown();
|
|
ossClient.shutdown();
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
- logger.error(e);
|
|
|
|
|
|
|
+ logger.error("下载图片失败", e);
|
|
|
}
|
|
}
|
|
|
return response;
|
|
return response;
|
|
|
}
|
|
}
|