类 ZipUtils
java.lang.Object
com.publiccms.common.tools.ZipUtils
压缩/解压缩zip包处理类
ZipUtils
-
字段概要
字段 -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明static voidcompress(Path sourceFilePath, org.apache.commons.compress.archivers.ArchiveOutputStream<org.apache.commons.compress.archivers.zip.ZipArchiveEntry> out, String basedir) static voidcompressFile(File file, org.apache.commons.compress.archivers.ArchiveOutputStream<org.apache.commons.compress.archivers.zip.ZipArchiveEntry> out, String fullName) @RequestMapping("export") public ResponseEntity<StreamingResponseBody> export() { HttpHeaders headers = new HttpHeaders(); headers.setContentDisposition( ContentDisposition.attachment().filename("filename.zip", StandardCharsets.UTF_8).build()); StreamingResponseBody body = new StreamingResponseBody() { @Override public void writeTo(OutputStream outputStream) throws IOException { try (ArchiveOutputStream zipOutputStream = new ZipArchiveOutputStream(outputStream)) { ZipUtils.compressFile(new File("filename.txt"), zipOutputStream, "dir/filename.txt"); } } }; return ResponseEntity.ok().headers(headers).body(body); }static voidcompressFile(InputStream inputStream, org.apache.commons.compress.archivers.ArchiveOutputStream<org.apache.commons.compress.archivers.zip.ZipArchiveEntry> out, String fullName) static voidunzip(String zipFilePath, String encoding, boolean overwrite, BiPredicate<org.apache.commons.compress.archivers.zip.ZipFile, org.apache.commons.compress.archivers.zip.ZipArchiveEntry> overwriteFunction) static voidunzip(String zipFilePath, String targetPath, String encoding, boolean overwrite, BiPredicate<org.apache.commons.compress.archivers.zip.ZipFile, org.apache.commons.compress.archivers.zip.ZipArchiveEntry> overwriteFunction) static voidunzip(org.apache.commons.compress.archivers.zip.ZipFile zipFile, String directory, String targetPath, boolean overwrite, BiPredicate<org.apache.commons.compress.archivers.zip.ZipFile, org.apache.commons.compress.archivers.zip.ZipArchiveEntry> overwriteFunction) private static voidunzip(org.apache.commons.compress.archivers.zip.ZipFile zipFile, org.apache.commons.compress.archivers.zip.ZipArchiveEntry zipEntry, String targetPath, String filePath, boolean overwrite, BiPredicate<org.apache.commons.compress.archivers.zip.ZipFile, org.apache.commons.compress.archivers.zip.ZipArchiveEntry> overwriteFunction) static voidunzipHere(String zipFilePath, String encoding, boolean overwrite, BiPredicate<org.apache.commons.compress.archivers.zip.ZipFile, org.apache.commons.compress.archivers.zip.ZipArchiveEntry> overwriteFunction) static booleanstatic boolean
-
字段详细资料
-
log
protected static final org.apache.commons.logging.Log log
-
-
构造器详细资料
-
ZipUtils
private ZipUtils()
-
-
方法详细资料
-
zip
- 参数:
sourceFilePath-zipFilePath-- 返回:
- whether the compression is successful
- 抛出:
IOException
-
zip
public static boolean zip(String sourceFilePath, String zipFilePath, boolean overwrite) throws IOException - 参数:
sourceFilePath-zipFilePath-overwrite-- 返回:
- whether the compression is successful
- 抛出:
IOException
-
compress
public static void compress(Path sourceFilePath, org.apache.commons.compress.archivers.ArchiveOutputStream<org.apache.commons.compress.archivers.zip.ZipArchiveEntry> out, String basedir) throws IOException - 参数:
sourceFilePath-out-basedir-- 抛出:
IOException
-
compressFile
public static void compressFile(File file, org.apache.commons.compress.archivers.ArchiveOutputStream<org.apache.commons.compress.archivers.zip.ZipArchiveEntry> out, String fullName) throws IOException @RequestMapping("export") public ResponseEntity<StreamingResponseBody> export() { HttpHeaders headers = new HttpHeaders(); headers.setContentDisposition( ContentDisposition.attachment().filename("filename.zip", StandardCharsets.UTF_8).build()); StreamingResponseBody body = new StreamingResponseBody() { @Override public void writeTo(OutputStream outputStream) throws IOException { try (ArchiveOutputStream zipOutputStream = new ZipArchiveOutputStream(outputStream)) { ZipUtils.compressFile(new File("filename.txt"), zipOutputStream, "dir/filename.txt"); } } }; return ResponseEntity.ok().headers(headers).body(body); }- 参数:
file-out-fullName-- 抛出:
IOException
-
compressFile
public static void compressFile(InputStream inputStream, org.apache.commons.compress.archivers.ArchiveOutputStream<org.apache.commons.compress.archivers.zip.ZipArchiveEntry> out, String fullName) throws IOException - 抛出:
IOException
-
unzipHere
public static void unzipHere(String zipFilePath, String encoding, boolean overwrite, BiPredicate<org.apache.commons.compress.archivers.zip.ZipFile, org.apache.commons.compress.archivers.zip.ZipArchiveEntry> overwriteFunction) throws IOException- 参数:
zipFilePath-encoding-overwrite- if true then overwrite the fileoverwriteFunction- if overwrite is true and this function return true or this function is null then overwrite the file- 抛出:
IOException
-
unzip
public static void unzip(String zipFilePath, String encoding, boolean overwrite, BiPredicate<org.apache.commons.compress.archivers.zip.ZipFile, org.apache.commons.compress.archivers.zip.ZipArchiveEntry> overwriteFunction) throws IOException- 参数:
zipFilePath-encoding-overwrite-overwriteFunction-- 抛出:
IOException
-
unzip
public static void unzip(String zipFilePath, String targetPath, String encoding, boolean overwrite, BiPredicate<org.apache.commons.compress.archivers.zip.ZipFile, org.apache.commons.compress.archivers.zip.ZipArchiveEntry> overwriteFunction) throws IOException- 参数:
zipFilePath-targetPath-encoding-overwrite-overwriteFunction-- 抛出:
IOException
-
unzip
private static void unzip(org.apache.commons.compress.archivers.zip.ZipFile zipFile, org.apache.commons.compress.archivers.zip.ZipArchiveEntry zipEntry, String targetPath, String filePath, boolean overwrite, BiPredicate<org.apache.commons.compress.archivers.zip.ZipFile, org.apache.commons.compress.archivers.zip.ZipArchiveEntry> overwriteFunction) -
unzip
public static void unzip(org.apache.commons.compress.archivers.zip.ZipFile zipFile, String directory, String targetPath, boolean overwrite, BiPredicate<org.apache.commons.compress.archivers.zip.ZipFile, org.apache.commons.compress.archivers.zip.ZipArchiveEntry> overwriteFunction) - 参数:
zipFile-directory-targetPath-overwrite-overwriteFunction-
-