Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

All numeric values are stored in the header information

 
paul seldon
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Header Information"
Is it from the start of the file to right before schema section,
right? When I print *.db file it comes out like below :
------------------------------------------------------------------------
< Instruction.html >
-> Start of file
4 byte numeric, magic cookie value. Identifies this as a data file
4 byte numeric, total overall length in bytes of each record
2 byte numeric, number of fields in each record

Schema description section.

------------------------------------------------------------------
< Result after reading dataInputStream>

Cookie value(4Byte) : 513
OveralLength(4Byte) : 183
NumberOfField(2Byte): 6

Each Record has :
name : 32
location : 64
specialties : 64
size : 6
rate : 8
owner : 8
Head Size : 70
----------------------------------------------------------------

70 means what? 70 byte for all header information?
How should I think of this?

Let me know. Thanks -
 
Benjamin Wang
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes

We have same magic cookie value and header length.
 
Keith Jones
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wonder how you came to that cookie value. Mine is:

first byte: 0
second byte: 0
third byte: 2
forth byte: 3

I was also wondering if we have to check this value whenever reading the file. In other words do we have to say:

if (magicCookieValue equals "something") {
proceed
}
else {
error
}
 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

A small tip - uses a hex editor to peek in to the db file, you'll easily get your cookie.
The cookie purpose is to identify a valid database file, this because each database can have a different structure, by example in my scheme :

1 byte flag. 00 implies valid record, 0xFF implies deleted record


but I know other scheme with different values.

Regards M
 
Mark Smyth
Ranch Hand
Posts: 288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Keith Jones:
I wonder how you came to that cookie value. Mine is:

first byte: 0
second byte: 0
third byte: 2
forth byte: 3

I was also wondering if we have to check this value whenever reading the file. In other words do we have to say:

if (magicCookieValue equals "something") {
proceed
}
else {
error
}


You need to read the four bytes together as an integer value rather than as 4 consectutive bytes to get the magic cookie value. Use the readInt() method to do this.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!