wood burning stoves 2.0*
The moose likes I/O and Streams and the fly likes Auditing ZipInputStream Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Auditing ZipInputStream" Watch "Auditing ZipInputStream" New topic
Author

Auditing ZipInputStream

Henrique Sousa
Ranch Hand

Joined: Apr 29, 2004
Posts: 92
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


Henrique Sousa<br />SCJP 1.4<br /> <br />All men die, not all men really live - Braveheart, 1995
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

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.


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Vlado Zajac
Ranch Hand

Joined: Aug 03, 2004
Posts: 245
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

Joined: Apr 29, 2004
Posts: 92
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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Auditing ZipInputStream