• Post Reply Bookmark Topic Watch Topic
  • New Topic

Best way to manipulate multiple zip file in Java?

 
Hải Đăng Nguyễn
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We are now using NIO's Zip File System Provider to dynamically add meta file to difference zip file before send it to our user. The problem is we must make a copy of the original file, then add meta file to it, then delete the temp file after the task done. I feel that doing that task is very inefficient. I tried use NIO's MappedByteBuffer to directly map zip file to memory then manipulate it with Zip Input/Output Stream, but it is incredibly slow because there are too much zip entries and we doesn't need all.

I'm thinking of an In-memory Zip File System, which we can first load the zip file into memory, then manipulate it with without makes the stupid temporary copy and then delete it. But I can't find anything like that.

Can you share your experience and solution for this problem? Thank you very much!

Here is my effort with ZIP Input/Output Stream. The test.zip size is ~60MB, contains 1,142 files, 46 folders. Note that this is just a code snippet. Actually the byte[] byteBlock = "Hello World".getBytes() will be generated based on user's request.

 
Tony Docherty
Saloon Keeper
Posts: 3138
72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What makes you say "I feel that doing that task is very inefficient."?
Have you timed it and it takes longer than is acceptable or longer than other methods of manipulating a zip file?

AFAIK Modifying a zip file will involve reading the file and writing it out again whichever technique you use.
 
Tony Docherty
Saloon Keeper
Posts: 3138
72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BTW thanks for mentioning NIO's Zip File System Provider. I hadn't spotted that addition to NIO library and it could be very useful for something I've been working on.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!