It is much easier to use a triple quote Str or a Str DSL than escaping all those quotes. And now you can use sys::Str.in to turn any string into an InStream:
fansh> using json
Add using: using json
fansh> Json.read("""{"foo":"bar"}""".in)
[foo:bar]
You can create your own subclasses of InStream/OutStream, but in general you will use these methods (especially during testing):
You can also get I/O streams from TcpSocket, UdpSocket, WebClient, WebReq, and WebRes.
I think I/O in Fantom is pretty slick b/c we boil everything down to one InStream class and one OutStream class, and we make it really easy to get an I/O stream from anything that makes sense.
DanielFathSat 28 Nov 2009
Thanks a bunch. I didn't know each Str had its own Str.in method, I just kept looking in InStream for a method that returns Str (presumably in static context).
DanielFath Sat 28 Nov 2009
After playing with
json
I kinda grew tired of messing with In/Out streams so I'm looking for a quick way out. I'm sure this example is quite outdated:From: Json
This is as far as I've got:
So the question is since In/Out Stream have protected constructors, how are we supposed to create in/out streams that can be serialized with Json?
brian Sat 28 Nov 2009
Sorry about the docs being outdated, it should read:
It is much easier to use a triple quote Str or a Str DSL than escaping all those quotes. And now you can use
sys::Str.in
to turn any string into an InStream:You can create your own subclasses of InStream/OutStream, but in general you will use these methods (especially during testing):
sys::Str.in
: read in-memory stringsys::StrBuf.out
: write in-memory stringsys::Buf.in
: read in-memory buffersys::Buf.out
: read in-memory buffersys::File.in
: read file (or zip entry)sys::File.out
: read file (or zip entry)You can also get I/O streams from TcpSocket, UdpSocket, WebClient, WebReq, and WebRes.
I think I/O in Fantom is pretty slick b/c we boil everything down to one InStream class and one OutStream class, and we make it really easy to get an I/O stream from anything that makes sense.
DanielFath Sat 28 Nov 2009
Thanks a bunch. I didn't know each Str had its own Str.in method, I just kept looking in InStream for a method that returns Str (presumably in static context).