aspose file tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Magic cookie in database file - what for? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Magic cookie in database file - what for?" Watch "Magic cookie in database file - what for?" New topic

Magic cookie in database file - what for?

Jimmy Ho
Ranch Hand

Joined: Jul 31, 2007
Posts: 61
So the database file provided in my SCJD assignment has its first two bytes reserved as a magic cookie at the very beginning of the file. What is this magic cookie for? I currently don't see a use for it. Am I missing something?
Alexander Duenisch

Joined: May 29, 2006
Posts: 24
The magic cookie identifies your file as a database file
in the reqired format for your application.
Your app should check this cookie in the startup process
so it can throw around exceptions if it got fed an unknown
file format.
If the cookie is correct, you can still encounter a corrupted
file, but if it is incorrect, you know for sure the file is bad.

Hope this brought some enlightenment.


---------------------------<br />OCUP-F, SCJP 5.0, SCJD, SCWCD
mohamed sulibi
Ranch Hand

Joined: Sep 04, 2005
Posts: 169

i read the Magic cookie value; but because the requirement is not clear for
it, i through this value away. and i will discuss it in the choices document.

what you think ?

Mohamed Darim.
Roberto Perillo

Joined: Dec 28, 2007
Posts: 2269

Well, since the Magic Number that the database already has is, in my case, 257, I assumed that this is the right Magic Cookie (Magic Number in my case). When I first open the database file I check if this is the value found; if it is, than it's OK, otherwise, I don't proceed.

Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
Jack Yang

Joined: Dec 10, 2007
Posts: 1
Hi Roberto,

I didn't see any Magic cookie number for the assignment. May I ask you how you knew your Magic cookie is 257?

[ April 30, 2008: Message edited by: Jack Yang ]
Roberto Perillo

Joined: Dec 28, 2007
Posts: 2269

Hey my buddy.

So, this number is the first thing that appears in the .db file. It indeed does not appear in the assignment, and all we know is that it identifies whether a particular file is valid or not. Since the valid value is not mentioned, and my .db file has this value (257), I assumed that this value is the correct one. By the way, I hardcoded this value.
This is the first thing of the .db file. As soon as you open it, call the readInt() method of your RAF object, and you'll find out the magic number of your database!
I agree. Here's the link:
subject: Magic cookie in database file - what for?