Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NX: Update Record - padding problem

 
Terry Martinson
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Dushy Inguva
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
TJ,
I've had the exact same problem. I pad the difference with null bytes which are 0.
byte nullByte = (byte)0;
Dushy
 
Terry Martinson
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Dushy. I'll do that
TJ
 
Terry Martinson
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have just simply fill up the String with "space", instead of null, since I can use String.trim() to remove those padding spaces.
 
Terry Martinson
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 11865
194
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nicholas / Terry,
You might be interested in Gareth Knowles's email to Sun and their response regarding spaces versus nulls .
Regards, Andrew
 
Terry Martinson
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Andrew!
TJ
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic