Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes NX:URLyBird What's magic cookie? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "NX:URLyBird What Watch "NX:URLyBird What New topic
Author

NX:URLyBird What's magic cookie?

Leo Tien
Ranch Hand

Joined: Sep 10, 2002
Posts: 156
In my assignment there is this statement:
4 byte numeric,magic cookie value . Identifies this as a data file

What's magic cookie value?? Is it like the "cookie" in the web??
Philippe Maquet
Bartender

Joined: Jun 02, 2003
Posts: 1872
Hi Leo,
It's just a file signature. You should check its value when you open the file to make sure the file is a data file.
Best,
Phil.
Bharat Ruparel
Ranch Hand

Joined: Jul 30, 2003
Posts: 493
Hello Phil,
I am following up on your explanation. As far as the assignment is concerned, do we just read it from the file and forget about it? Is that what it boils down to?
Thanks.
Bharat


SCJP,SCJD,SCWCD,SCBCD,SCDJWS,SCEA
Philippe Maquet
Bartender

Joined: Jun 02, 2003
Posts: 1872
Hi Bharat,
There is nothing special to do with it according to our instructions. But, as I did, you may think that "identifies this as a data file" means that if you read another value than the one expected, the file you're reading is not a datafile.
So may just skip it or throw an exception.
Best,
Phil.
Bharat Ruparel
Ranch Hand

Joined: Jul 30, 2003
Posts: 493
Hello Phil,
Thanks your your response. I am following up on it. Everytime I read it I get the same value, i.e., 257 (numeric). I have no way of checking if it has been changed.
Do you mean that I should store it in a static variable on my data.java class and everytime I access the data file. I keep checking whether it has been changed? and if it is (at least in theory), then throw an exception? However, if I don't provide a mutator method in my class then it pretty much guarantees that it cannot be changed? Are you thinking of an external program inadverantly modifying this value?
Let me know your thoughts.
Thanks.
Bharat
Philippe Maquet
Bartender

Joined: Jun 02, 2003
Posts: 1872
Hi Bharat,
Do you mean that I should store it in a static variable on my data.java class

You shouldn't but you could
and everytime I access the data file. I keep checking whether it has been changed?

Not each time you access the data file, just once when you open it.
However, if I don't provide a mutator method in my class then it pretty much guarantees that it cannot be changed? Are you thinking of an external program inadverantly modifying this value?

No, I am thinking of a user which makes a mistake (choose any wrong file) when telling your server which file is its database file.
Cheers,
Phil.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: NX:URLyBird What's magic cookie?
 
Similar Threads
NX:About MAGIC flag in the Data file
What is the magic cookie used for?
not to hard code database location
NX:[URLyBird]Focus in the COOKIE
URLyBird: Read data file