Socketから送られてくるUTF-8なデータをScala(Java)のUnicodeで使う。
ScalaでUTF-8な文字コードが設定されているIRCサーバ(のチャンネル)と通信したいときなど、エンコーディングが統一されていない場合はInputStreamReaderを頼って第二引数に文字コードを指定しましょう。
import java.io._ val in = new BufferedReader(new InputStreamReader(sock.getInputStream(), "UTF-8")) var line = in.readLine() while (line != null) { serverMsg(line) line = in.readLine() }
An InputStreamReader is a bridge from byte streams to character streams: It reads bytes and decodes them into characters using a specified charset. The charset that it uses may be specified by name or may be given explicitly, or the platform's default charset may be accepted.
http://download.oracle.com/javase/1.5.0/docs/api/java/io/InputStreamReader.html