Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Completely Stumped!

 
Robert Paris
Ranch Hand
Posts: 585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So far, I'm stumped too. What does your read(byte[], int, int) code look like?
 
Chad McGowan
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure was. I'd better start hearing more "genius" praise when I do answer your questions correctly though.
 
Robert Paris
Ranch Hand
Posts: 585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lol. You got it.
 
Chad McGowan
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic