• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

More eyes please :(

 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah!

I think I understand that, thanks a lot to the both of you!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic