www.dextsolution.com
DEXTUPLOAD
JK
menu toggleReference > dextuploadjk > support > spring > JKDirectoryToZipDownloadView

dextuploadjk.support.spring
Class JKDirectoryToZipDownloadView

Minimum version
1.0.0
Minimum environment
Java 17, Spring Framework 6.0.14, Spring Boot 3.0.12
Description

A View class that packs a given directory into a single zip file and performs the download.

@RequestMapping(value = "download-zip", method = RequestMethod.GET)
public ModelAndView downloadZip(...) {
    String targetDirPath = new File("/src/test/resources/compress/").getAbsolutePath();
			
    JKDirectoryToZipDownloadView view = new JKDirectoryToZipDownloadView();
			
    view.setTargetDirPath(targetDirPath);
    view.setIncludeTargetDirName(true);
    view.setCharsetName("UTF-8");
			
    return new ModelAndView(view);
}

JKDirectoryToZipDownloadView compresses the target directory and then performs the download.

It removes the compressed file internally as soon as the download is complete, and compressed downloads do not support partial content downloads.

If you want to reuse the compressed file without deleting it, you should use the CompressUtil class directly (not the JKDirectoryToZipDownloadView view class) to create the compressed file and then use the JKFileDownloadView class to download it.

@RequestMapping(value = "download-zip", method = RequestMethod.GET)
public ModelAndView downloadZip(...) {

    // Manually create a compressed file using CompressUtil.
    CompressUtil zipper = new CompressUtil();
    File zipped = zipper.zip("/src/test/resources/compress/", true, "/tmp", "UTF-8", false, true);
		
    // Create a JKFileDownloadView object to download the file.
    JKFileDownloadView view = new JKFileDownloadView();
    
    view.setFile(zipped);
    view.setFilename("directory.zip");
    view.setMime("application/x-zip-compressed");
    view.setUseClientCache(false);
    view.setCharsetName("UTF-8");

    return new ModelAndView(view);
}
Constructor

JKDirectoryToZipDownloadView

  • Create an object of class JKDirectoryToZipDownloadView.

  • Signatures

    public JKDirectoryToZipDownloadView()
    public JKDirectoryToZipDownloadView(String targetDirPath)
    public JKDirectoryToZipDownloadView(String targetDirPath, String filename)
    
  • Parameters

    Name Type Description
    targetDirPath java.lang.String A path pointing to the directory to zip
    filename java.lang.String The filename to be downloaded by the client
Methods

getTargetDirPath

  • Returns the path to the directory to be compressed.

  • Signatures

    public String getTargetDirPath()
  • Return

    A path to the directory to be compressed

setTargetDirPath

  • Set a java.util.List object pointing to the list of files to compress.

  • Signatures

    public void setTargetDirPath(String targetDirPath)
  • Parameters

    Name Type Description
    targetDirPath java.lang.String A path to the directory to be compressed

isIncludeTargetDirName

  • Returns whether to include the root directory when compressing.

  • Signatures

    public boolean isIncludeTargetDirName()
  • Return

    Whether to include the root directory when compressing

setIncludeTargetDirName

  • Sets whether to include the root directory when compressing.

  • Signatures

    public void setIncludeTargetDirName(boolean includeTargetDirName)
  • Parameters

    Name Type Description
    includeTargetDirName boolean If the parameter value is true, compresses up to the destination directory.

getTempZipRepositoryPath

  • Returns a path indicating the temporary directory where the zip file will be created.

  • Signatures

    public String getTempZipRepositoryPath()
  • Return

    Path to the temporary directory where the zip file will be created

setTempZipRepositoryPath

  • Sets the path to the temporary directory where the zip file will be created.

  • Signatures

    public void setTempZipRepositoryPath(String tempZipRepositoryPath)
  • Parameters

    Name Type Description
    tempZipRepositoryPath java.lang.String Path to temporary directory

getZipCharsetName

  • Returns the charset name to use when encoding multilingual filenames.

  • Signatures

    public String getZipCharsetName()
  • Return

    Charset name to use when encoding multilingual filenames

setZipCharsetName

  • Sets the charset name to use when encoding multilingual filenames.

  • Signatures

    public void setZipCharsetName(String zipCharsetName)
  • Parameters

    Name Type Description
    zipCharsetName java.lang.String Charset name to use when encoding multilingual filenames

isIncludeHiddenFile

  • Returns whether to compress hidden files when compressing.

  • Signatures

    public boolean isIncludeHiddenFile()
  • Return

    true or false

setIncludeHiddenFile

  • Sets whether to compress hidden files when compressing.

  • Signatures

    public void setIncludeHiddenFile(boolean includeHiddenFile)
  • Parameters

    Name Type Description
    includeHiddenFile boolean If the parameter value is true, hidden files will be compressed.

getFile

See the getFile method of class JKFileDownloadView.

setFile

See the setFile method of class JKFileDownloadView.

isAllowingWeakRange

See the isAllowingWeakRange method of class JKFileDownloadView.

setAllowingWeakRange

See the setAllowingWeakRange method of the JKFileDownloadView class.

isUseClientCache

See the isUseClientCache method of the JKFileDownloadView class.

setUseClientCache

See the setUseClientCache method of the JKFileDownloadView class.

isRemoveAfterDownloading

See the isRemoveAfterDownloading method of the JKFileDownloadView class.

setRemoveAfterDownloading

See the setRemoveAfterDownloading method of class JKFileDownloadView.

getUseTomcatSendFile

See the getUseTomcatSendFile method of class JKFileDownloadView.

setUseTomcatSendFile

See the setUseTomcatSendFile method of class JKFileDownloadView.

doRenderImpl

See the doRenderImpl method of the JKAbstractDownloadableView abstract class.

getFilename

See the getFilename method of the JKAbstractDownloadableView abstract class.

setFilename

See the setFilename method of the JKAbstractDownloadableView abstract class.

getMime

See the getMime method of the JKAbstractDownloadableView abstract class.

setMime

See the setMime method of the JKAbstractDownloadableView abstract class.

isInline

See the isInline method of the JKAbstractDownloadableView abstract class.

setInline

See the setInline method of the JKAbstractDownloadableView abstract class.

getCharsetName

See the getCharsetName method of the JKAbstractDownloadableView abstract class.

setCharsetName

See the setCharsetName method of the JKAbstractDownloadableView abstract class.

getDownloadStreamBufferSize

See the getDownloadStreamBufferSize method of the JKAbstractDownloadableView abstract class.

setDownloadStreamBufferSize

See the setDownloadStreamBufferSize method of the JKAbstractDownloadableView abstract class.

getContentDisposition

See the getContentDisposition method of the JKAbstractDownloadableView abstract class.

setContentDisposition

See the setContentDisposition method of the JKAbstractDownloadableView abstract class.