New Java - Create Zip file in memory By Patricbensen

New Java - Create Zip file in memory By Patricbensen - is the information you are looking for, and in the blog All Specs Gadget we have provided her, all right in this article titled New Java - Create Zip file in memory By Patricbensen we will discuss it in full, in addition to the information we have also provided a lot of info about the latest gadgets and a wide range of tips and tricks that according to the gadget you are using, well please continue reading:

Articles: New Java - Create Zip file in memory By Patricbensen
Full Link : New Java - Create Zip file in memory By Patricbensen
Artikel java, Artikel sample code, Artikel tips and tricks,

You can also see our article on:


New Java - Create Zip file in memory By Patricbensen

I find myself writing and rewriting this piece of code whenever I want to zip a set of files (in memory) and return the zipped file back as an object in memory. I often use this when the user requests a download of multiple reports and the deployment environment doesn't allow for disk access.

I thought I'd post it here so that I could copy-paste it the next time I need it :) If you've stumbled upon this page, you're free to use the code below too!



private static byte[] createZip(Map files) throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ZipOutputStream zipfile = new ZipOutputStream(bos);
Iterator i = files.keySet().iterator();
String fileName = null;
ZipEntry zipentry = null;
while (i.hasNext()) {
fileName = (String) i.next();
zipentry = new ZipEntry(fileName);
zipfile.putNextEntry(zipentry);
zipfile.write((byte[]) files.get(fileName));
}
zipfile.close();
return bos.toByteArray();
}



Information New Java - Create Zip file in memory By Patricbensen has finished we discussed

says the article New Java - Create Zip file in memory By Patricbensen, we beharap be useful to you in finding repensi about the latest gadgets and long.

Information on New Java - Create Zip file in memory By Patricbensen has finished you read this article and have the link https://patricbensen.blogspot.com/2008/04/new-java-create-zip-file-in-memory-by.html Hopefully the info we deliver is able to address the information needs of the present.

0 Response to "New Java - Create Zip file in memory By Patricbensen"

Post a Comment