[jruby-user] Re: Reading binary Files
Roger Palma <[email protected]>
| Newsgroups | gmane.comp.lang.jruby.user |
|---|---|
| Message-ID | <[email protected]> |
According to the Ruby Documentation, I just use their "file" class,
since my PDFs (here JPGs) are rather small. This seems to work so far,
but might be slower than a stream-based way. It did well for importing 5
files on my test box, we'll see how it does when running on the real
site with millions of files. Even without my "puts" the HBase shell
produces a lot of messages on screen...
java_import "org.apache.hadoop.hbase.util.Bytes"
java_import "org.apache.hadoop.hbase.client.HTable"
java_import "org.apache.hadoop.hbase.client.Put"
def jbytes(*args)
args.map { |arg| arg.to_s.to_java_bytes }
end
files = Dir.glob("/home/roger/Downloads/*.jpg")
files.each { |x| puts "File #{x}"
inFile = File.new(x)
buffer = inFile.read()
table = HTable.new(@hbase.configuration, "rb_test")
p = Put.new(*jbytes(File.basename(x)))
p.add(*jbytes("inhalt", "", buffer))
table.put(p)
table.close()
}
--
Posted via http://www.ruby-forum.com/.
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email