www.dextsolution.com
DEXTUPLOAD
NJ
menu toggleReference > devpia > dextuploadnj > CompressUtil

devpia.dextuploadnj
Class CompressUtil

Minimum version supported
1.3.0
Minimum support environment
JRE 1.6
Description

The CompressUtil class has a function of compressing files and directories.

List<File> files = new ArrayList<File>();
files.add(new File("/src/test/resources/compress/....txt"));
files.add(new File("/src/test/resources/compress/....pdf"));
files.add(new File("/src/test/resources/compress/subA/subB/....txt"));
files.add(new File("/src/test/resources/compress/....jpg"));
files.add(new File("/src/test/resources/compress/....docx"));
		
CompressUtil zipper = new CompressUtil();
File zip = zipper.zip(files, new File("/tmp"), "UTF-8", false, true);

You can specify a directory instead of a file list.

CompressUtil zipper = new CompressUtil();
File zip = zipper.zip(new File("/src/test/resources/compress/"), true, new File("/tmp"), "UTF-8", false, true);

The CompressUtil class does not use the java.util.zip package to compress files or a directory, but uses the Apache Commons Compress™ library. Although DEXTUploadNJ runs under the JRE 1.6 environment, the java.util.zip has a problem that it cannot handle filenames with 1.6-based multilingual names. Therefore, to use the zip compression function, refer to the Apache Commons Compress™ library (commons-compress-{version}.jar) and do it. (Apache Commons Compress™ supports up to version 1.12 in 1.6 environment.)

For details, please refer to https://commons.apache.org/proper/commons-compress/.

Constructor

CompressUtil

  • Create an object of the CompressUtil class.

  • Signatures

    public CompressUtil()
Methods

zip

  • Compresses the specified file or directory and returns it in one zip file.

  • Signatures

    public File zip(List<File> targets, File tempZipDir, String zipCharsetName, boolean includeHiddenFile, boolean persist)
    public File zip(List<File> targets, List<String> names, List File tempZipDir, String zipCharsetName, boolean includeHiddenFile, boolean persist)
    public File zip(File targetDir, boolean includeTargetDirName, File tempZipDir, String zipCharsetName, boolean includeHiddenFile, boolean persist)
  • Parameters

    Name Type Description
    targets java.util.List<java.io.File> It is an object that points to a list of files to be compressed.
    targetDir java.io.File It is an object that points to a directory to be compressed.
    includeTargetDirName boolean

    Sets whether to include the root directory when compressing directories.

    When the value of the parameter is true, compression including the target directory is performed, and when it is false, only files or the sub-directories are compressed.

    tempZipDir java.io.File

    It is an object that points to the temporary directory where the zip file is created.

    If null, the operating system determines the location of the temporary directory.

    zipCharsetName java.lang.String

    Set the name of the character set used in the process of encoding file name including multilingual.

    Generally set to "UTF-8", if null, use the default character set.

    includeHiddenFile boolean

    When compressing, set whether to compress hidden files.

    persist boolean

    Set compressed file maintenance condition.

    When setting the value of the parameter to false, when the virtual machine exit, the generated compressed file is deleted. Conversely, if true, maintain the file regardless of whether to exit the machine.

    names java.util.List<java.lang.String>

    (Supported since version 2.4.0)

    A list of names of files to be compressed, the size of the 'names' parameter is equal to the size of the 'targets' parameter.

  • Returns

    Returns a java.io.File object pointing to the compressed file.