harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oliver Deakin <oliver.dea...@googlemail.com>
Subject Re: [classlib][archive] problems with ZipFile 9was: Re: [testing] M12 testing on Windows x86)
Date Fri, 27 Nov 2009 09:56:21 GMT
Tim Ellison wrote:
> On 26/Nov/2009 18:44, Tim Ellison wrote:
>   
>> On 26/Nov/2009 17:00, Oliver Deakin wrote:
>>     
>>> <snip>
>>>       
>> I'll bet you a beer that it is our friend available() again...
>>
>> Consider this:
>>
>>  static final String NAME = "javax/swing/text/html/parser/html32.bdtd";
>>
>>  public void test() throws IOException {
>>     JarFile jar = new JarFile("swing.jar");
>>     ZipEntry ze = jar.getEntry(NAME);
>>     InputStream is = jar.getInputStream(ze);
>>
>>     System.out.println("Size = " + ze.getSize());
>>     System.out.println("Available = " + is.available());
>>
>>     jar.close();
>>  }
>>
>> On Harmony it prints:
>> Size = 51140
>> Available = 1
>>
>> On the RI it prints:
>> Size = 51140
>> Available = 51140
>>
>> I know the arguments that say available() should not be used to judge
>> the total number of bytes that can be read, but it seems that a number
>> of applications (including our generated parser?) use it in this way.
>>
>> I haven't tried changing it yet[1], but I'll take that bet if you want :-)
>>
>> Regards,
>> Tim
>>
>> [1] I'm supposed to be packing for a long weekend away, so I'll be quiet
>> for the next few days.
>>     
>
> Ok, so I may owe you a beer :-)
>   

Sounds good!

> A quick trial of implementing available() for the inflater stream fixes
> this test case (above) but not the original problem.
>   

Yep, I see the same thing. Although (as Jesse mentioned in the JIRA) we 
call available() in DTD.java and the results are significantly different 
for M11 and M12, as exposed by your test case above, implementing 
available() still does not fix the swing test case.

> Given there are these differences we see emerging, I wonder if we should
> revert the offending code and retry again after M12?
>   

It would be tempting to do this so we can get M12 out the door and then 
fix this issue for M13.

> FYI here is my hacked available() impl, which needs some testing before
> it is good to go in..
>
> 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