• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

B&S:db format question

 
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Saheed Adepoju
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 267
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 267
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic