File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes NULL in db-file. 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 "NULL in db-file." Watch "NULL in db-file." New topic

NULL in db-file.

Allan Smith

Joined: Aug 18, 2005
Posts: 16

I'm currently in the process with the B&S assignment. Trying to read from the file is my main concern right now to get an understanding of the file format. However, I'm getting this strange error, or I'm misunderstanding someting critical which you maybe can help me with.

This is what my spec looks like:

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, 0xFF 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

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.

Now, I've manages to read in the header names, and their lenghts. What I do after that point is to save the filepointer, and start reading the data according to the column lengths and then type them out just to see that I'm on the right way. And yes, They print nicely except for one thing; a null value which now and then suddenly appears in the middle of the file, and then on the end of the file next time I run my test application, and so on. Has this something to do with the bold text above? What did I misunderstand?

Thankx in advance!
Allan Smith

Joined: Aug 18, 2005
Posts: 16
Never mind the null. I seem to have found the problem. Still need an explanation on the bold text above, since I obviously don't get it.
Daniel Dalton
Ranch Hand

Joined: Mar 20, 2005
Posts: 146
Take a look at the original file you were supplied in a binary text editor to see if there are any nulls in it. Ordinarily, you'd go back to the customer and ask about it, and they'd probably say "oh - sorry, that bit's wrong..."

I'd just document that the file format differs slightly from the spec, so you decided to assume that Strings are NOT null terminated. I think some bits of the instructions are meant to be deliberately iffy!
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11778

Hi Allan & Daniel,
Originally posted by Daniel Dalton:
Ordinarily, you'd go back to the customer and ask about it, and they'd probably say "oh - sorry, that bit's wrong..."
I recommend against candidates asking Sun questions about this, but it has happened in the past.

Regards, Andrew

The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
I agree. Here's the link:
subject: NULL in db-file.
It's not a secret anymore!