How to avoid null character comes on setLength method on string buffer without using trim()