Ruby runtime = context.runtime;
if (!s.respondsTo("to_str")) {
throw runtime.newTypeError("can't convert " + s.getMetaClass() + " into String");
}
ByteList bytes = s.convertToString().getByteList();
ByteBuffer buf = ByteBuffer.wrap(bytes.getUnsafeBytes(), bytes.begin(), bytes.length());
CharsetDecoder decoder;
try {
decoder = Charset.forName("x-JISAutoDetect").newDecoder();
} catch (UnsupportedCharsetException e) {
throw runtime.newStandardError("charsets.jar is required to use NKF#guess. Please install JRE which supports m17n.");