afbase

af.compile

af.compile(aScriptString, aSourceName) : Object

Compiles the aScriptString executing it and returning the corresponding result.  Optionally you can provide aSourceName.

af.compileToClasses

af.compileToClasses(aClassfile, aScriptString, aPath)

Given aClassfile name, aScriptString and, optionally, a filesystem aPath it will generate Java bytecode as result of compiling the aScriptString into a filesystem aClassfile (on the provided aPath). Example:

af.compileToClasses("SomeClass", "print('hello world!');", "/some/path")


af.cp

af.cp(aSourceFilePath, aTargetFilePath)

Tries to copy aSourceFilePath to aTargetFilePath preserving file attributes.

af.create2FACredentials

af.create2FACredentials(anAccountName, anIssuer) : Map

Given anAccountName and anIssuer will create a the 2FA/TOTP (Time-Based One-Time Password) returning a map with the scratchCodes, the verificationCode, the key, the openaf encryptedKey, the QR code URL  and the OTP URL.

af.crypt

af.crypt(aKey, aSalt) : String

Tries to mimic crypt(3) password encryption using the org.apache.commons.codec.digest.Crypt.crypt function. Please check https://commons.apache.org/proper/commons-codec/apidocs/org/apache/commons/codec/digest/Crypt.html for more. Use af.randomCryptSalt() to generate a random salt if necessary.

af.decrypt

af.decrypt(aString, aKey) : String

Decrypts the provided aString with the provided aKey.

af.e

af.e(aString)

Outputs to stderr aString ending with a newline.

af.encrypt

af.encrypt(aString, aKey) : String

Encrypts the provided aString as password for most of the OpenAF password functionality. If aKey is provided it will encrypt using it.

af.enl

af.enl(aString)

Outputs to stderr aString without a newline on the end.

af.eval

af.eval(aScript) : Object

Performs the equivalent version of the javascript eval function for the provided aScript. Returns  the corresponding result of the evaluation.

af.externalAddClasspath

af.externalAddClasspath(aURL)

Tries to add aURL to the current classpath. Don't forget that directories must end with a '/', for  example: file:/my/own/dir/

Note: This might not work for some JVMs.

af.externalClass

af.externalClass(anArrayOfClasspathEntries, aClassName) : JavaClass

Returns an external Java class with the aClassName, not included in the initial OpenAF's classpath, loaded from a list of jars/folders in anArrayOfClasspathEntries.

af.externalClassLoader

af.externalClassLoader(anArrayOfClasspathEntries) : ClassLoader

Returns a ClassLoader suitable to be use with af.getClass to dynamically load Java classes that weren't included  on the initial OpenAF's classpath and are included in the jars/folders provided in anArrayOfClasspathEntries.

af.externalPlugin

af.externalPlugin(anArrayOfClasspathEntries, aPluginClass)

Loads a OpenAF's plugin identified by the aPluginClass that isn't available in the initial OpenAF's classpath, loaded from a list of jars/folders in anArrayOfClasspathEntries.

af.fromArray2Bytes

af.fromArray2Bytes(anArray) : anArrayOfBytes

Converts a javascript array of integers into a Java anArrayOfBytes.

af.fromBase64

af.fromBase64(aBase) : anArrayOfBytes

Given aBase as a string or an array of bytes will convert it to anArrayOfBytes in Base 64.

af.fromBytes2Array

af.fromBytes2Array(anArrayOfBytes) : Array

Converts a Java anArrayOfBytes into a javascript array of integers with the value representation of  each byte.

af.fromBytes2InputStream

af.fromBytes2InputStream(anArrayOfBytes) : Stream

Converts anArrayOfBytes into a ByteArrayInputStream.

af.fromBytes2OutputStream

af.fromBytes2OutputStream(anArrayOfBytes) : Stream

Converts anArrayOfBytes into a ByteArrayOutputStream. After using this stream you can, for example, use .toString and toByteArray methods from the resulting stream.

af.fromBytes2String

af.fromBytes2String(anArrayOfBytes, anEncoding) : aString

Converts anArrayOfBytes into a string, optionally with the provided anEncoding.

af.fromInputStream2Bytes

af.fromInputStream2Bytes(aStream) : anArrayOfBytes


af.fromInputStream2String

af.fromInputStream2String(aStream, anEncoding) : String

Tries to convert an input aStream into a String.

af.fromString2Bytes

af.fromString2Bytes(aString, anEncoding) : anArrayOfBytes

Converts aString into anArrayOfBytes, optionally with the provided anEncoding.

af.fromString2InputStream

af.fromString2InputStream(aString, anEncoding) : Stream

Converts aString into a ByteArrayInputStream.

af.fromString2OutputStream

af.fromString2OutputStream(aString, encoding) : Stream

Converts aString into a ByteArrayOutputStream. After using this stream you can, for example, use .toString and toByteArray methods from the resulting stream.

af.fromXML

af.fromXML(aXMLObject) : aString

Converts aXMLObject (E4X) into a String. Warning: beware that E4X is an obsolete object.

af.get2FAToken

af.get2FAToken(aKey, aSpecificTime) : String

Given 2FA aKey it will return the current token. Note: it will use the current date/time of the system so it must be in sync with the authenticator. Optionally you can provide aSpecificTime.

af.getClass

af.getClass(aName, aLoader) : JavaClass

Returns the JavaClass object the Java class identified by aName. Optionally you can provide a Java classloader ( this can be the result of using af.externalClassLoader).

af.getDistribution

af.getDistribution() : String

Returns the current OpenAF's distribution channel.

af.getOpenAFJar

af.getOpenAFJar() : String

Retrives the fullpath for the OpenAF jar.

af.getScopeIds

af.getScopeIds() : Array

Returns an array of the current scope IDs.

af.getVersion

af.getVersion() : String

Returns the current OpenAF's build version.

af.js2s

af.js2s(aObject) : String

Tries to convert an object into a beautified string representation.

af.load

af.load(aFilename)

Loads an OpenAF script/file aFilename. The variable __loadedfrom will always be set to the aFilename value a after each execution. The aFilename can be composed not only by a filename but also with a zip/opack file where it resides (for example: "aZipFile.zip::aScriptInsideTheZip.js"). The variable __loadedfromzip would hold,  in this case, the zip file from which the script was executed.

af.loadRequire

af.loadRequire(arrayOfPaths, isSandboxed)

Will redefine the require function on the current scope to use the arrayOfPaths provided.  Optionally you can the require function can provide a sandbox enviroment if isSandboxed = true.

af.mkdir

af.mkdir(aNewDirectory) : boolean

Tries to create aNewDirectory. Returns true if successfull, false otherwise.

af.mv

af.mv(aSourceFilePath, aTargetFilePath)

Tries to move aSourceFilePath to aTargetFilePath preserving file attributes.

af.newOutputStream

af.newOutputStream() : Stream

Creates a new ByteArrayOutputStream. After using this stream you can, for example, use .toString and toByteArray methods from the resulting stream.

af.p

af.p(aString)

Outputs to stdout aString ending with a newline.

af.parse

af.parse(aScriptString, aSourceName) : Array

Parses aScriptString, with aSourceName, returning the corresponding parsed statments.

af.plugin

af.plugin(aPluginClass)

Loads a OpenAF's plugin class (aPluginClass).

af.pnl

af.pnl(aString)

Outputs to stdout aString without a newline on the end.

af.randomCryptSalt

af.randomCryptSalt() : String

Generates a random valid, 2 char long, crypt salt to be used with af.crypt.

af.rename

af.rename(aSourceFilePath, aTargetFilePath)

Tries to rename aSourceFilePath to aTargetFilePath.

af.restartOpenAF

af.restartOpenAF(aCommandLineArray)

Terminates the current OpenAF execution and tries to start a new with the same command line, if aCommandLineArray is not provided. If aCommandLineArray is provided each array element will be use sequentially to build the command line to start a new OpenAF instance.

af.rm

af.rm(aFilePath)

Tries to delete a file or a directory on the provided aFilePath. In case it's a directory it will try to  recursively delete all directory contents.

af.runFromClass

af.runFromClass(aCompiledJavascriptClass) : Object

Runs aCompiledJavascriptClass returning it's output. Example:

af.compileToClasses("SomeClass", "print('hello world!');", "/some/path");
var aScriptClass = af.externalClass(["file://some/path/"], "SomeClass");
af.runFromClass(aScriptClass.newInstance());


af.secureRandom

af.secureRandom() : Double

Returns a java security SecureRandom double value.

af.setK

af.setK(aK)

Sets the current 16 bytes encrypt/decrypt key.

af.sh

af.sh(commandArguments, aStdIn, aTimeout, shouldInheritIO, aDirectory, returnMap, callbackFunc, encoding, dontWait, envsMap) : String/Map

Tries to execute commandArguments (either a String or an array of strings) in the operating system. Optionally aStdIn can be provided, aTimeout can be defined for the execution and if shouldInheritIO is true the stdout, stderr and stdin will be inherit from OpenAF. If shouldInheritIO is not defined or false it will return the stdout of the command execution. It's possible also to provide a different working aDirectory. If envsMap (a map of strings) is defined the environment variables will be replaced by envsMap. The variables __exitcode and __stderr can be checked for the command exit code and the stderr output correspondingly. In alternative  if returnMap = true a map will be returned with stdout, stderr and exitcode. A callbackFunc can be provided, if shouldInheritIO is undefined or false, that will receive, as parameters, an output stream, a error stream and an input stream. If defined the stdout and stderr won't be available for the returnMap if true. Example:

sh("someCommand", void 0, void 0, false, void 0, false, function(o, e, i) { ioStreamReadLines(o, (f) => { print("TEST | " + String(f)) }, void 0, false) });


af.sleep

af.sleep(aTime)

Suspends the current script execution (if using Threads only the thread executing this function) for a  period of aTime in ms. For example aTime = 1000 would result in suspending the execution for 1 second.

af.sync

af.sync(aFunction, aObject)

When running in multithreaded scripts will ensure that aFunction is synchronized. Optionally aObject for synchronization can be provided.

af.toBase64Bytes

af.toBase64Bytes(arrayOfBytes) : anArrayOfBytes

Given arrayOfBytes as a string or an array of bytes in Base 64 will convert it back to an array of bytes.

af.toEncoding

af.toEncoding(aString, aTargetEncoding, aSourceEncoding) : String

Converts aString to aTargetEncoding optionally providing aSourceEncoding. If aTargetEncoding is not provided it will default to the current java encoding.

af.validate2FA

af.validate2FA(aKey, aToken) : boolean

Given aToken and a 2FA aKey returns true if it's valid. Note: it will use the current date/time of the system so it must be in sync with the authenticator app; scratchCodes are not handled.

af.visibleLength

af.visibleLength(aString) : int

Given aString will try to remove ansi characters and just count code point (e.g. removing combined characters like emojis).