This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of Darcy DeClute's Scrum Master Certification Guide: The Definitive Resource for Passing the CSM and PSM Exams and have Darcy DeClute on-line!
See this thread for details.
  • 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
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

B&S: problem in the db file processing

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm just at the begining of doing the SCJD assignment, and I have some confusion in processing the binary db file sun given.

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
2 byte numeric, number of fields in each record

Schema description section.
Repeated for each field in a record:
1 byte numeric, length in bytes of field name
n bytes(defined by previous entry), field name
1 byte numeric, field length in bytes
end of repeating block

Data section.
Repeat to end of file:
1 byte flag. 00 implies valid record, OxFF implies deleted record
Record contaioning fields in order specified in schema section, no separators between fields, each field fixed length at maximum specified in schema information

End of 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 maxmum length for the field. The character encoding is 8 bit US ASCII.



I'm not fimilar with Java IO, but I'm helped via many relatives threads in Java Ranch(so many thanks! ). I reslove the db file with some results:

1. the Start of file and the Schema section totally occupy 54 bytes
2. each record occupies 183 bytes
3. there're 33 records in the db file

But I don't know how to go the next step to process the db file, any advice ?

Thanks a lot !
 
Dawn T.Y.Lee
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for asking so strange question above...

Now I have dumped the whole data of the db file:



There's still a question ...
The condition of the "for loop" is manully calculated.
So stupid.... but How can I write in another smart way ??



Any advice will be highly appreciated,
Thanks!
 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Dawn - apart from as a test, do you really need to read the whole file? Have a look at the methods in the supplied interface - are they something like

public String [] read(int recno) throws RecordNotFoundException;

??

If they are, have a look at what the seek method of the RandomAccessFile can do for you.
 
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Dawn T.Y.Lee:
The condition of the "for loop" is manully calculated.
So stupid.... but How can I write in another smart way ??



Hi Dawn,

You can use the length() method of RandomAccessFile to determine the file length. Using this value you can calculate how many records exist in the file.

Frans.
 
Dawn T.Y.Lee
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Many Thanks to Daniel and Frans ! I'll try it...Thank you.
 
Hey, I'm supposed to be the guide! Wait up! No fair! You have the tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic