| Author |
More eyes please :(
|
Ryan Waggoner
Ranch Hand
Joined: Jun 27, 2007
Posts: 75
|
|
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
Joined: Aug 07, 2007
Posts: 1162
|
|
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
Joined: Jun 27, 2007
Posts: 75
|
|
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
Joined: Aug 05, 2005
Posts: 3011
|
|
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.
|
Joanne
|
 |
Ryan Waggoner
Ranch Hand
Joined: Jun 27, 2007
Posts: 75
|
|
Ah! I think I understand that, thanks a lot to the both of you!
|
 |
 |
|
|
subject: More eyes please :(
|
|
|