harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nathan Beyer <ndbe...@apache.org>
Subject Re: [classlib][archive] problems with ZipFile 9was: Re: [testing] M12 testing on Windows x86)
Date Fri, 27 Nov 2009 21:10:09 GMT
On Fri, Nov 27, 2009 at 5:30 AM, Oliver Deakin
<oliver.deakin@googlemail.com> wrote:
>
>
> Tim Ellison wrote:
>>
>> <snip>
>> FYI here is my hacked available() impl, which needs some testing before
>> it is good to go in..
>>
>
> With this patch for available() applied the ASN1Exception no longer gets
> thrown in BerInputStream.read(), but instead an ASN1Exception is thrown in
> BerInputStream.readSequence() at line 671. The message from this exception
> is "Mandatory value is missing at [3255]".
>
> Looking in the byte buffer contents, I see that after index 3255 all its
> values are 0, whereas in M11 they are all populated as expected. It looks
> like DTD.read() is assuming that its stream.read(enc) call (around line 149)
> will return a full buffer, but with the new zip changes it does not.
> Applying a patch something like this (along with Tim's ZipFile patch below)
> fixes the test failures and I get a clean run of the full swing test suite:
>
> Index: DTD.java
> ===================================================================
> --- DTD.java    (revision 884214)
> +++ DTD.java    (working copy)
> @@ -142,8 +142,12 @@
>
>    public void read(final DataInputStream stream) throws IOException {
>        // converts from DataInputStream into a byte array
> -        byte[] enc = new byte[stream.available()];
> -        stream.read(enc);
> +        int available = stream.available();
> +        byte[] enc = new byte[available];
> +        int readBytes = 0;
> +        while (readBytes != available) {
> +            readBytes += stream.read(enc, readBytes, available -
> readBytes);
> +        }
>        // decode the byte array
>        Asn1Dtd asn1 = new Asn1Dtd(enc);
>

Isn't this still incorrect? The available() method isn't equivalent to
what's left in the stream - it's just what's available before the read
will start blocking. Don't you have to read from the stream until it
hits EOF/EOS?

If the use case requires that the entire stream must be read before
moving on, then there's really no point in using available() at all.
Correct?

-Nathan

-Nathan

> Regards,
> Oliver
>
>
>> Index: src/main/java/java/util/zip/ZipFile.java
>> ===================================================================
>> --- src/main/java/java/util/zip/ZipFile.java    (revision 884543)
>> +++ src/main/java/java/util/zip/ZipFile.java    (working copy)
>> @@ -247,7 +247,7 @@
>>             rafstrm.skip(entry.nameLen + localExtraLenOrWhatever);
>>             rafstrm.mLength = rafstrm.mOffset + entry.compressedSize;
>>             if (entry.compressionMethod == ZipEntry.DEFLATED) {
>> -                return new InflaterInputStream(rafstrm, new
>> Inflater(true));
>> +                return new ZipInflaterInputStream(rafstrm, new
>> Inflater(true), 1024, entry);
>>             } else {
>>                 return rafstrm;
>>             }
>> @@ -415,4 +415,27 @@
>>             return n;
>>         }
>>     }
>> +
>> +    static class ZipInflaterInputStream extends InflaterInputStream {
>> +
>> +        ZipEntry entry;
>> +        long bytesRead = 0;
>> +
>> +        public ZipInflaterInputStream(InputStream is, Inflater inf, int
>> bsize, ZipEntry entry) {
>> +            super(is, inf, bsize);
>> +            this.entry = entry;
>> +        }
>> +
>> +        public int read(byte[] buffer, int off, int nbytes) throws
>> IOException {
>> +            int i = super.read(buffer, off, nbytes);
>> +            if (i != -1) {
>> +                bytesRead += i;
>> +            }
>> +            return i;
>> +        }
>> +
>> +        public int available() throws IOException {
>> +            return super.available() == 0 ? 0 : (int) (entry.getSize()
>> - bytesRead);
>> +        }
>> +    }
>>  }
>>
>>
>>
>>
>
> --
> Oliver Deakin
> Unless stated otherwise above:
> IBM United Kingdom Limited - Registered in England and Wales with number
> 741598. Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire
> PO6 3AU
>
>

Mime
View raw message