ZIp files Asynchronously using java.util.zip

50 views
Skip to first unread message

David P

unread,
Mar 4, 2022, 3:17:46 AMMar 4
to vert.x
Hello dear Vertx Community,

I want ot ZIP files suing the  java.util.zip like code sample below:

------------------------------
String sourceFile = "test1.txt"; FileOutputStream fos = new FileOutputStream("compressed.zip"); ZipOutputStream zipOut = new ZipOutputStream(fos); File fileToZip = new File(sourceFile); FileInputStream fis = new FileInputStream(fileToZip); ZipEntry zipEntry = new ZipEntry(fileToZip.getName()); zipOut.putNextEntry(zipEntry); byte[] bytes = new byte[1024]; int length; while((length = fis.read(bytes)) >= 0) { zipOut.write(bytes, 0, length); } zipOut.close(); fis.close(); fos.close();
------------------------------------------------------------

How to perform the I/O operation (write to file) Asynchronously (with EventLoop Thread)?
  1. - Is there a way to ZIP files using ONLY Vertx toolbox?
  2. - Is there a way to "bridge" java.io.OutputStream for ZipOutputStream to io.vertx.core.streams.WriteStrea of io.vertx.core.file.AsyncFile?
  3. Else, Should I use a WorkerThread to perform this Synchronous operation?
Thanks,

David



Young

unread,
Jun 21, 2022, 12:45:25 AMJun 21
to vert.x
I also encountered the same issue? Could anyone give some advices?

Julien Viet

unread,
Jun 22, 2022, 4:45:18 AMJun 22
to vert.x
I think what should be done is to use a worker thread and work with
java.io files

It could be possible to use the event loop by compressing the stream
by chunks along with vertx async files too and not block the event
loop, but it seems a bit technical to achieve and perhaps worthless if
you only need to compress a single file.

Julien
> --
> You received this message because you are subscribed to the Google Groups "vert.x" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
> To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/a6ee8a87-0e77-4249-ae3d-f3430568de0fn%40googlegroups.com.

David P

unread,
Jun 23, 2022, 11:09:11 AMJun 23
to vert.x
Thanks Julien.

We use a Worker Thread to zip files with Jave.io.

David

Reply all
Reply to author
Forward
0 new messages