File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes B&S:db format question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "B&S:db format question" Watch "B&S:db format question" New topic
Author

B&S:db format question

Saheed Adepoju
Ranch Hand

Joined: Jun 23, 2004
Posts: 267
Hi all
I started looking @ my datafile yesterday and was able to get my Magic cookie and the information @ the start of the file with the following code:
(Pls if i violate any policy, I apologise and you may edit or remove the post).
My data format goes thus:



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.
Repeated for each field in a record:
2 byte numeric, length in bytes of field name
n bytes (defined by previous entry), field name
2 byte numeric, field length in bytes
end of repeating block

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

End of file



Now my little confusion,
My assignment version is 2.1.1 and i hear that your magic cookie value was tied to the version of your assignment!
Well the output was

Magic Cookie value : 513
Total Length : 182
Field Size : 6

I was expecting a magic cookie value of like 211!(Was just expecting: I do hope i read it correctly) If the total length is 182 does it include the marker that says:

Repeat to end of file:
1 byte "deleted" flag. 0 implies valid record, 1 implies deleted record


I know i have to find a method of RandomAccessFile to be able to read in the field name after i have skipped the
2 byte numeric, length in bytes of field name

And also i have another(might sound stupid though funny). Is it possible to get a diagrammatic representation of what happens when u read a file say with the readInt() method, i know it skips after it reads! Or a file in general when u have a pointer and are reading from it! Anyways, all i am asking for is a push in the right directions! Thanks all!


Saheed Adepoju<br />SCJP 1.4<br />SCJD (B&S..In progress)
Saheed Adepoju
Ranch Hand

Joined: Jun 23, 2004
Posts: 267
Hi
I just got an insight into how to solve reading the field name from another post! But still feel free to post your answers but i just got a head on! Will stay in touch!
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11525
    
100

Hi Saheed
My assignment version is 2.1.1 and i hear that your magic cookie value was tied to the version of your assignment!
Well the output was

Magic Cookie value : 513
Total Length : 182
Field Size : 6

I was expecting a magic cookie value of like 211!(Was just expecting: I do hope i read it correctly) If the total length is 182 does it include the [delete flag].
The magic cookie does appear to be tied to the version number, but in a funny way. It appears that the magic cookie is the hexadecimal representation of your assignment version number, without the middle digit. So, since you have assignment version 2.1.1 I would expect you to have a magic cookie of 0x0201 which in decimal = 513

I think the length excludes the delete flag - you should have the field sizes listed in your instructions - add them up. If they add up to 182 then the length does not include the delete flag .

Is it possible to get a diagrammatic representation of what happens when u read a file say with the readInt() method, i know it skips after it reads!
Sorry, I don't understand what you are asking for here.

Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Saheed Adepoju
Ranch Hand

Joined: Jun 23, 2004
Posts: 267
Hi
Thanks alot for your insight! And my request for the "SERVER" header thing i think was answered in the url you gave! Thank you
Saheed Adepoju
Ranch Hand

Joined: Jun 23, 2004
Posts: 267
Hi


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

I have been able to read the field names ! Now i added up the field lengths and it corresponded to what i got when i read it from the file(Expected though)! My concern is the above statement from the schema, is the 1 bytein the beginning or @ the end of the file and again it says that.. no separators between fields, each field fixed length at maximum specified in schema information, i am getting the feeling all the information are jumbled together , it this right?
My guess would be to get the records is the following pseudocode(according to my schema):



I do hope i am making some sense! I just need some directions.. Thank u!
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11525
    
100

Hi Saheed,

I have been able to read the field names !
Excellent

My concern is the above statement from the schema, is the 1 bytein the beginning or @ the end of the file and again it says that.. no separators between fields, each field fixed length at maximum specified in schema information, i am getting the feeling all the information are jumbled together , it this right?
As mentioned in another topic recently - it is quite possible that Sun are deliberately trying to emulate clueless spec-writers

Perhaps if we psuedo-draw it:Does that help?

As shown above, and as described in the text description, the delete flag is going to be inside the repeated section. So there will be one delete flag per record.

Regards, Andrew
Saheed Adepoju
Ranch Hand

Joined: Jun 23, 2004
Posts: 267
Cool, now a litlt problem while i was trying to read it in!
If my code below violates anything pls edit or delete code: Here it goes:

The output i do get is funny:


name
byte flag 0
ocation @ ?specialties @ ?size ? ?rat ?owner Buonarotti & Company
Smallville Air Conditi
oning, Painting, Painting 10 $40.00 Swan
ders & Flaughn Smallville
Painting, Air Conditioning 7
$55.00 Moore Power Tool Ya Whoville
Air Conditioning
7 $65.00 Hamner & Tong Whovil
le Roofing, Carpets, Elec
trical 9 $90.00 Bitter Homes &
Gardens Metropolis
Electrical, Plumbing 5 $45.00
Buonarotti & Company Metropolis
Heating, Carpets
4 $75.00 Hamner & Tong Pleasantville
Drywall
5 $90.00 Bitter Homes & Gardens
Pleasantville Drywall, E
lectrical, Carpets 5 $50.00 Bit
ter Homes & Gardens Digitopolis
Electrical 4
$55.00 Fred & Nobby Digitopolis
Roofing
3 $75.00 Dogs With Tools Digit
opolis Electrical, Glass, Gl
ass 3 $75.00 Moore Power To
ol Ya Atlantis
byte flag 32
null
Magic Cookie value 513
Total Length 182
Field size 6


Though the output was scattered about the DOS window;Funny, i imagined i would get something cleanly printed! I know now that the byte flag appears in the beginning of each record ! How do i cleanly print this or better still keep the records in a clean format! I know i am close, i would just require a bit of a push as usual! Thanks!
[ October 01, 2005: Message edited by: Saheed Adepoju ]
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11525
    
100

Hi Saheed,

You really need to follow a coding standard for this project - you will loose a great many marks if you do not. I recommend you follow the Sun Code Conventions for the Java Programming Language.

When I reformatted the indentations for your code using that standard, it looks like:I can then see that you have put the Data section inside the loop for the Schema section. That is, your code has:Whereas you should have:Regards, Andrew
[ October 01, 2005: Message edited by: Andrew Monkhouse ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: B&S:db format question