Accessor: util/GetResource


Get a resource, which may be a relative file name or a URL, and return the value of the resource as a string.

Implementations of this function may restrict the locations from which resources can be retrieved. This implementation restricts relative file names to be in the same directory where the swarmlet model is located or in a subdirectory, or if the resource begins with "$CLASSPATH/", to the classpath of the current Java process.

If the accessor is not restricted, the $KEYSTORE is resolved to $HOME/.ptKeystore.

The options parameter may have the following values:

  • If the type of the options parameter is a Number, then it is assumed to be the timeout in milliseconds.
  • If the type of the options parameter is a String, then it is assumed to be the encoding, for example "UTF-8". If the value is "Raw" or "raw" then the data is returned as an unsigned array of bytes. The default encoding is the default encoding of the system. In CapeCode, the default encoding is returned by Charset.defaultCharset().
  • If the type of the options parameter is an Object, then it may have the following fields: encoding {string} The encoding of the file, see above for values. timeout {number} The timeout in milliseconds.

    If the callback parameter is not present, then getResource() will be synchronous read like Node.js's fs.readFileSync(). If the callback argument is present, then getResource() will be asynchronous like fs.readFile().

  • $$Id$$
  • Edward A. Lee, Matt Weber
Name Type Description
options Options passed to the getResources() function, see above for details.
resource string The file or URL to be read. Defaults to the Accessors home page (
trigger boolean Send a token to this input to read the file or URL.
Name Type Description
output The contents of the file or URL.
Name Type Description
synchronous boolean Perform a synchronous or asynchronous call of getResource. Note some hosts do not currently implement both versions.


(static) filterResponse(response)

Filter the response. This base class just returns the argument unmodified, but derived classes can override this to extract a portion of the response, for example. Note that the response argument can be null, indicating that there was no response (e.g., a timeout or error occurred).

Name Type Description

The response, or null if there is none.