How to convert fantom Buf to java byte[]?
brian
23 Mar 2011
Hi
How to convert fantom Buf to java byte[]?
Probably the simplest way:
buf := "hello".toBuf bytes := ByteArray(buf.size) Interop.toJava(buf.in).read(bytes)
If you know you have an ASCII string you might be able to optimize that.
I am Flux user. In 1.0.58 if choose another file in dirtree then dialog window appear in with one button "OK".
Interestingly enough I was using Flux 1.0.58 for like a week and kept noticing something was really weird but couldn't put it my finger on it. But it was a bug in a fix I made to Dialog. If you pull that fix and rebuild fwt it works.
Akcelisto
23 Mar 2011
May be this conversion need to add to Interop:
bytes := Interop.toJava(buf)
tcolar
8 Aug 2012
Related question .... what do I do with a ByteArray ?
I mean I call a java function that returns byte[], I'm left with a fanx.interop.ByteArray .... is there any good way to convert that into a Fantom object, like a Buf ?
I tried Interop.toFan(byteArray) but that fails:
Invalid args toFan([java]fanx.interop::ByteArray?)
tcolar
8 Aug 2012
I guess i could create a java string from the bytearray and get that into a fantom Str .... would that be the best approach ?
hum ... never mind i see i can probably use nio ByteBuffer instead.
brian
8 Aug 2012
The Fantom type ByteArray is byte[] - it just a FFI stub interface.
If you are working in Java, then you can just cast to MemBuf and access the public byte[] field directly
Akcelisto
23 Mar 2011
I want to add simple and small db to my webserver. I choose Berkeley DB. This db need
byte[]as key and as value.In java:
byte[] key = str.getBytes("UTF-8");In fantom:
How to convert fantom
Bufto javabyte[]?PS. In Firefox 4.0: green method signatures disappear in fantom doc. http://i18.fastpic.ru/big/2011/0323/9e/ed6fc88ac5b07cafa11736ee67e7bf9e.png
PPS. I am Flux user. In 1.0.58 if choose another file in dirtree then dialog window appear in with one button "OK". If press on it then file is not saved. I rollback to 1.0.57.