• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 697
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 697
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All, I got the answer for post one. Thanks.
But still a bit doubtful regarding second post. Please clarify me.
Appreciate it.
 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, you are right. The owner field is a String like the other fields.
Regards,
Maria
 
Satish Avadhanam
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Maria.
 
Ranch Hand
Posts: 619
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Satish Avadhanam
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
That is a really big piece of pie for such a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic