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
See the getFile method of JKFileDownloadView class.
See the setFile method of class JKFileDownloadView.
See the isAllowingWeakRange method of the JKFileDownloadView class.
See the setAllowingWeakRange method of the JKFileDownloadView class.
See the isUseClientCache method of the JKFileDownloadView class.
See the setUseClientCache method of the JKFileDownloadView class.
See the isRemoveAfterDownloading method of class JKFileDownloadView.
See the setRemoveAfterDownloading method of class JKFileDownloadView.
See the getUseTomcatSendFile method of class JKFileDownloadView.
See the setUseTomcatSendFile method of class JKFileDownloadView.
See the doRenderImpl method of the JKAbstractDownloadableView abstract class.
See the getFilename method of the JKAbstractDownloadableView abstract class.
See the setFilename method of the JKAbstractDownloadableView abstract class.
See the getMime method of the JKAbstractDownloadableView abstract class.
See the setMime method of the JKAbstractDownloadableView abstract class.
See the isInline method of the JKAbstractDownloadableView abstract class.
See the setInline method of the JKAbstractDownloadableView abstract class.
See the getCharsetName method of the JKAbstractDownloadableView abstract class.
See the setCharsetName method of the JKAbstractDownloadableView abstract class.
See the getDownloadStreamBufferSize method of the JKAbstractDownloadableView abstract class.
See the setDownloadStreamBufferSize method of the JKAbstractDownloadableView abstract class.
See the getContentDisposition method of the JKAbstractDownloadableView abstract class.
See the setContentDisposition method of the JKAbstractDownloadableView abstract class.
-