Skip to content

Instantly share code, notes, and snippets.

@hakanai
Created January 25, 2013 02:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hakanai/4631108 to your computer and use it in GitHub Desktop.
Save hakanai/4631108 to your computer and use it in GitHub Desktop.
1. java -classpath jruby-complete.jar;. org.jruby.Main test.rb
I would expect this to work, but JRuby for whatever reason converts Unicode strings
to windows-1252 internally, so you get question marks. No surprises there, and I have
already raised a separate ticket about that anyway.
Output:
encoding of the stream:
encoding of the string: Windows-1252
2. java -Dfile.encoding=UTF-8 -classpath jruby-complete.jar;. org.jruby.Main test.rb
This is supposed to be the workaround. Now you get non-question mark output, but not UTF-8 either.
Output:
encoding of the stream:
encoding of the string: UTF-8
3. java -Dfile.encoding=UTF-8 -classpath jruby-complete.jar;. org.jruby.Main -Eutf-8 test.rb
This is the suggested thing to try to see if it fixes it. Exactly the same behaviour as #2.
public class Test
{
public String getValue()
{
// forgive the Japanese South Park example...
return "\u30D1\u30F3\u30C4\u3092\u96C6\u3081\u308B\u7B2C\u4E00\u6BB5\u968E\u30D1\u30F3\u30C4\u306E\u53CE\u96C6\u30FC\uFF01";
}
}
require 'java'
obj = Java::Test.new
File.open('out.txt', 'w') do |io|
puts "encoding of the stream: #{io.external_encoding}"
str = obj.value
puts "encoding of the string: #{str.encoding}"
io.puts(str)
end
@enebo
Copy link

enebo commented Jan 25, 2013

Ok so something significant happened on master since JRuby 1.7.2 was released. I get this to work with:

jruby -J-Dfile.encoding=UTF-8 test.rb

So we fixed some internal encoding issue with Windows since 1.7.2 was released. The file.encoding is required because apparently windows uses Window-1252 by default. I suspect had you been on Windows-1252J this somehow would have been able to transcode these chars to Java Charset.

We (JRuby) really need to consider making JRuby run file.encoding=UTF-8 all the time on windows (at least as a default)....

@d1egoaz
Copy link

d1egoaz commented Mar 22, 2013

tks, I spend several hours trying to find the bug, i was on 1.7.1, after 1.7.3 i can save the files with UTF-8 encoding.
tks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment