JRuby: Create Java InputStream or byte[] from Ruby

2019-07-03 18:44发布

问题:

I have a Java method I want to call from JRuby. The argument I want to pass is just a normal string (org.jruby.RubyString), but the Java method is overloaded to take either:

  • java.io.InputStream
  • byte[]
  • com.google.protobuf.ByteString

What's an easy way I can convert my string to an instance of one of those classes?

回答1:

Found it: org.jruby.RubyString#to_java_bytes.