Help coderanch get a
new server
by contributing to the fundraiser
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

How to read MAGIC for db-2x2.db

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The format of data in the database file is as follows:
Start of file
4 byte numeric, magic cookie value identifies this as a data file
4 byte numeric, offset to start of record zero
2 byte numeric, number of fields in each record
How to read MAGIC and what mean about the "4 byte numeric"?
 
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jofer,

How to read MAGIC and what mean about the "4 byte numeric"?


"4 byte numeric" means "int" and you can read it using java.io.RandomAccessFile.readInt().
Best,
Phil.
 
Jofer Chan
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,Philippe:
"2 byte numeric" also uses readInt() method?
 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For "2 byte numeric", use readShort() instead.
Best,
Phil.
 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you use java.io.RandomAccessFile.readInt() and readShort() to read in the db file? I'm asking because sun seemed to be rather specific in their instructions on the format used to read and write from the file: All numeric values are stored in the header information use the formats of the DataInputStream and DataOutputStream classes. All text values, and all fields (which are text only), contain only 8 bit characters, null terminated if less than the maximum length for the field. The character encoding is 8 bit US ASCII. RandomAccessFile implements DataInput/DataOutput just as DataInputStream/DataOuputStream do, but will using RandomAccessFile fulfill the requirement to use the formats within DataInputStream/DataOuputStream??
Dave
 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Dave,

RandomAccessFile implements DataInput/DataOutput just as DataInputStream/DataOuputStream do, but will using RandomAccessFile fulfill the requirement to use the formats within DataInputStream/DataOuputStream??


As RandomAccessFile implements DataInput/DataOutput, it is format-compatible with both DataInputStream and DataOuputStream. So, I would say that yes, you fulfill the requirement by using it. Notice that your instructions just state that "(...) use the formats of the DataInputStream and DataOutputStream classes", not something like "you must use the DataInputStream and DataOutputStream classes to access the file header".
Best,
Phil.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Agreed - there is no requirement to use DataInputStream or DataOutputStream. There is merely the information that the format used is the one used by DataInputStream and DataOutputStream. What you do with that information is up to you.
 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jim,
As I feel well and as we cannot find - for a few days now - any subject on which to disagree with each other, I wonder if you feel ill ... I worry a bit ! Are you still OK ?
Best,
Phil.
 
Dave Knipp
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
cool, thanks Philippe and Jim for both of your responses, i started using RandomAccessFile and it looks alot easier to use than DataInputStream/DataOutputStream.
Thanks!
Dave
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm fine, thanks, PM.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic