Return a negative integer, zero, or a positive integer if this object is less than, equal to, or greater than the specified object:
this < that => <0
this == that => 0
this > that => >0
This method may also be accessed via the <
<=
<=>
>=
and >
shortcut operators. If not overridden the default
implementation compares the toStr
representations. Also see docLang.
Examples:
3.compare(8) => -1
8.compare(3) => 1
8.compare(8) => 0
3 <=> 8 => -1 // shortcut for 3.compare(8)
Compare this object to the specified for equality. This
method may be accessed via the == and != shortcut operators.
If not overridden the default implementation compares for
reference equality using the === operator. If this method
is overridden, then hash() must also be overridden such that
any two objects which return true for equals() must return
the same value for hash(). This method must accept null
and
return false.
Return a unique hashcode for this object. If a class overrides hash() then it must ensure if equals() returns true for any two objects then they have same hash code.
Get an immutable representation of this instance or throw NotImmutableErr if this object cannot be represented as an immutable:
Return a string representation of this object.
Trap a dynamic call for handling. Dynamic calls are invoked with the -> shortcut operator:
a->x a.trap("x", null)
a->x() a.trap("x", null)
a->x = b a.trap("x", [b])
a->x(b) a.trap("x", [b])
a->x(b, c) a.trap("x", [b, c])
The default implementation provided by Obj attempts to use reflection. If name maps to a method, it is invoked with the specified arguments. If name maps to a field and args.size is zero, get the field. If name maps to a field and args.size is one, set the field and return args[0]. Otherwise throw UnknownSlotErr.
This method called whenever an it-block is applied to an
object. The default implementation calls the function with this
,
and then returns this
.
Static
echoWrite x.toStr
to standard output followed by newline. If x
is null then print "null". If no argument is provided then
print an empty line.
Optional
x: JsObjStatic
ioStatic
ioConfigure an I/O handle to use the specified charset. The handle is any supported I/O handle and the charset is a string name supported by the JVM installation. Standard charset names:
Examples:
// write text file in UTF-16BE
ioWriteStr(str, ioCharset(`io/foo.txt`, "UTF-16BE"))
// read CSV file in ISO-8859-1
ioCharset(`io/foo.csv`, "ISO-8859-1").ioReadCsv
Static
ioCopy a file or directory to the new specified location. If this file represents a directory, then it recursively copies the entire directory tree. Both handles must reference a local file or directory on the file system.
If during the copy, an existing file of the same name is
found, then the "overwrite" option should be to marker or true
to overwrite or false
to skip. Or if overwrite is not
defined then an IOErr is raised.
Examples:
ioCopy(`io/dir/`, `io/dir-copy/`)
ioCopy(`io/file.txt`, `io/file-copy.txt`)
ioCopy(`io/file.txt`, `io/file-copy.txt`, {overwrite})
ioCopy(`io/file.txt`, `io/file-copy.txt`, {overwrite:false})
Static
ioGenerate a cycle reduancy check code as a Number. See sys::Buf.crc for available algorithms.
Example:
ioCrc("foo", "CRC-32").toHex
Static
ioStatic
ioStatic
ioGenerate a one-way hash of the given I/O handle. See sys::Buf.toDigest for available algorithms.
Example:
ioDigest("foo", "SHA-1").ioToBase64
Static
ioRead a directory listing, return a grid with cols:
uri
: Uri for handle to read/write the filename
: filename stringmimeType
: file mime type or null if unknowndir
: marker if file is a sub-directory or nullsize
: size of file in bytes or nullmod
: modified timestamp or null if unknownIf the I/O handle does not map to a file in the virtual file system then throw an exception.
ioDir(`io/`) // read files in project's io/ directory
ioDir(`fan://haystack`) // read files in pod
Static
ioIterate the rows of a CSV file (comma separated values) and callback the given function with two parameters: Str[] cells of current row and zero based Number line number.
The following options are supported:
Also ioReadCsv, ioWriteCsv, and docHaystack::Csv.
Static
ioFor each line of the given source stream call the given function with two parameters: Str line and zero based Number line number. Lines are processed according to sys::InStream.eachLine.
Static
ioExport a view to the given file handle - see docFresco::Export.
Note: this feature is available in SkySpark only
Static
ioReturn an I/O handle to decode from a base64 string. Also see ioToBase64() and sys::Buf.fromBase64
Example:
// decode base64 to a string
ioFromBase64("c2t5c3Bhcms").ioReadStr
Static
ioStatic
ioGenerate an HMAC message authentication as specified by RFC 2104. See sys::Buf.hmac.
Example:
ioHmac("foo", "SHA-1", "secret").ioToBase64
Static
ioGet information about a file handle and return a Dict with the same tags as ioDir().
If the I/O handle does not map to a file in the virtual file system then throw an exception.
ioInfo(`io/`) // read file info for the project's io/ directory
ioInfo(`io/sites.trio`) // read file info for the io/sites.trio file
Static
ioStatic
ioStatic
ioStatic
ioRead a CSV (comma separated values) file into memory as a Grid. CSV format is implemented as specified by RFC 4180:
delimiter
char"
double quote, or newline
are quoted; quotes are escaped as ""
The following options are supported:
Also see ioStreamCsv, ioEachCsv, ioWriteCsv, and docHaystack::Csv.
Static
ioRead a JSON file into memory. This function can used to read any arbitrary JSON nested object/array structure which can be accessed as Axon dicts/lists. The default decoding assumes Haystack 4 JSON format (Hayson). Also see ioReadJsonGrid if reading a Haystack formatted grid.
Object keys which are not valid tag names will decode
correctly and can be used in-process. But they will not
serialize correctly over the HTTP API. You can use the safeNames
option to force object keys to be safe tag names (but you
will lose the original key names).
The following options are supported:
Static
ioRead a JSON file formatted as a standardized Haystack grid into memory. See ioReadJson to read arbitrary JSON structured data.
Static
ioRead an I/O handle into memory as a list of string lines. Lines are processed according to sys::InStream.readLine semanatics.
By default the maximum line size read is 4kb of Unicode characters (not bytes). This limit may be overridden using the option key "limit".
Examples:
ioReadLines(`io/file.txt`)
ioReadLines(`io/file.txt`, {limit: 10_000})
Static
ioRead an I/O handle into memory as a string. Newlines are always normalized into "\n" characters.
Static
ioStatic
ioRead a Xeto data file into memory as a Haystack data type. See xeto::LibNamespace.compileData for details and options.
Static
ioStatic
ioApply a skipping operation to an input I/O handle. The following options are available (in order of processing):
Skipping a BOM will automatically set the appropiate charset. If no BOM is detected, then this call is safely ignored by pushing those bytes back into the input stream. The following byte order marks are supported:
Examples:
// skip leading 4 lines in a CSV file
ioSkip(`io/foo.csv`, {lines:4}).ioReadCsv
// skip byte order mark
ioSkip(`io/foo.csv`, {bom}).ioReadCsv
Static
ioRead a stream of dicts from a comma separated value file. This function uses the same options and semantics as ioReadCsv except it streams the rows as dicts instead of reading to an in-memory grid. See docHaxall::Streams#ioStreamCsv.
Static
ioRead a stream of lines. Lines are processed according to sys::InStream.eachLine. See docHaxall::Streams#ioStreamLines.
Static
ioEncode an I/O handle into a base64 string. The default
behavior is to encode using RFC 2045 (see sys::Buf.toBase64).
Use the {uri}
option to encode a URI-safe URI via RFC 4648
(see sys::Buf.toBase64Uri).
Also see ioFromBase64.
Example:
// encode string to base64
ioToBase64("myusername:mysecret")
// encode string to base64 without padding using URI safe chars
ioToBase64("myusername:mysecret", {uri})
Static
ioStatic
ioWrite a grid to a CSV (comma separated values) file.
CSV format is implemented as specified by RFC 4180:
delimiter
char"
double quote, or newline
are quoted; quotes are escaped as ""
The following options are supported:
Also ioReadCsv, ioEachCsv, and docHaystack::Csv.
Static
ioWrite an Excel XLS file, where val
may be:
By default each worksheet is named "Sheet1", "Sheet2", etc.
Use a title
tag in Grid.meta to give the worksheets a
specific name.
Example:
readAll(site).ioWriteExcel(`io/sites.xls`)
Static
ioStatic
ioWrite an Axon data structure to JSON. By default, Haystack 4
(Hayson) encoding is used. The val
may be:
The following options are supported:
Static
ioStatic
ioStatic
ioRender data to a PDF file. The grid meta "view" tag determines the visualization:
table
: render grid as table
(default)chart
: render grid as chartfandoc
: render string as fandoctext
: render as plaintextOptions:
Examples:
// render as chart with default page size
read(power).hisRead(yesterday).ioWritePdf(`io/portrait.pdf`)
// render as chart with landscape page size of 11" x 8.5"
read(power).hisRead(yesterday).ioWritePdf(`io/landscape.pdf`, {pageSize:"11in,8.5in"})
// render table as single auto-fit page
readAll(site).ioWritePdf(`io/sites.pdf`, {pageSize:"auto"})
Note: this feature is available in SkySpark only
Static
ioStatic
ioRender data to an SVG file. Pass size
option to specify the
SVG viewBox
, width
, and height
attribtues (defaults to
"1000,800"). The visualization is determined by the grid
meta "view" tag - see ioWritePdf() for
specifics.
Examples:
read(power).hisRead(yesterday).ioWriteSvg(`io/example.svg`)
read(power).hisRead(yesterday).ioWriteSvg(`io/example.svg`, {size:"600,400"})
Note: this feature is available in SkySpark only
Static
ioStatic
ioStatic
ioWrite value to a Xeto text format file. See xeto::LibNamespace.writeData for details and options.
Static
ioStatic
ioStatic
ioRead a zip file's entry listing, return a grid with cols:
path
: path of entry inside zip as Urisize
: size of file in bytes or nullmod
: modified timestamp or null if unknownThe handle must reference a zip file in the file system. Use ioZipEntry to perform a read operation on one of the entries in the zip file.
Example:
ioZipDir(`io/batch.zip`)
Static
ioReturn a I/O handle which may be used to read from a zip
entry within a zip file. The handle
parameter must be an
I/O handle which references a zip file in the file system.
The path
parameter must be a Uri which identifies the path
of the entry within the zip file. See ioZipDir
to read the listing of paths within a zip.
Example:
// read CSV file from within a zip
ioZipEntry(`io/batch.zip`, `/zone-temp.csv`).ioReadCsv
Static
make
I/O library functions