Fix the truncate_utf8 so it also works on jruby

* will report an issue on github.com/jruby/jruby with title:
  "test".encode("UTF-16BE", :invalid => :replace, :replace =>"") fails