aspose file tools*
The moose likes Java in General and the fly likes Completely Stumped! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Completely Stumped!" Watch "Completely Stumped!" New topic
Author

Completely Stumped!

Robert Paris
Ranch Hand

Joined: Jul 28, 2002
Posts: 585
When I read from a ZipInputStream (in a while loop checking that it's not -1) into ByteArrayOutputStream and then put that byte array into a ByteArrayInputStream and read from it, it reads out 36864 (which is 512 * 72), which is the correct size.
When I read from a ZipInputStream in a while loop, but this time just filling a byte array of size 512, 72 times (I implemented read(byte[], int, int) to read in a while loop and fill the array), the last time it only returns 441 bytes, for a total of 36793 (which is NOT the right size).
What could possibly be going on here?

That's my method which is used when reading the byte[512] amounts.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
So far, I'm stumped too. What does your read(byte[], int, int) code look like?


"I'm not back." - Bill Harding, Twister
Chad McGowan
Ranch Hand

Joined: May 10, 2001
Posts: 265
Here is the problem:
while ( ( byteRead = stream.read() ) != -1 && count < length )
Each iteration of your while loop is missing a byte because when count = 512, you don't write the byte... however you have already read the byte from the stream.
You need to change your while loop to:
Robert Paris
Ranch Hand

Joined: Jul 28, 2002
Posts: 585
You absolute GENIUS Chad!! ANYTIME you want a question answered, just throw it my way!!! I've been trying EVERYTHING all day to solve that! Of COURSE! that's why it was exactly 71 bytes off (the previous 71 reads all left it off) I totally missed that.
Thanks for the reply too Jim. Nice catch by Chad, right?
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Sure was. I'd better start hearing more "genius" praise when I do answer your questions correctly though.
Robert Paris
Ranch Hand

Joined: Jul 28, 2002
Posts: 585
Lol. You got it.
Chad McGowan
Ranch Hand

Joined: May 10, 2001
Posts: 265
Wow, now thats what I call positive feedback!!
I may print that out and hang it in my cube...
PS How about writing a letter to my boss
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Make sure he spell checks it first. He just called me a "genuis" in this thread. The sentiment was appreciated though.
Robert Paris
Ranch Hand

Joined: Jul 28, 2002
Posts: 585
Don't know what you're talking about Jim.
Trust me on this: even if a client said you were amazing and indisposable, your boss probably wouldn't share the same sentiment.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Completely Stumped!