Error in String.getBytes() ?

jzuidema:
Hmmm ok, dont wanna argue, but the way I did it consistently yields the correct result (varying String size/chars)

Except it doesn't, does it? You said that one of your attempts truncated the string, and the other one appended a spurious space. Both of these are direct consequences of the bugs in the way you declare the array and copy the received bytes in it.

I suggest you drop all use of the String class and use plain old c-strings (null-terminated char arrays). It's no harder than using Strings, avoids the possibility of memory corruption introduced by the String class, and avoids the messy copying between Strings and c-strings which is causing you the problem here.