Frage

I want to open a specific file and zip it and send the byte array of the zipped result over UDP.

Now I checked the java zip API but it only give me to save the zipped file to the computer and opening it again and send it would be inefficiency.

Is there any way to do what I need without writing an implementation of the compression algorithm of my own ?

War es hilfreich?

Lösung

You cand wrap your ZipOutputStream around a ByteArrayOutputStream and get the bytes out of the ByteArrayOutputStream. Something like this:

ByteArrayOutputStream baos = new ByteArrayOutputStream();
ZipOutputStream zos = new ZipOutputStream(baos);
//write the entries
zos.close();
byte[] bytes = baos.toByteArray();
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top