• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Interpretation of data file format

 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, everyone

I am starting to work on my assignment (URLyBird). I was reading the instructions file and I played a bit with the reading of the database file.

My instructions file says:

Start of file

4 byte numeric, magic cookie value. Identifies this as a data file
2 byte numeric, number of fields in each record
....


Does anyone of you know what this magic cookie value mean and what is it good for?

What am I suppose to do with this cookie value? Are you using this data with any particular purpose?

Just for exploration purposes I've written this lines of code to read the file metadata, but I do not see the use of this magic cookie.



Thanks in advance, guys.

Regards,
LoC.
[ January 10, 2006: Message edited by: Edwin Dalorzo ]
 
Chengwei Lee
Ranch Hand
Posts: 884
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Edwin,

Working on the same assignment as you're. I'd probably use this magic value to validate that the file I'm opening is a valid database file. As in if the value is non-numeric, I'd probably throw an exception & stop.

Good luck for your assignment!
 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, comrade. Thanks for your reply.

Well, I've been thinking about the file validation, you know, I was giving some thought to the problem of determining if the file is corrupted.

I am not sure that I should do that, because I could suppose the file is never corrupted and I could document it that way in the design choices file. What do you say to that, pal?

On the other hand I could use this "magic cookie" as validation mechanism, but that does not warrant that the file is not corrupted at all.

Are you taking any particular strategy to validate the well-formedness of your file?

For instance, while reading metadata:
  • Validate file size (Because the file has to be at least big enough to hold the magic cookie and an integer containing the number of fields equal to 0 if the file is empty, and that'll be at least 6 bytes).
  • Validate that the number of fields be a positive number integer.
  • Validate that fields names are compliant with the naming conventions of identifiers
  • Validate that field sizes are positive numbers


  • If I find unexpected values in any of this validations I will have to throw some sort of UnknowFileFormatException.

    What do you think, people?

    Good luck to you too, Chengwei. Thanks again for your feedback.

    Regards,
    Edwin Dalorzo
    [ January 11, 2006: Message edited by: Edwin Dalorzo ]
     
    Andrew Monkhouse
    author and jackaroo
    Marshal Commander
    Pie
    Posts: 12007
    215
    C++ Firefox Browser IntelliJ IDE Java Mac Oracle
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi Edwin,

    Having gotten past all those checks you mentioned, you can also do a validation on the file size itself: you should know the size of the meta-data (that is a constant), you should be able to calculate the length of the schema, and from that you can determine the size of a record. Subtract the meta-data size and the schema size from the size of the file, and the remainder should be an exact multiple of the the record size.

    Regards, Andrew
     
    Edwin Dalorzo
    Ranch Hand
    Posts: 961
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hey, Andrew

    That's a good one, I will add it to my validations while loading the file metadata.

    Thanks very much!
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic