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!
Joined: Aug 18, 2005
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.
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!