aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes NX: Update Record - padding problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "NX: Update Record - padding problem" Watch "NX: Update Record - padding problem" New topic
Author

NX: Update Record - padding problem

Terry Martinson
Ranch Hand

Joined: Oct 18, 2003
Posts: 293
After I do an update to the database file, I read it again and print it out.
Before my update, when I print results of name field, it looks fine (i.e. no weird characters at the end). However, after my update, I get weird characters at the end. These weird characters do not show up in Notepad, but do show up when I use the Programmers File Editor tool. Updates for all my fields work fine with the exception of the weird characters at the end. (i.e. I am not just off by a few bytes for each field.)
When I read the initial file and print out an unused ending byte from one of the string fields, it prints out as 0. Also, when I print out the 1st element of my "just initialized" fully padded byte array below, that also shows up as 0. So I thought I would be in synch. Note that my specs say data is "null terminated if less than the maximum length for the field".
Here is my pseudo code for the update:

Do I need to explicitly pad the fullyPaddedByteArray above with something
for null? If so, what character sequence represents null for a primitive byte?
Any help appreciated. Thanks.
TJ


SCJP, SCJD, SCWCD, SCBCD
Dushy Inguva
Ranch Hand

Joined: Jun 24, 2003
Posts: 264
TJ,
I've had the exact same problem. I pad the difference with null bytes which are 0.
byte nullByte = (byte)0;
Dushy


SJCP, SCBCD, SJCD, SCDJWS, SCEA (Part I)
Terry Martinson
Ranch Hand

Joined: Oct 18, 2003
Posts: 293
Thanks Dushy. I'll do that
TJ
Terry Martinson
Ranch Hand

Joined: Oct 18, 2003
Posts: 293
I tried that approach and unfortunately I'm still getting those strange characters. Here is what I added (after the System.arraycopy and before the write to the file.

Any ideas on what else might be goofing me up?
Thanks.
TJ
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
I have just simply fill up the String with "space", instead of null, since I can use String.trim() to remove those padding spaces.


SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
Terry Martinson
Ranch Hand

Joined: Oct 18, 2003
Posts: 293
Do you think the space approach would lose marks though, since my spec says: "... data is "null terminated if less than the maximum length for the field".
Space approach sounds reasonable, but I'd hate lose points (or even worse auto fail) because of it.
Thoughts???
TJ
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
Since I cannot find the "MUST" keyword in that paragraph, I guess the null terminated requirement is not stictly enforced.
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11481
    
  94

Nicholas / Terry,
You might be interested in Gareth Knowles's email to Sun and their response regarding spaces versus nulls .
Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Terry Martinson
Ranch Hand

Joined: Oct 18, 2003
Posts: 293
Thanks Andrew!
TJ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NX: Update Record - padding problem