Created
January 25, 2013 02:09
-
-
Save hakanai/4631108 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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