This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "NULL in db-file." Watch "NULL in db-file." New topic
Author

NULL in db-file.

Allan Smith
Greenhorn

Joined: Aug 18, 2005
Posts: 16
Hi!

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
Greenhorn

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: 11278
    
  59

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: http://aspose.com/file-tools
 
subject: NULL in db-file.
 
Similar Threads
how to read data from db file
NX:[URLyBird]Small case about numeric type
NX:[URLyBird]Get the correct field values
Data file Format question
Last Record in Database File