aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes About the null termination (UB 1.3.3) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "About the null termination (UB 1.3.3)" Watch "About the null termination (UB 1.3.3)" New topic
Author

About the null termination (UB 1.3.3)

Jari Timonen
Ranch Hand

Joined: Jan 16, 2004
Posts: 232
Ok, i've searched, tried and tried. I still can't get null termination right:

Choises:
char c = '\u0000'
byte b = 00000000;
String s = new String(byte[]{00000000}, "US-ASCII");

I write them back to file as byte-array. They just print out as "boxes" when i re-read them. (data is ok still, but null termination is someshow messed up)


Can somebody bend me a wire?


SCJP 5.0, SCJD URLyBird 1.3.3, OCMJEA 5 (SCEA) Factory Homes
Jari Timonen
Ranch Hand

Joined: Jan 16, 2004
Posts: 232
Allright, i've come to conclution, that i'm doing everything correctly. I checked with hex editor and indeed my null terminators are: 00 00 00 ..
But, the file contains 20 20 20 .. that is a space.

I'll go what the specs says:

null terminated if less than the maximum length for the field. The character encoding is 8 bit US ASCII.

Alex Belisle Turcot
Ranch Hand

Joined: Apr 26, 2005
Posts: 516
Jari Timonen wrote:Allright, i've come to conclution, that i'm doing everything correctly. I checked with hex editor and indeed my null terminators are: 00 00 00 ..
But, the file contains 20 20 20 .. that is a space.

I'll go what the specs says:

null terminated if less than the maximum length for the field. The character encoding is 8 bit US ASCII.


The spec explicitly says to end with null terminator. However, it also says to support the database file.. You must be able to handle records padded with white spaces...
I documented that the spec was contradictory, that other application were possibly using the database file and could be unable to handle another padding character.. I chose to use "blank space" to @null terminated@ my records
Another choice could be to replace spaces by null value as you modify the records..

I think the only wrong choice is not being able to handle spaces terminated records since that's how the database is by default.

Alex
Jari Timonen
Ranch Hand

Joined: Jan 16, 2004
Posts: 232
Alex Belisle Turcot wrote:
The spec explicitly says to end with null terminator. However, it also says to support the database file.. You must be able to handle records padded with white spaces...
I documented that the spec was contradictory, that other application were possibly using the database file and could be unable to handle another padding character.. I chose to use "blank space" to @null terminated@ my records
Another choice could be to replace spaces by null value as you modify the records..

I think the only wrong choice is not being able to handle spaces terminated records since that's how the database is by default.

Alex



Handling the termination is just trivial issue, String.trim() makes the trick.

You've got point there. The other program might not know how to handle null terminations. I've got to think about it Thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: About the null termination (UB 1.3.3)