pod util

Utilities

Classes

AbstractMain

AbstractMain provides conveniences for writing the main routine of an app.

BoolArray

Optimized fixed size array of booleans packed into words of 32-bits.

CsvInStream

CsvInStream is used to read delimiter-separated values as specified by RFC 4180.

CsvOutStream

CsvOutStream is used to write delimiter-separated values as specified by RFC 4180.

FileLoc

FileLoc is a location within a text file or source string.

FileLogger

FileLogger appends Str log entries to a file.

FloatArray

Optimized fixed size array of 4 or 8 byte unboxed floats.

IntArray

Optimized fixed size array of 1, 2, 4, or 8 byte unboxed integers.

JsonInStream

JsonInStream reads objects from Javascript Object Notation (JSON).

JsonOutStream

JsonOutStream writes objects in Javascript Object Notation (JSON).

LockFile

LockFile is used to acquire an exclusive lock to prevent two different processes from using same files

Macro

Macro provides a way to replace macro expressions within a pattern using a pluggable implementation for the macro resolution.

PathEnv

PathEnv is a simple implementation of a Fantom environment which uses a search path to resolve files.

Random

Random provides different implementation of random number generators with more flexibility than the methods available in sys.

Facets

Arg

Facet for annotating an AbstractMain argument field.

Opt

Facet for annotating an AbstractMain option field.

Errs

FileLocErr

Exception with a file location

JSON

The json APIs provide basic serialization between Fantom and Javascript Object Notation (JSON). Refer to json.org for more information about JSON.

Type Mapping

JSON types are mapped to Fantom types as follows:

JSON     Fantom
------   --------
object   Str:Obj?
array    Obj?[]
string   Str
number   Int or Float
true     Bool
false    Bool
null     null

In addition when writing Fantom objects the following is supported:

  • Simples are written as a JSON string
  • Serializables are written as JSON objects with each non-static, non-transient field being written as a key/val pair

Writing simples or serializables do not "roundtrip". For example if you write a Date it is written and will be read back as a normal string.

Writing Json

Writing is accomplised via JsonOutStream. To write to standard out:

map := ["key":"value", "intKey":123]
JsonOutStream(Env.cur.out).writeJson(map)

You can also use the writeToStr as a convenience to write to an in-memory string.

Reading Json

Reading JSON is accomplised via JsonInStream which takes raw JSON from a stream and produces of the core JSON types. For example:

str := """{"k1":"v1", "k2":3.4159, "k3":[1,2,3], "k4": {"m1":true, "m2":null}}"""
Str:Obj? data := JsonInStream(str.in).readJson
data["k1"]  =>  v1