Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need to varify my file discriptor...

 
Yucca Nel
Ranch Hand
Posts: 147
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here it is and what I do with the info....

Start of file
4 byte numeric, magic cookie value. Identifies this as a data file
I hardcode this value and use it to varify the database as the correct one for my program.
4 byte numeric, total overall length in bytes of each record
I hardcode this value and use it to read my records one record at a time (reduces bottlenecking).
2 byte numeric, number of fields in each record
I hardcode this value to varify that all new entries have the correct number of fileds to be considered valid.


data section.
Repeat to end of file:
1 byte "deleted" flag. 0 implies valid record, 1 implies deleted record
Here I need help. All other info (database schema) is coded into my Contracter object as filelds. I intend to use this deleted flag as a field too but am insure if I can use a Byte to store it?
Record containing fields in order specified in schema section, no separators between fields, each field fixed length at maximum specified in schema information


End of file
 
Anne Crace
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it says it is 1 Byte long, it should fit in a Byte. 0 and 1 should easily go in a Byte. Mine is 2 bytes long and I use RandomAccessFile readUnsignedShort and writeShort to deal with it. I don't put it in a variable at all. My deleted flag is actually too big by 1 to fit in a Short, and rolls to -32,768, but from what I've read on this forum that is perfectly acceptable. Hope this helps.
 
Yucca Nel
Ranch Hand
Posts: 147
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry peeps I am having issues. I have no clue where my offset starts. I have not been given one and dont know how to find where I should start reading records from. The other issue I have is determining the length of the deleted flag field. I tried to calculate this value by taking the my total record length(as read from file) and the subtracting all field lengths(as read from file) and then setting that as my length for the deleted flag. Does that sound like a plausible way to do it?
 
Anne Crace
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is from my instructions: Start of file. 4 byte numeric, magic cookie...4 byte numeric, offset to the start of record zero, 2 byte numeric, number of fields in each record. I have 4A in hex for my offset (4 * 16 = 64 + 10 = 74). Looking at it in a hex editor, it is a letter J, Ascii character 74, so my offset is 74. Do yourself a huge favor and get a hex editor. You should be able to Google and find a free one. It is so much easier if you can see the contents of that file, especially when you are just starting out and have to parse the whole file.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic