Search code examples
javastringjruby

JRuby: Create Java InputStream or byte[] from RubyString


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?


Solution

  • Found it: org.jruby.RubyString#to_java_bytes.