aspose file tools
The moose likes Java in General and the fly likes More eyes please :( Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "More eyes please :(" Watch "More eyes please :(" New topic
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
    
    3

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
    
    9
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!
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: More eyes please :(
 
Similar Threads
Simple JUnit test failed
Junit error
NULL Pointer Exception
Spring framework test case for DAO: No suitable driver
StrutsTestCase problem