aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes What is the magic cookie used for? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "What is the magic cookie used for?" Watch "What is the magic cookie used for?" New topic
Author

What is the magic cookie used for?

hua chen
Greenhorn

Joined: Aug 18, 2006
Posts: 8
Hello all,

The database file has the magic cookie in the start of database file. but I do not use it. where should we use it?

Thank you.

Hua
Daniel Massie
Greenhorn

Joined: Jan 08, 2005
Posts: 28
To determine whether the database file specified by the user is valid or not.
Adam Nace
Ranch Hand

Joined: Jul 17, 2006
Posts: 117
since the assignment doesn't specifically require validation of the database file, you can probably safely ignore the magic cookie. It's your call.

- Adam
Daniel Massie
Greenhorn

Joined: Jan 08, 2005
Posts: 28
I'm not so sure about that. My instructions state:
"4 byte numeric, magic cookie value. Identifies this as a data file "

To me that says that the value should be checked.
Adam Nace
Ranch Hand

Joined: Jul 17, 2006
Posts: 117
Originally posted by Daniel Massie:
I'm not so sure about that. My instructions state:
"4 byte numeric, magic cookie value. Identifies this as a data file "

To me that says that the value should be checked.


To me that says "4 byte numeric, magic cookie value. Identifies this as a data file "

That's just telling you what's in the file. It's not uncommon to put a "magic cookie value" at the start of a file. So that when you go to read the data, you know that you have to move into the file by 4 bytes before you try to read the header information. That doesn't mean you have to check it. You can, but you don't have to. It's probably a good idea, and it couldn't hurt. I, for one, actually DO check it, and for the sake of a good design, I would recommend it, but I don't think that it's actually implied that you need to check it.

- Adam
Luiz Reginaldo Curado
Ranch Hand

Joined: Jan 19, 2006
Posts: 108
Hi!

I think you can or not do the validation. Your decision, however, must be justified in the notes file.

One more thought... Remember: you will not be graded for additional code, but you can lost points if you do not implement what is required.
Adam Nace
Ranch Hand

Joined: Jul 17, 2006
Posts: 117
Originally posted by Luiz Reginaldo Curado:
One more thought... Remember: you will not be graded for additional code, but you can lost points if you do not implement what is required.


You're not suggesting that we over-do the crap out of the project just to make sure we get every little thing they were looking for but not telling us about, are you?

Wow. Somebody has a lot of time on his hands...

- Adam
Jeroen T Wenting
Ranch Hand

Joined: Apr 21, 2006
Posts: 1847
Originally posted by Adam Nace:


You're not suggesting that we over-do the crap out of the project just to make sure we get every little thing they were looking for but not telling us about, are you?

Wow. Somebody has a lot of time on his hands...

- Adam


There's no time limit, so no excuse to cut corners.
It's also no competition to get done faster than someone else, so no excuse to cut corners.

I'd rather have an overengineered solution that covers all the points asked for in the specs and then some than some rapidly smashed together piece of junk that misses a single point because I was so hyped up about wanting it completed yesterday that I forgot about something in my haste.


42
Eamonn O'Connell
Greenhorn

Joined: Aug 25, 2006
Posts: 11
It seems like the consensus on this, is that while not required, verifying the magic cookie value is good practice. If this is the case then (here comes the stupid question) how if this verification done?

Do you find out and make a note of what that magic cookie value is, then when the data object (or whatever) attempts to open the file, you make sure it has this same (hardcoded) cookie value?

What if another application also used the database file, and made changes to this magic cookie value?

Hope this makes some kind of sense...
Oricio Ocle
Ranch Hand

Joined: Nov 30, 2004
Posts: 284

My reading is that magic cookie must be ignored, since you dont know validation rules.
The reason is that it is unknown by the developer until execution. So it's value could be that or could be other. We ignore the nature and use of the cookie.
As a personal note, i think it is used by Sun automatic tests to verify the integrity of the uploaded database file or/and choose the right Data implementation from a factory...

Regards


SCJP, OCMJD, OCMJEA
Anne Crace
Ranch Hand

Joined: Aug 29, 2005
Posts: 223
Any thoughts on this from folks who have already passed the exam??? To use or not to use...


SCJP, SCJD
Cindy Rogers
Ranch Hand

Joined: May 17, 2006
Posts: 31
I passed, and did validate the magic cookie. (You're probably looking for the other folks, who passed without validation...)

> Do you find out and make a note of what that magic cookie value is, then
> when the data object (or whatever) attempts to open the file, you make
> sure it has this same (hardcoded) cookie value?

Yes. If the magic cookie value was an exact match, then I assumed the file contents were in the expected format (that is, schema description followed by data section).

> What if another application also used the database file, and made changes
> to this magic cookie value?

The file would be treated as corrupted, and not eligible to be used. For example, we wouldn't know if the information in the schema description section was also overlaid, which could cause unexpected results.
Anne Crace
Ranch Hand

Joined: Aug 29, 2005
Posts: 223
Cindy, no just curious as to the consensus. I have much bigger things that are vexing me right now than figuring out how to use that cookie! It's so small, I figured it is probably better to just go ahead and use it like a validiy flag. I kind of think it is there for a reason (to be used). Congrats on your pass.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What is the magic cookie used for?
 
Similar Threads
Magic cookie in database file - what for?
magic cookie value?
magic cookie ?
non-networked and network mode
quick question about magic cookie