Forum: JRuby How to pass file contents in ruby as inputstream to Java

77bd435212b88949704a87792c48990e?d=identicon&s=25 Ravi Gudipati (rgud)
on 2014-03-13 21:30
My Java method is expecting DataInputstream as argument. I need to read
file contents in ruby and call that Java method with these contents.

contents = IO.read('filename')
JavaObj.method(datainputstream)

How to convert contents (string) to inputstream?

Please help.
B05d3cbc64b0031a24c2887fb6ddc173?d=identicon&s=25 christian (Guest)
on 2014-03-13 21:50
(Received via mailing list)
I would use something like

java.io.DataInputStream.new(java.io.ByteArrayInputStream.new(content.to_java.bytes))

-christian
C37cb1a6a19e23f067aae6ccb2d0de4b?d=identicon&s=25 Manuel Ramos Caro (Guest)
on 2014-03-13 22:10
(Received via mailing list)
Hi, its not the same but i remenber to read about this and take this
solution to read a image resource from a jar and write it to a profile
dir. Basically i use a java class to read and other to content the
readed image. I think code that can solve your problem can look similar
to this.

class ConfigWebResources
def initialize
@web_resource1_name = Dir.home.to_s + "/.rmldonkey/log6.png"
if File.exists?(@web_resource1_name)
puts @web_resource1_name + " resource readed..."
else
is = Java::BufferedImage.new
is =
javax.imageio.ImageIO.read(java.lang.Object.new.java_class.resource("/log6.png"))

javax.imageio.ImageIO.write(is,"png".to_java,
java.io.File.new(@web_resource1_name))
puts @web_resource1_name + " resource write..."
end #if File.exists?(@web_resource1_name)
end #def configWebResources
end #class ConfigWebResources




Manuel Ramos Caro.
Coding on JRuby for fun.

http://sourceforge.net/p/rmldonkey

Regards


El 13/03/14 21:30, Ravi Gudipati escribi??:
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.