Re: [jruby-user] Reading binary Files
Christian MICHON <[email protected]>
| Newsgroups | gmane.comp.lang.jruby.user |
|---|---|
| Message-ID | <CACx2yF_U=y5fFN_x6SgYyvn-M+pX0+JAV7gxmq-6P9UDtq8mLg@mail.gmail.com> |
Strange: based on your code, it should warn you that File is already defined by ruby. "warning: already initialized constant File" You need to perform at least a :remove_const on Object prior to any java class import. Like this: Object.send(:remove_const,:File) # put this as 1st line Next error... NameError: no method 'read' for arguments (org.jruby.RubyString) on Java::JavaIo::FileInputStream Explanation: your buffer is actually a ruby string, not a byte[]. Possible fix: buffer = [].to_java(:byte) I did not check the rest of HBase related code. Good luck! On Sat, Oct 4, 2014 at 11:38 PM, Roger Palma <[email protected]> wrote: > Hi there > I am trying to read a binary file using Java's "FileInputStream" to > later store it in HBase. > > My problem is the byte-array conversion needed to call the read-method: > > inFile = File.new("/home/roger/Downloads/test.jpg") > inputStream = FileInputStream.new(inFile) > > length = inFile.length() > buffer = "" > > inputStream.read(buffer) > > > Any Ideas? > > You may find the entire code in the attachment. > > Thanks > Roger > > Attachments: > http://www.ruby-forum.com/attachment/10139/test.rb > > > -- > Posted via http://www.ruby-forum.com/. > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > > -- Christian