Groovyで日本語表示
Groovyは日本語を受け付けてくれない。
>groovysh Lets get Groovy! ================ Version: 1.0-beta-3 JVM: 1.4.2-b28 Hit carriage return twice to execute a command The command 'quit' will terminate the shell groovy> print "ほげ" groovy> ???°null groovy>
なので、ソースを調べてみた。単純に、InputStreamReaderをつかってないからだった。以下のように適当に変更(デフォルトエンコーディングに頼った)したらちゃんと表示できるようになった。
package org.codehaus.groovy.syntax.lexer; import java.io.InputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; public class InputStreamCharStream extends AbstractCharStream { private InputStream in; private InputStreamReader reader ; public InputStreamCharStream(InputStream in) { this.in = in; this.reader = new InputStreamReader(in) ; } public InputStreamCharStream(InputStream in,String description) { super( description ); this.in = in; this.reader = new InputStreamReader(in) ; } public InputStream getInputStream() { return in; } public InputStreamReader getInputStreamReader() { return reader; } public char consume() throws IOException { return (char) getInputStreamReader().read(); } public void close() throws IOException { getInputStreamReader().close() ; getInputStream().close(); } }
な感じ。
>groovysh Lets get Groovy! ================ Version: 1.0-beta-4-snapshot JVM: 1.4.2-b28 Hit carriage return twice to execute a command The command 'quit' will terminate the shell groovy> print "ほげ" groovy> ほげnull groovy>
本当は引数で encodingを指定したいのだが、groovy script.groovy args になっているのでいろいろいじらないと渡せない。
英語力がないのでどうすればここら辺をうまく伝えればいいのかわからずほっぽっている。。。