File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Auditing ZipInputStream

 
Henrique Sousa
Ranch Hand
Posts: 92
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Vlado Zajac
Ranch Hand
Posts: 245
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic