This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Null-terminated data entries. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Null-terminated data entries." Watch "Null-terminated data entries." New topic
Author

Null-terminated data entries.

Anton Golovin
Ranch Hand

Joined: Jul 02, 2004
Posts: 476
Hi, guys!

My assignment says that if an entry in the data file is less than the maximum length specified for that entry, it is null-terminated. However, in the original data file supplied, it is not null-terminated at all! What would be advice for this matter? I am thinking about writing null-terminated strings out, but it is definitely puzzling!


Anton Golovin (anton.golovin@gmail.com) SCJP, SCJD, SCBCD, SCWCD, OCEJWSD, SCEA/OCMJEA [JEE certs from Sun/Oracle]
Mike Vess
Ranch Hand

Joined: Aug 25, 2004
Posts: 41
The entries in my data file is also space filled but the assignment tells me that the entries should be null terminated. What i have done is to null-terminate the values i update/write to database but i always trim the values read from database so a null terminated value will give the same result as a space filled.


What you thought was right today may need a refactoring tomorrow...
Anton Golovin
Ranch Hand

Joined: Jul 02, 2004
Posts: 476
Originally posted by Mike Vess:
The entries in my data file is also space filled but the assignment tells me that the entries should be null terminated. What i have done is to null-terminate the values i update/write to database but i always trim the values read from database so a null terminated value will give the same result as a space filled.


May I ask what you put as the null-terminator? Is it a zero or a "\0"? And how do you write them, as a char turned to byte?

Thanks for your reply.
peter wooster
Ranch Hand

Joined: Jun 13, 2004
Posts: 1033
Originally posted by Anton Golovin:


May I ask what you put as the null-terminator? Is it a zero or a "\0"? And how do you write them, as a char turned to byte?

Thanks for your reply.


The data in the file is bytes not chars, so the termination value is byte 0.
Robert Chisholm
Ranch Hand

Joined: Jul 18, 2004
Posts: 69
My data is not null terminated either, and my assignment says:


"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."


It doesn't say anything about "should be".

However, that statement (IMO) implies that it can be... which is an easier process than padding out a field with blanks to make it fit the size constraints of the record.


SCJP 1.4<br />(WIP) SCJD B&S v2.3.3
Anton Golovin
Ranch Hand

Joined: Jul 02, 2004
Posts: 476
So would it be safe to ignore this? I am not sure, but it has no must, and it seems to describe existing data...
Robert Chisholm
Ranch Hand

Joined: Jul 18, 2004
Posts: 69
Anton,

I'm doing what Mike Vess is doing (see above). It seems like the safest bet (but who knows -- it might be a candidate for choices.txt).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Null-terminated data entries.
 
Similar Threads
NX: US-ASCII confusion
Trimming values?
URLyBird DB Null Terminated Values
NX (Contractors): Encoding instructions unclear?
ServerSocketChannel.accept() seems to create a random port to send data to?