Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2006

Tip: Looking for answers? Try searching our database.

How to update a file within a jar file?

Thread view: 
O.B. - 29 Jan 2006 00:00 GMT
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?
opalpa@gmail.com opalinski from opalpaweb - 29 Jan 2006 00:49 GMT
Haven't used it but using java.util.jar seems better than
java.util.zip.  It can write jar files, I think you can use this to
read entries, delete entries, and then add entries, which you may be
able to encapsulate as an update:

http://java.sun.com/j2se/1.4.2/docs/api/java/util/jar/package-summary.html

Good luck

Opalinski
opalpa@gmail.com
http://www.geocities.com/opalpaweb/
Roedy Green - 29 Jan 2006 02:51 GMT
>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

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Thomas Weidenfeller - 30 Jan 2006 08:23 GMT
> 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
Signature

The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.