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.
US-ASCII Seven-bit ASCII, a.k.a. ISO646-US, a.k.a. the Basic Latin block of the Unicode character set
Jacques<br />*******<br />MCP, SCJP, SCJD, SCWCD
My question is:
Is the *8 bit US ASCII* in the instructions the same thing as *US-ASCII Seven-bit*?
I.e. Will this be valid as *8 bit US ASCII*?
Jacques<br />*******<br />MCP, SCJP, SCJD, SCWCD
Jacques<br />*******<br />MCP, SCJP, SCJD, SCWCD
Phil. Thanx again. You should get paid for this.
Do these two methods look like a good way to read a field?
Jacques<br />*******<br />MCP, SCJP, SCJD, SCWCD
Jacques<br />*******<br />MCP, SCJP, SCJD, SCWCD
"null terminated if less than the maximum length for the field."
Since it is a fair assumption that users of the software will only want to see and work with the value of the fields without their padding spaces, I have decided to trim all white space from the values when they are read from the database file. I.e. if a field in the database has the value "123 ", only the value "123" will be returned.
To keep the data format consistent, I have resolved that when field values are written back to the database, they will be padded with spaces up to the length of the field.
Since future formats of the database file might contain null terminated values in the text fields, I have included support for reading values of this format. The value up to the null terminator will be read, and returned after trimming the white space. However, when these values are written back to the database they will be written according to the defacto standard explained above (not with the null terminator, but padded with spaces).
Jacques<br />*******<br />MCP, SCJP, SCJD, SCWCD
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Jacques<br />*******<br />MCP, SCJP, SCJD, SCWCD
Jacques<br />*******<br />MCP, SCJP, SCJD, SCWCD
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
When I pad with spaces, should I first pad and then convert to US-ASCII byte array? Or padd after convert?
Trimming (read) + padding (write) would be a *restriction* to the specs : saving the value "abc " in a 10 characters field would be impossible. While the specs clearly allow it.
Jacques<br />*******<br />MCP, SCJP, SCJD, SCWCD
Jacques<br />*******<br />MCP, SCJP, SCJD, SCWCD
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Have you looked at what java.util.Arrays.fill() and System.arrayCopy() can do for you?
Jacques<br />*******<br />MCP, SCJP, SCJD, SCWCD
"I'm not back." - Bill Harding, Twister
Yes, but given Sun has said Data must implement a particular spec, I think it's safer to be very literal in the interpretation of that spec, and put corrections in other, outside classes.
In the real world, it would be possible that the customer has (or plans to have) other applications which interact with the Data class but may not require or even allow padding/trimming. They didn't mention it in the specs, true, but they did give a precise API to follow. They're not required to explain the reasoning behind all their choicesv - it's enough that they've provided a requirement, and we implement it as written.
a) The file is valid. You've just used the maximum length of the field by padding with spaces and I should do the same. i.e. You are are trying to simulate typical semi-clueless customers, who says one thing but actually means something else.
They said go with (a).
Jacques<br />*******<br />MCP, SCJP, SCJD, SCWCD
"I'm not back." - Bill Harding, Twister
Jacques<br />*******<br />MCP, SCJP, SCJD, SCWCD
Can you hear that? That's my theme music. I don't know where it comes from. Check under this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|