Win a copy of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Bear Bibeault
  • Liutauras Vilda
  • Devaka Cooray
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

All numeric values are stored in the header information

 
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 -
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes

We have same magic cookie value and header length.
 
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
}
 
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
 
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.
 
Forget this weirdo. You guys wanna see something really neat? I just have to take off my shoe .... (hint: it's a tiny ad)
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!