Miscellaneous improvements to "jar".

Xueming Shen Xueming.Shen at Sun.COM
Thu Jun 25 20:04:25 UTC 2009


Martin Buchholz wrote:
> I have an updated version of this fix, with these changes:
>
> - Documented the turkish i problem
>
>     /**
>      * Compares two strings for equality, ignoring case.  The second
>      * argument must contain only upper-case ASCII characters.
>      * We don't want case comparison to be locale-dependent (else we
>      * have the notorious "turkish i bug").
>      */
>     private boolean equalsIgnoreCase(String s, String upper) {
>
> - Refactored code so that updateEntry now also sets the method to STORED.
>
>         /**
>          * Updates a ZipEntry which describes the data read by this
>          * output stream, in STORED mode.
>          */
>         public void updateEntry(ZipEntry e) {
>             e.setMethod(ZipEntry.STORED);
>             e.setSize(n);
>             e.setCrc(crc.getValue());
>         }
>
> - addIndex was never updating the size in the ZipEntry (as required),
>   which was not previously noticed because closeEntry was never called.
>
>     private void addIndex(JarIndex index, ZipOutputStream zos)
>         throws IOException
>     {
>         ZipEntry e = new ZipEntry(INDEX_NAME);
>         e.setTime(System.currentTimeMillis());
>         if (flag0) {
>             CRC32OutputStream os = new CRC32OutputStream(crc32);
>             index.write(os);
>             os.updateEntry(e);
>         }
>         zos.putNextEntry(e);
>         index.write(zos);
>         zos.closeEntry();
>     }
>
> http://cr.openjdk.java.net/~martin/jar-misc/ 
> <http://cr.openjdk.java.net/%7Emartin/jar-misc/>
> Previous webrev:
> http://cr.openjdk.java.net/~martin/jar-misc.0/ 
> <http://cr.openjdk.java.net/%7Emartin/jar-misc.0/>
>
> Martin
>
yes, it now solved the puzzle:-)

(1)closeEntry() is not strictly necessary, either putNextEntry or 
close() will close the previous entry
(2)you might want to go a little further to "encapsulate" the 
updateEntry into crc32os, pass the entry
into the constructor and setup the value with a crc32os.close()...bad idea?

btw,

sherman



More information about the core-libs-dev mailing list