Last Updated: February 25, 2016
·
834
· nuvan

Jruby (Java) Encoding for LATIN-1 victims and how to detect issues

Once upon a time, I was developing a couple of extensions for Logstash Link.

One of my input extensions, connected to a SQLServer via JDBC driver and it all worked fine in my OSX machine. But then, an evil Red Hat Enterprise server appeared, and it started to mess with all of my good encoding JVM flags (that I didn't even know that they existed).

After some suffering, anger and hunger that all debugging processes bring, I've found an ancient JVM flag that my evil Red Hat server changed, just to see me cry after several bad relationships with an assorted number of encodings.

sun.io.unicode.encoding=UnicodeBig (on my OSX)

sun.io.unicode.encoding=UnicodeLittle ( on my Red Hat)

Loading up my JVM with -J-Dsun.io.unicode.encoding=UnicodeLittle saved the day.

By the way, if you ever want to check your encoding flags just add this to your JRuby script:

require 'java'

java_import java.util.Locale
java_import java.util.Properties
java_import java.util.Enumeration
java_import java.lang.System

{assorted code}

p = System.getProperties();
keys = p.keys();
keys.each do |key|
  value = p.get(key);
  puts "#{key} : #{value}"
end

With this script you can print all of your JVM instance flags