Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (491)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (556)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Problem with Zip Files  (Read 1595 times)
0 Members and 1 Guest are viewing this topic.
Offline Evil-Devil

Senior Member


Medals: 2


Fir Tree Master


« Posted 2005-09-01 18:42:08 »

Hi there,
I have a problem with ZipFiles.
In my programm I can create and read the Zipfiles and add files to it, when they are newly created. But when I open a zipfile and wanna append some files, it always overwrite it from the beginning. How have I to open and read the zipfile, that the outputstream will append at the end where the inputstream lasts?

Benny
Offline CaptainJester

JGO Knight


Medals: 12
Projects: 2
Exp: 14 years


Make it work; make it better.


« Reply #1 - Posted 2005-09-04 03:30:19 »

It's not a problem with Zip, it is a problem with the way you open the file.  You might be doing this:
1  
2  
FileOutputStream out = new FileOutputStream("myfile.zip");
ZipOutputStream zip = new ZipOutputStream(out);


What you need is:
1  
2  
FileOutputStream out = new FileOutputStream("myfile.zip", true);
ZipOutputStream zip = new ZipOutputStream(out);

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 783
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #2 - Posted 2005-09-04 08:34:49 »

Note that the bytes you append to the file will not be part of the zip-file structure.

Quote
But when I open a zipfile and wanna append some files

You cannot append files that way to the zip. You have to rewrite the entire file.


Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline CaptainJester

JGO Knight


Medals: 12
Projects: 2
Exp: 14 years


Make it work; make it better.


« Reply #3 - Posted 2005-09-04 23:13:34 »

Note that the bytes you append to the file will not be part of the zip-file structure.

Quote
But when I open a zipfile and wanna append some files

You cannot append files that way to the zip. You have to rewrite the entire file.


I never tried it before.  I just thought you could append if you opened the stream with append enabled.

Offline Jeff

JGO Coder




Got any cats?


« Reply #4 - Posted 2005-09-05 03:15:02 »

Note that the bytes you append to the file will not be part of the zip-file structure.

Quote
But when I open a zipfile and wanna append some files

You cannot append files that way to the zip. You have to rewrite the entire file.


I never tried it before.  I just thought you could append if you opened the stream with append enabled.

Zip files are an on-disc indexed data structure.  Thats how the Zip program can tell a damaged one (sometimes.)  You cant just dorp stuff at the end.

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline Evil-Devil

Senior Member


Medals: 2


Fir Tree Master


« Reply #5 - Posted 2005-09-05 16:50:24 »

err, ok...when i understand all correct...i have to open the zip file and extract all entries to a tmp directory and then creating a new zipfile that will hold the new and old entries. Uff, i won't mention the loading bars the user see....

But who does the Win32 Version of Zip do appending? There is just no speeddecrease while appending files to the archive. You open and can add them... Confused...

Benny
Offline Alan_W

JGO Knight


Medals: 8
Projects: 3


Java tames rock!


« Reply #6 - Posted 2005-09-05 17:38:09 »

The files in a zip archive are individually compressed.  Therefore Winzip (say) only needs to open the archive and extract the files as binary blobs.  When new files are added, they are compressed into blobs as part of the adding process.  When you close the archive, the directory structure is regenerated and it and the blobs are written to the disc.  Thus why you do need to rewrite the entire archive, you don't need to decompress/recompress the files already in it.

So... the question is (and I don't know the answer) - Can you open a zip archive in java & add stuff to it, without decompressing/recompressing the existing files.

Time flies like a bird. Fruit flies like a banana.
Offline Evil-Devil

Senior Member


Medals: 2


Fir Tree Master


« Reply #7 - Posted 2005-09-05 18:31:15 »

You mean it should be enough to create for each ZipEntry in the file a corresponding ZipEntry that will be saved back to the new archive with the new entries?

I' ll give all hints a try Smiley
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 783
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #8 - Posted 2005-09-05 19:42:20 »

You just can't do it with java.util.zip.*

You would have to write your own Zip-loader that gives you the off->len for each entry in the binary zip-file. This might be quite some work, but when you achieved that, you can copy the compressed data, instead of decompress/compress. And you would have to recreate the directory-structure. Maybe there are some 3rd party APIs what will save you all this work.

Good luck.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Evil-Devil

Senior Member


Medals: 2


Fir Tree Master


« Reply #9 - Posted 2005-09-06 11:01:56 »

Ok, that seems to be some more work that i wanted in first place. I will look through the web for such a 3rd API or just create a simple package with each containing file compressed with GZIP as alternative. That way i woul be able to append at the end.

thank for the tips Smiley
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Nickropheliac (15 views)
2014-08-31 22:59:12

TehJavaDev (23 views)
2014-08-28 18:26:30

CopyableCougar4 (32 views)
2014-08-22 19:31:30

atombrot (41 views)
2014-08-19 09:29:53

Tekkerue (40 views)
2014-08-16 06:45:27

Tekkerue (35 views)
2014-08-16 06:22:17

Tekkerue (25 views)
2014-08-16 06:20:21

Tekkerue (37 views)
2014-08-16 06:12:11

Rayexar (72 views)
2014-08-11 02:49:23

BurntPizza (49 views)
2014-08-09 21:09:32
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!