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
posted
0
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
posted
0
Hello All, I got the answer for post one. Thanks. But still a bit doubtful regarding second post. Please clarify me. Appreciate it.
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
posted
0
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.