ZIp files Asynchronously using java.util.zip

279 visualizações
Pular para a primeira mensagem não lida

David P

não lida,
4 de mar. de 2022, 03:17:4604/03/2022
para 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

não lida,
21 de jun. de 2022, 00:45:2521/06/2022
para vert.x
I also encountered the same issue? Could anyone give some advices?

Julien Viet

não lida,
22 de jun. de 2022, 04:45:1822/06/2022
para 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

não lida,
23 de jun. de 2022, 11:09:1123/06/2022
para vert.x
Thanks Julien.

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

David

Responder a todos
Responder ao autor
Encaminhar
0 nova mensagem