Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

More eyes please :(

 
Ryan Waggoner
Ranch Hand
Posts: 75
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Heres the code and the error, I am not sure how to deal with. Can anyone see what is going wrong?


And the error...


I am doing the create, then running putBlock, and then when I try to do the getBlock, I am getting that error.
 
Tony Docherty
Bartender
Pie
Posts: 2878
59
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fin.read(block, position, header.getBlockSize());

This line reads 'header.getBlockSize()' number of bytes into the 'block' byte array starting at index 'position'. Now given that the 'block' array was created at the size of 'header.getBlockSize()' you should be able to see that if the starting index is anything other than 0 the 'block' array isn't going to be big enough for all the values.
 
Ryan Waggoner
Ranch Hand
Posts: 75
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tony,
I'm sorry I don't quite see what you mean.

I was trying to create the block array to the block size.
Then i was trying to read in the amount of a block size, into the block array, starting at that position.
 
Joanne Neal
Rancher
Pie
Posts: 3742
16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you try and read 10 bytes into a byte array of size 10 starting at position zero, then you will fill positions 0 to 9. No problem

If you try and read 10 bytes into a byte array of size 10 starting at position 5, then you will fill positions 5 to 14. Unfortunately you don't have positions 10 to 15, so you get an out of bounds exception.

Your array is header.getBlockSize() bytes long. You are trying to read 'header.getBlockSize() bytes into it. So, unless Header.headerSize + (id * Header.blockSize) evaluates to zero, you will get an out of bounds exception.
 
Ryan Waggoner
Ranch Hand
Posts: 75
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah!

I think I understand that, thanks a lot to the both of you!
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic