my dog learned polymorphism
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes B&S database file format 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 database file format" Watch "B&S database file format" New topic

B&S database file format

hatim osman
Ranch Hand

Joined: Jun 10, 2005
Posts: 105
Hi there...
I have 2 questions about the database file format:

it says :

All text values, and all fields (which are text only) conatins only 8 bit characters, null terminated if less than the maximum length for the field.

1. Does the null terminated thing applies to both the text values in the schema "Filed Names", and the actual record text values. The statement above,"All text values, and all fields (which are text only)" , is confusing, I don't know what do they exactly refer to.
2. after Fully Reading the text value, do we have to truncated when there is a null character in it? Because I was able to read the file but then, although the first field is less than the length specified in the schema, it wasn't terminated with null, instead padded with spaces. I am confused now between fully reading the record or reading one byte at a time until the null character is read or the length of the field is reached.

Thanx in advance
Jan Groth
Ranch Hand

Joined: Feb 03, 2004
Posts: 456

if you search in the forum, you'll find several post, one an original quote from sun, saying that null termination is not to be kept strict and that space padding will be okay ;-)

hope that helps,
hatim osman
Ranch Hand

Joined: Jun 10, 2005
Posts: 105
Hi there...
Thanx, I was able to find the thread you refered me to. Now, this is what I understood please correct me if I am wrong:

1. I should Fuly Read the field :

2. I should assume that, if the field text value is less than the maximum length, then it's padded with spaces and not terminated with null. "null character doesn't exist"

3. when writing fields back to the file, I should pad them with spaces only, and not terminate them with null and then pad them with spaces, in case they are less than their respective lengths.

4. I should not bother finding out whether the field conatins null character or no.

5. when creating the String:
String (byte[], charset)
this will work fine, but then I should trim the String to preserve resources in case it's padded with spaces.

6. when the field that points to the availability of the record for booking is blank, all chracter are spaces?

7. I am worried that my assumptions will not work when tested using the Automatic Software test harness at Sun.

Please correct me if I am wrong. I stopped developing 'cause of this issue. I can handle both, but it seems like I cannot understand the specification correctly. Please guide me guys.

thanx in advance
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11778

Hi Hatim,

I think your assumptions look reasonable - just make sure you document them in your design decisions document.

As a side note: it is my understanding that Sun do not have a test harness (yes, I do know that this contradicts what they say in their instructions). They do have automated tests that will confirm basic structure of your submission / method signatures of specified interfaces and classes, but that is as far as it goes. There has been some speculation that a test harness was too difficult to generate since Sun have not specified a constructor for the Data class (and there are many different constructors possible).

Regards, Andrew

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

Joined: Jun 10, 2005
Posts: 105
Hi there...

Check this reply from Sun "Exact Words from Sun":

Sorry about the misprint. (By the way we have fixed the problem.) Yes, please treat the file as space-padded, not null-terminated.

It's very clear, I will also add this message to my cohices.txt file. I am posting this and I would like to ensure the credibility and authenticity of this message.

I agree with you regarding the test harness thing. As if you were able to read my mind. My class has a private constuctor and a getInstance() method, and I was thinking in case this class is automatically tested then how would they create an instance of it dynamicly. But your words moved a huge load off my back. Thanx Andrew and of course everybody in this forum for your constant support.

I agree. Here's the link:
subject: B&S database file format
It's not a secret anymore!