• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Auditing ZipInputStream

 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, ranchers!
I am trying to track how many bytes are actually read from a remote zip file, but a mistery lies before me. Here is the scenario: I have URLConnection to a zip file from which I obtain an InputStream. I create a ZipInputStream from that. In order to audit the reads I wrap the InputStream (the one from the URLConnection) into a my own class, AuditInputStream. Its code is below.
The strange is that, no matter which files I extract from the zip file, the Audit always says only one call was made to read(byte[], int, int) and it returned 30 bytes; but the zip file is 260KB long! So where is the Zip stream reading from?


Any help is appreciated.

Henrique
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you really need a separate class that maintains information about the number of bytes that you are reading from the stream ? Cant you just add up the int value returned by the read() function everytime, and then save it in a log file or something ?

Here is what you would need



As simple as that. Read from the public int result member variable after everything is over. Sandwhich your stream between the buffer and the zip stream.
 
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is what the variable reading does.

I don't know what is the intended purpose of that variable, but the code sets it to true during first read and after that all other reads are not counted because it is set to true.


You can use FilterInputStream when making custom wrapper streams it provides default implementation for most InputStreams methods (by calling methods of underlying stream).
 
Henrique Sousa
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Vlado Zajac:
This is what the variable reading does.

I don't know what is the intended purpose of that variable, but the code sets it to true during first read and after that all other reads are not counted because it is set to true.



Now that was stupid... I forgot to set that variable back to false. I did that because I assumed some read method might end up calling another one (like read(byte[]) calling read(byte[],int,int)) and I would have the wrong byte read count. Thank you so much!
 
reply
    Bookmark Topic Watch Topic
  • New Topic