How to update a file within a jar file?

O

O.B.

I have some xml files that need to be read and/or updated are within a
jar file. Using java.util.zip.ZipFile, I have been able to extract the
xml files as an InputStream. But there appears to be no methods in
ZipFile to modify/update an xml file within an existing jar file with an
OutputStream. What other solutions are there?
 
R

Roedy Green

ut there appears to be no methods in
ZipFile to modify/update an xml file within an existing jar file with an
OutputStream. What other solutions are there?
See the code at http://mindprod.com/jgloss/zip.html

You can certainly add a new entry. So perhaps the way you are supposed
to do it is by deleting the old entry and writing a new one.

On my curiosity list is to discover how clever java is about writing
zips.. In the worst scenario, every time you update an element it
would rewrite the whole file, or collapse and created hole in place.
If it were smart it could just tack on the end, and when you did the
file close, it could copy the whole thing to a new file, leaving out
the holes. In the happy case there were no holes, it could bypass the
final copy/rename.

Anyone old enough to remember IBM 360 and the endless in-place
compressing of partitioned datasets, shaking the drives? Univac byte
machines had the same problem. I wrote a compressor that found another
physical drive to copy to, leaving the holes behind, then copied
back. It was much faster and put less wear on the drives, since
neither head had to move more than a track at a time.

I have wondered how long until we get high performance drives with
multiple sets of arms then a smart algorithm in the drive reduce head
motions. Their existence could be transparent to the OS, though the
system might work better if the two co-operated.

Similarly, I still have not seen any marthaing hard drives. I proposed
this idea way back in the early 80s. See
http://mindprod.com/jgloss/martha.html
 
T

Thomas Weidenfeller

O.B. said:
I have some xml files that need to be read and/or updated are within a
jar file. Using java.util.zip.ZipFile, I have been able to extract the
xml files as an InputStream. But there appears to be no methods in
ZipFile to modify/update an xml file within an existing jar file with an
OutputStream.

Jes, there is indeed no such API in Java. You would have to unpack the
zip/jar and repack it with your new file.

What other solutions are there?

Not doing it. Why do you need to have that xml file in the jar file?

Or you could try going native. One particular form of a Zip file has its
directory at the file end. Maybe (I have never tried or studied it in
detail), it is possible to use this to manipulate the contents without
the need to repack the complete file. Maybe not.

/Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,434
Messages
2,571,689
Members
48,796
Latest member
Greg L.

Latest Threads

Top