I wrote the code with the spring boot.
A feature that allows you to take several directories from a resource, compress them into a zip, and download them.
It is currently developed using the zip4j library.
File.createTempFile("test_", ".zip");
String tempFilePath = createTempFile.getAbsolutePath();
createTempFile.delete(); // create and delete to take only different temporary file paths in different OSs
ZipFile zipFile = new ZipFile(createTempFile);
... a summary of...
FileInputStream fileInputStream = new FileInputStream(zipFile.getFile());
byte[] binaryData = IOUtils.toByteArray(fileInputStream);
fileInputStream.close();
new File(tempFilePath).delete();
Create a zip file as above (to be exact, create a temporary file in the tmp path that fits each OS, take the temporary file path, delete it, and leave it to zip4j) and send the zip file down using the addStream method. The zip file has been deleted since then.
I guess when you create a ZipFile object in zip4j, the constructor actually creates the file internally. Because if you do not call the createTempFile.delete(); method, an excursion occurs.
Although the zip4j library is very good in terms of ease of use, it bothers me to create temporary files and delete them after I get the byte array. Instead of creating a zip file as a real file, I want to send it to Response Entities by byte array with only streams.
I've searched github, but I don't think I found a library that fits my needs exactly my needs.
Please let me know if you know any open source libraries.
java spring spring-boot
The window on the screen is Zeppelin.Create a sample with a scalar.
The sample code is not much different from Java, so I think you will understand it easily.
The code is to compress the string ABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABC.
import java.util.zip._
import java.io._
val buffer = new ByteArrayOutputStream(4096)
val w = new ZipOutputStream(buffer)
w.putNextEntry(new ZipEntry("filename.txt"))
w.write(Array[Byte](65, 66, 67, 65, 66, 67, 65, 66, 67, 65, 66, 67, 65, 66, 67, 65, 66, 67, 65, 66, 67, 65, 66, 67, 65, 66, 67, 65, 66, 67, 65, 66, 67, 65, 66, 67, 65, 66, 67, 65, 66, 67, 65, 66, 67, 65, 66, 67))
w.finish()
w.flush()
w.closeEntry()
584 PHP ssh2_scp_send fails to send files as intended
578 Understanding How to Configure Google API Key
614 GDB gets version error when attempting to debug with the Presense SDK (IDE)
576 Who developed the "avformat-59.dll" that comes with FFmpeg?
573 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
© 2024 OneMinuteCode. All rights reserved.