aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes NX: null terminated if less than the maximum length for the field 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 "NX: null terminated if less than the maximum length for the field" Watch "NX: null terminated if less than the maximum length for the field" New topic
Author

NX: null terminated if less than the maximum length for the field

Satish Avadhanam
Ranch Hand

Joined: Aug 12, 2003
Posts: 697
Hi All,
I have a question regarding the null termination of text fields. As per the requirements here is what Sun expects

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.


I am reading each character at a time using the read() of RAF. I tried to use something like this

and also like this


But both did'nt work. Each field is read to its maximum length and not breaking out. Please enlighten me. Thanks.

I'm not sure of how a null character is represented. I tried, but could'nt succeed. Can anyone please throw some light on how a null character is represented in db file?
Thanks.
[ February 24, 2004: Message edited by: Satish Avadhanam ]
Satish Avadhanam
Ranch Hand

Joined: Aug 12, 2003
Posts: 697
And one more question, please.
As Sun said all fields are text only, it means that the owner field which is an 8 digit number is also present in the database as text. Am I right? So we also read and write this field as all other fields?
Appreciate your help, thanks.
Satish Avadhanam
Ranch Hand

Joined: Aug 12, 2003
Posts: 697
Hello All, I got the answer for post one. Thanks.
But still a bit doubtful regarding second post. Please clarify me.
Appreciate it.
Maria Lepschy
Ranch Hand

Joined: Jan 12, 2004
Posts: 78
Yes, you are right. The owner field is a String like the other fields.
Regards,
Maria
Satish Avadhanam
Ranch Hand

Joined: Aug 12, 2003
Posts: 697
Thanks Maria.
George Marinkovich
Ranch Hand

Joined: Apr 15, 2003
Posts: 619
Hi Satish,
Originally posted by Satish Avadhanam:
I'm not sure of how a null character is represented. I tried, but could'nt succeed. Can anyone please throw some light on how a null character is represented in db file?

A null character is represented in Unicode by '\u0000'. The reason you're not seeing any null characters is that there might not be any null characters in the db file. The relevant quote from the assignment instructions is as follows:

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.

So if you're not finding any null characters that may mean that there aren't any to find. In other words all the fields contain the maximum length for the field. In practice what this means is that the creator of the database file seems to have right-padded each field with spaces, rather than using nulls.
It's not clear to me that this makes any practical difference to your application. I basically ignored the null issue. In other words, if a field value (having a 64 byte length) had the value "Dogs With Tools " I basically treated it within my application as if it were "Dogs With Tools" by using String.trim(). For the purposes of trim the null character and a blank space are both considered white-space and trimmed accordingly. The null character has no particular meaning within the db file. Fields are all fixed-length so they can be read using raf.read(byte[]) (which I would recommend over reading byte-by-byte, by the way) and then trimmed.
Regarding the owner field, yes it is like all the other fields.


Regards, George
SCJP, SCJD, SCWCD, SCBCD
Satish Avadhanam
Ranch Hand

Joined: Aug 12, 2003
Posts: 697
Originally posted by George Marinkovich:
Hi Satish,
So if you're not finding any null characters that may mean that there aren't any to find. In other words all the fields contain the maximum length for the field. In practice what this means is that the creator of the database file seems to have right-padded each field with spaces, rather than using nulls.

Thanks George, I just have gone through the issue in previous threads also and they have said the same thing as you did.

It's not clear to me that this makes any practical difference to your application. I basically ignored the null issue. In other words, if a field value (having a 64 byte length) had the value "Dogs With Tools " I basically treated it within my application as if it were "Dogs With Tools" by using String.trim(). For the purposes of trim the null character and a blank space are both considered white-space and trimmed accordingly. The null character has no particular meaning within the db file.

Ok George, I got the idea now.

Fields are all fixed-length so they can be read using raf.read(byte[]) (which I would recommend over reading byte-by-byte, by the way) and then trimmed.
Yes, now I will try to implement it using the read(byte []) instead of reading byte-by-byte. Thanks.

Regarding the owner field, yes it is like all the other fields.
Ok George.

George, many thanks finally
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NX: null terminated if less than the maximum length for the field
 
Similar Threads
URLyBird's [Version 1.2.3]
Must end with null?
NX: db.db file format
NX: Null terminated
.db file format problem, help please!!!