public class ZipUtils
extends java.lang.Object
限定符和类型 | 字段和说明 |
---|---|
protected static org.apache.commons.logging.Log |
log |
限定符 | 构造器和说明 |
---|---|
private |
ZipUtils() |
限定符和类型 | 方法和说明 |
---|---|
static void |
compress(java.nio.file.Path sourceFilePath,
org.apache.commons.compress.archivers.ArchiveOutputStream<org.apache.commons.compress.archivers.zip.ZipArchiveEntry> out,
java.lang.String basedir) |
static void |
compressFile(java.io.File file,
org.apache.commons.compress.archivers.ArchiveOutputStream<org.apache.commons.compress.archivers.zip.ZipArchiveEntry> out,
java.lang.String fullName)
@RequestMapping("export")
public ResponseEntity<StreamingResponseBody> export() {
HttpHeaders headers = new HttpHeaders();
headers.setContentDisposition(
ContentDisposition.attachment().filename("filename.zip", Constants.DEFAULT_CHARSET).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 void |
compressFile(java.io.InputStream inputStream,
org.apache.commons.compress.archivers.ArchiveOutputStream<org.apache.commons.compress.archivers.zip.ZipArchiveEntry> out,
java.lang.String fullName) |
static void |
unzip(java.lang.String zipFilePath,
java.lang.String encoding,
boolean overwrite,
java.util.function.BiPredicate<org.apache.commons.compress.archivers.zip.ZipFile,org.apache.commons.compress.archivers.zip.ZipArchiveEntry> overwriteFunction) |
static void |
unzip(java.lang.String zipFilePath,
java.lang.String targetPath,
java.lang.String encoding,
boolean overwrite,
java.util.function.BiPredicate<org.apache.commons.compress.archivers.zip.ZipFile,org.apache.commons.compress.archivers.zip.ZipArchiveEntry> overwriteFunction) |
static void |
unzip(org.apache.commons.compress.archivers.zip.ZipFile zipFile,
java.lang.String directory,
java.lang.String targetPath,
boolean overwrite,
java.util.function.BiPredicate<org.apache.commons.compress.archivers.zip.ZipFile,org.apache.commons.compress.archivers.zip.ZipArchiveEntry> overwriteFunction) |
private static void |
unzip(org.apache.commons.compress.archivers.zip.ZipFile zipFile,
org.apache.commons.compress.archivers.zip.ZipArchiveEntry zipEntry,
java.lang.String targetPath,
java.lang.String filePath,
boolean overwrite,
java.util.function.BiPredicate<org.apache.commons.compress.archivers.zip.ZipFile,org.apache.commons.compress.archivers.zip.ZipArchiveEntry> overwriteFunction) |
static void |
unzipHere(java.lang.String zipFilePath,
java.lang.String encoding,
boolean overwrite,
java.util.function.BiPredicate<org.apache.commons.compress.archivers.zip.ZipFile,org.apache.commons.compress.archivers.zip.ZipArchiveEntry> overwriteFunction) |
static boolean |
zip(java.lang.String sourceFilePath,
java.lang.String zipFilePath) |
static boolean |
zip(java.lang.String sourceFilePath,
java.lang.String zipFilePath,
boolean overwrite) |
public static boolean zip(java.lang.String sourceFilePath, java.lang.String zipFilePath) throws java.io.IOException
sourceFilePath
- zipFilePath
- java.io.IOException
public static boolean zip(java.lang.String sourceFilePath, java.lang.String zipFilePath, boolean overwrite) throws java.io.IOException
sourceFilePath
- zipFilePath
- overwrite
- java.io.IOException
public static void compress(java.nio.file.Path sourceFilePath, org.apache.commons.compress.archivers.ArchiveOutputStream<org.apache.commons.compress.archivers.zip.ZipArchiveEntry> out, java.lang.String basedir) throws java.io.IOException
sourceFilePath
- out
- basedir
- java.io.IOException
public static void compressFile(java.io.File file, org.apache.commons.compress.archivers.ArchiveOutputStream<org.apache.commons.compress.archivers.zip.ZipArchiveEntry> out, java.lang.String fullName) throws java.io.IOException
@RequestMapping("export") public ResponseEntity<StreamingResponseBody> export() { HttpHeaders headers = new HttpHeaders(); headers.setContentDisposition( ContentDisposition.attachment().filename("filename.zip", Constants.DEFAULT_CHARSET).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
- java.io.IOException
public static void compressFile(java.io.InputStream inputStream, org.apache.commons.compress.archivers.ArchiveOutputStream<org.apache.commons.compress.archivers.zip.ZipArchiveEntry> out, java.lang.String fullName) throws java.io.IOException
java.io.IOException
public static void unzipHere(java.lang.String zipFilePath, java.lang.String encoding, boolean overwrite, java.util.function.BiPredicate<org.apache.commons.compress.archivers.zip.ZipFile,org.apache.commons.compress.archivers.zip.ZipArchiveEntry> overwriteFunction) throws java.io.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 filejava.io.IOException
public static void unzip(java.lang.String zipFilePath, java.lang.String encoding, boolean overwrite, java.util.function.BiPredicate<org.apache.commons.compress.archivers.zip.ZipFile,org.apache.commons.compress.archivers.zip.ZipArchiveEntry> overwriteFunction) throws java.io.IOException
zipFilePath
- encoding
- overwrite
- overwriteFunction
- java.io.IOException
public static void unzip(java.lang.String zipFilePath, java.lang.String targetPath, java.lang.String encoding, boolean overwrite, java.util.function.BiPredicate<org.apache.commons.compress.archivers.zip.ZipFile,org.apache.commons.compress.archivers.zip.ZipArchiveEntry> overwriteFunction) throws java.io.IOException
zipFilePath
- targetPath
- encoding
- overwrite
- overwriteFunction
- java.io.IOException
private static void unzip(org.apache.commons.compress.archivers.zip.ZipFile zipFile, org.apache.commons.compress.archivers.zip.ZipArchiveEntry zipEntry, java.lang.String targetPath, java.lang.String filePath, boolean overwrite, java.util.function.BiPredicate<org.apache.commons.compress.archivers.zip.ZipFile,org.apache.commons.compress.archivers.zip.ZipArchiveEntry> overwriteFunction)
public static void unzip(org.apache.commons.compress.archivers.zip.ZipFile zipFile, java.lang.String directory, java.lang.String targetPath, boolean overwrite, java.util.function.BiPredicate<org.apache.commons.compress.archivers.zip.ZipFile,org.apache.commons.compress.archivers.zip.ZipArchiveEntry> overwriteFunction)
zipFile
- directory
- targetPath
- overwrite
- overwriteFunction
-