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

dextuploadjk.support.spring
Class JKFilesToZipDownloadView

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 the given files into a single zip file and performs the download.

@RequestMapping(value = "download-zip", method = RequestMethod.GET)
public ModelAndView downloadZip(...) {
    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"));
		
    JKFilesToZipDownloadView view = new JKFilesToZipDownloadView();
			
    view.setEntries(files);
    view.setCharsetName("UTF-8");
			
    return new ModelAndView(view);
}

The JKFilesToZipDownloadView view compresses the target files and performs the download immediately afterward.

It removes the compressed files 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 JKFilesToZipDownloadView view class) to create the compressed file and then download it using the JKFileDownloadView class.

@RequestMapping(value = "download-zip", method = RequestMethod.GET)
public ModelAndView downloadZip(...) {
    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"));
    
    // Manually create a compressed file using CompressUtil.
    CompressUtil zipper = new CompressUtil();
    File zipped = zipper.zip(entries, "/tmp", "UTF-8", false, true);
		
    // Create a JKFileDownloadView object to download the file.
    JKFileDownloadView view = new JKFileDownloadView();
    
    view.setFile(zipped);
    view.setFilename("files.zip");
    view.setMime("application/x-zip-compressed");
    view.setUseClientCache(false);
    view.setCharsetName("UTF-8");
    
    return new ModelAndView(view);
}
Constructor

JKFilesToZipDownloadView

  • Create a JKFilesToZipDownloadView object.

  • Signatures

    public JKFilesToZipDownloadView()
    public JKFilesToZipDownloadView(List<File> entries)
    public JKFilesToZipDownloadView(List<File> entries, String filename)
    public JKFilesToZipDownloadView(List<File> entries, List<String> entryNames, String filename)
  • Parameters

    Name Type Description
    entries java.util.List<java.io.File> An object pointing to the list of files to zip
    filename java.lang.String the filenames to be downloaded by the client
    entryNames java.util.List<java.lang.String>

    A list of file names to be compressed, which should be equal to the size of the entries parameter.

Methods

getEntries

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

  • Signatures

    public List<File> getEntries()
  • Return

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

setEntries

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

  • Signatures

    public void setEntries(List<File> entries)
  • Parameters

    Name Type Description
    entries java.util.List<java.io.File> Object pointing to a list of files to compress

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, 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.

getEntryNames

  • Returns a list of file names to compress.

  • Signatures

    public List<String> getEntryNames()
  • Return

    List of names of files to compress

setEntryNames

  • Sets the list of names of files to compress.

  • Signatures

    public void setEntryNames(List<String> entryNames)
  • Parameters

    Name Type Description
    entryNames List<String> List of names of files to compress

getFile

See the getFile method of JKFileDownloadView class.

setFile

See the setFile method of class JKFileDownloadView.

isAllowingWeakRange

See the isAllowingWeakRange method of the JKFileDownloadView class.

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 class JKFileDownloadView.

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.