Libraries.Containers.ByteArray Documentation

The ByteArray class is a specialized kind of array specifically designed for low level byte manipulation from files. The purpose is to provide a way to manipulate bytes efficiently in Quorum, which is necessary for some specialized applications. The values in each position in the array are raw bytes, which means any integer returned is 8 bits in length. As such, they are individually between the numbers -128 and 127.

Example Code

//this example will load a file into memory as a ByteArray
    //and print the values from the bytes out one by one.

    use Libraries.System.File
    use Libraries.Containers.ByteArray
    use Libraries.System.BinaryFileReader
    use Libraries.Interface.Events.FileLoadListener
    use Libraries.Interface.Events.FileLoadEvent
    use Libraries.Containers.Support.ByteReader

    class Main is FileLoadListener
        action Main
            File file
            file = file:GetParentDirectory():GetParentDirectory()
            file:SetPath("Library/Tests/ByteArray/HourOfCode.png")
            BinaryFileReader reader
            reader:OpenForRead(file, me)
        end

    action OnLoad(FileLoadEvent event)
        ByteArray value = event:GetBinaryFileReader():ReadBytes()
        integer i = 0
        repeat while i < value:GetSize()
            integer byte = value:Get(i)
            output byte
            i = i + 1
        end
    end

Inherits from: Libraries.Language.Object

Summary

Actions Summary Table

ActionsDescription
CharacterFromByte(integer byte)This action converts a byte into a character.
CharacterFromTwoBytes(integer byte1, integer byte2)This action converts two bytes into a character.
Compare(Libraries.Language.Object object)This action compares two object hash codes and returns an integer.
Decompress()This action decompresses a file that has already been stored in a ByteArray and returns a new ByteArray containing the decompressed information.
Equals(Libraries.Language.Object object)This action determines if two objects are equal based on their hash code values.
Get(integer location)This action returns the byte, in integer form, in the array at the given location.
GetByteReader()This action gets a ByteReader for this ByteArray.
GetHashCode()This action gets the hash code for an object.
GetSize()This action gets the size of the array.
GetSubArray(integer begin, integer finish)This action creates a new ByteArray that is a sub-array of an existing ByteArray, starting at begin and ending at finish.
IntegerFromByte(integer byte)This action converts a byte into an integer.
IntegerFromFourBytes(integer byte1, integer byte2, integer byte3, integer byte4)This action converts four bytes into an integer.
IntegerFromTwoBytes(integer byte1, integer byte2)This action converts two bytes into an integer.
IsBigEndian()This action checks if the data file is in Big Endian format or not.
NumberFromEightBytes(integer byte1, integer byte2, integer byte3, integer byte4, integer byte5, integer byte6, integer byte7, integer byte8)This action converts eight bytes into a number.
NumberFromFourBytes(integer byte1, integer byte2, integer byte3, integer byte4)This action converts four bytes into a number.
Set(integer location, integer value)This action sets the byte at the given location in the array to the value given.
SetBigEndian(boolean yes)This action sets the file to be in Big Endian format or not.
SetSize(integer size)This action sets the size of the byte array to the value given.
SignedIntegerFromFourUnsignedBytes(integer byte1, integer byte2, integer byte3, integer byte4)This action converts four unsigned bytes into a signed integer.
TextFromEightBytes(integer byte1, integer byte2, integer byte3, integer byte4, integer byte5, integer byte6, integer byte7, integer byte8)This action converts eight bytes into text as a sequence of numbers.
TextFromFourBytes(integer byte1, integer byte2, integer byte3, integer byte4)This action converts four bytes into text as a sequence of numbers.
UnsignedIntegerFromByte(integer byte)This action converts a byte into an unsigned integer.
UnsignedIntegerFromTwoBytes(integer byte1, integer byte2)This action converts two bytes into an unsigned integer.

Actions Documentation

CharacterFromByte(integer byte)

This action converts a byte into a character.

Example Code

use Libraries.Containers.ByteArray

    ByteArray value
    value:SetSize(1)
    value:Set(0, 65)
    integer byte = value:Get(0)
    output value:CharacterFromByte(byte)

Parameters

Return

text: Returns the character as text.

CharacterFromTwoBytes(integer byte1, integer byte2)

This action converts two bytes into a character.

Example Code

use Libraries.Containers.ByteArray

    ByteArray value
    value:SetSize(2)
    value:Set(0, 1)
    value:Set(1, 1)
    integer byte1 = value:Get(0)
    integer byte2 = value:Get(1)
    output value:CharacterFromTwoBytes(byte1, byte2)

Parameters

Return

text: Returns the character as text.

Compare(Libraries.Language.Object object)

This action compares two object hash codes and returns an integer. The result is larger if this hash code is larger than the object passed as a parameter, smaller, or equal. In this case, -1 means smaller, 0 means equal, and 1 means larger. This action was changed in Quorum 7 to return an integer, instead of a CompareResult object, because the previous implementation was causing efficiency issues.

Example Code

Object o
        Object t
        integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smaller)

Parameters

Return

integer: The Compare result, Smaller, Equal, or Larger.

Decompress()

This action decompresses a file that has already been stored in a ByteArray and returns a new ByteArray containing the decompressed information. The default decompression method is ZLib.

Example Code

use Libraries.System.File
    use Libraries.Containers.ByteArray

    File file
    file:SetPath("files/Quorum.png")
    ByteArray value = file:ReadBytes()
    value = value:Decompress()

Return

Libraries.Containers.ByteArray: Returns a ByteArray containing all of the decompressed data.

Equals(Libraries.Language.Object object)

This action determines if two objects are equal based on their hash code values.

Example Code

use Libraries.Language.Object
        use Libraries.Language.Types.Text
        Object o
        Text t
        boolean result = o:Equals(t)

Parameters

Return

boolean: True if the hash codes are equal and false if they are not equal.

Get(integer location)

This action returns the byte, in integer form, in the array at the given location.

Example Code

use Libraries.Containers.ByteArray

    ByteArray value
    value:SetSize(1)
    value:Set(0, 65)
    integer byte = value:Get(0)
    output byte

Parameters

Return

integer: Returns the byte, as an integer, at the specified location.

GetByteReader()

This action gets a ByteReader for this ByteArray.

Example Code

use Libraries.System.File
    use Libraries.Containers.ByteArray
    use Libraries.Containers.Support.ByteReader

    File file
    file:SetPath("files/Quorum.png")
    ByteArray value = file:ReadBytes()
    ByteReader reader = value:GetByteReader()

Return

Libraries.Containers.Support.ByteReader: Returns a ByteReader.

GetHashCode()

This action gets the hash code for an object.

Example Code

Object o
        integer hash = o:GetHashCode()

Return

integer: The integer hash code of the object.

GetSize()

This action gets the size of the array.

Example Code

use Libraries.Containers.ByteArray
        ByteArray value
        value:SetSize(4)
        value:Set(0, 65)
        value:Set(1, 66)
        value:Set(2, 67)
        value:Set(3, 68)
        integer size = value:GetSize()
        output size

Return

integer:

GetSubArray(integer begin, integer finish)

This action creates a new ByteArray that is a sub-array of an existing ByteArray, starting at begin and ending at finish.

Example Code

use Libraries.Containers.ByteArray

    ByteArray value
    value:SetSize(4)
    value:Set(0, 65)
    value:Set(1, 66)
    value:Set(2, 67)
    value:Set(3, 68)

    ByteArray subArray
    subArray = value:GetSubArray(0, 2)
    output subArray:GetSize()
    output subArray:Get(0)
    output subArray:Get(1)

Parameters

Return

Libraries.Containers.ByteArray: Returns a ByteArray containing all elements from the original ByteArray between begin and finish, inclusive.

IntegerFromByte(integer byte)

This action converts a byte into an integer.

Example Code

use Libraries.Containers.ByteArray

    ByteArray value
    value:SetSize(1)
    value:Set(0, 65)
    integer byte = value:Get(0)
    output value:IntegerFromByte(byte)

Parameters

Return

integer: Returns the byte value as an integer.

IntegerFromFourBytes(integer byte1, integer byte2, integer byte3, integer byte4)

This action converts four bytes into an integer.

Example Code

use Libraries.Containers.ByteArray

    ByteArray value
    value:SetSize(4)
    value:Set(0, 65)
    value:Set(1, 66)
    value:Set(2, 67)
    value:Set(3, 68)
    integer byte1 = value:Get(0)
    integer byte2 = value:Get(1)
    integer byte3 = value:Get(2)
    integer byte4 = value:Get(3)
    output value:IntegerFromFourBytes(byte1, byte2, byte3, byte4)

Parameters

Return

integer: Returns the byte values as an integer.

IntegerFromTwoBytes(integer byte1, integer byte2)

This action converts two bytes into an integer.

Example Code

use Libraries.Containers.ByteArray

    ByteArray value
    value:SetSize(2)
    value:Set(0, 65)
    value:Set(1, 66)
    integer byte1 = value:Get(0)
    integer byte2 = value:Get(1)
    output value:IntegerFromTwoBytes(byte1, byte2)

Parameters

Return

integer: Returns the byte values as an integer.

IsBigEndian()

This action checks if the data file is in Big Endian format or not.

Example Code

use Libraries.Containers.ByteArray

    ByteArray value
    value:SetBigEndian(true)
    output value:IsBigEndian()

Return

boolean: Returns true if the file is in Big Endian and false if not.

NumberFromEightBytes(integer byte1, integer byte2, integer byte3, integer byte4, integer byte5, integer byte6, integer byte7, integer byte8)

This action converts eight bytes into a number.

Example Code

use Libraries.Containers.ByteArray

    ByteArray value
    value:SetSize(8)
    value:Set(0, 65)
    value:Set(1, 66)
    value:Set(2, 67)
    value:Set(3, 68)
    value:Set(4, 1)
    value:Set(5, 2)
    value:Set(6, 3)
    value:Set(7, 4)
    integer byte1 = value:Get(0)
    integer byte2 = value:Get(1)
    integer byte3 = value:Get(2)
    integer byte4 = value:Get(3)
    integer byte5 = value:Get(4)
    integer byte6 = value:Get(5)
    integer byte7 = value:Get(6)
    integer byte8 = value:Get(7)
    output value:NumberFromEightBytes(byte1, byte2, byte3, byte4, byte5, byte6, byte7, byte8)

Parameters

Return

number: Returns the byte values as a number.

NumberFromFourBytes(integer byte1, integer byte2, integer byte3, integer byte4)

This action converts four bytes into a number.

Example Code

use Libraries.Containers.ByteArray

    ByteArray value
    value:SetSize(4)
    value:Set(0, 65)
    value:Set(1, 66)
    value:Set(2, 67)
    value:Set(3, 68)
    integer byte1 = value:Get(0)
    integer byte2 = value:Get(1)
    integer byte3 = value:Get(2)
    integer byte4 = value:Get(3)
    output value:NumberFromFourBytes(byte1, byte2, byte3, byte4)

Parameters

Return

number: Returns the byte values as a number.

Set(integer location, integer value)

This action sets the byte at the given location in the array to the value given.

Example Code

use Libraries.Containers.ByteArray

    ByteArray value
    value:SetSize(1)
    value:Set(0, 65)
    output value:Get(0)

Parameters

SetBigEndian(boolean yes)

This action sets the file to be in Big Endian format or not.

Example Code

use Libraries.Containers.ByteArray

    ByteArray value
    value:SetBigEndian(false)
    output value:IsBigEndian()

Parameters

SetSize(integer size)

This action sets the size of the byte array to the value given.

Example Code

use Libraries.Containers.ByteArray

    ByteArray value
    value:SetSize(4)
    output value:GetSize()

Parameters

SignedIntegerFromFourUnsignedBytes(integer byte1, integer byte2, integer byte3, integer byte4)

This action converts four unsigned bytes into a signed integer.

Example Code

use Libraries.Containers.ByteArray

    ByteArray value
    value:SetSize(4)
    value:Set(0, 65)
    value:Set(1, 66)
    value:Set(2, 67)
    value:Set(3, 68)
    integer byte1 = value:Get(0)
    integer byte2 = value:Get(1)
    integer byte3 = value:Get(2)
    integer byte4 = value:Get(3)
    output value:SignedIntegerFromFourUnsignedBytes(byte1, byte2, byte3, byte4)

Parameters

Return

integer: Returns the byte values as a signed integer.

TextFromEightBytes(integer byte1, integer byte2, integer byte3, integer byte4, integer byte5, integer byte6, integer byte7, integer byte8)

This action converts eight bytes into text as a sequence of numbers.

Example Code

use Libraries.Containers.ByteArray

    ByteArray value
    value:SetSize(8)
    value:Set(0, 65)
    value:Set(1, 66)
    value:Set(2, 67)
    value:Set(3, 68)
    value:Set(4, 1)
    value:Set(5, 2)
    value:Set(6, 3)
    value:Set(7, 4)
    integer byte1 = value:Get(0)
    integer byte2 = value:Get(1)
    integer byte3 = value:Get(2)
    integer byte4 = value:Get(3)
    integer byte5 = value:Get(4)
    integer byte6 = value:Get(5)
    integer byte7 = value:Get(6)
    integer byte8 = value:Get(7)
    output value:TextFromEightBytes(byte1, byte2, byte3, byte4, byte5, byte6, byte7, byte8)

Parameters

Return

text: Returns the byte values as text.

TextFromFourBytes(integer byte1, integer byte2, integer byte3, integer byte4)

This action converts four bytes into text as a sequence of numbers.

Example Code

use Libraries.Containers.ByteArray

    ByteArray value
    value:SetSize(4)
    value:Set(0, 65)
    value:Set(1, 66)
    value:Set(2, 67)
    value:Set(3, 68)
    integer byte1 = value:Get(0)
    integer byte2 = value:Get(1)
    integer byte3 = value:Get(2)
    integer byte4 = value:Get(3)
    output value:TextFromFourBytes(byte1, byte2, byte3, byte4)

Parameters

Return

text: Returns the byte values as text.

UnsignedIntegerFromByte(integer byte)

This action converts a byte into an unsigned integer.

Example Code

use Libraries.Containers.ByteArray

    ByteArray value
    value:SetSize(1)
    value:Set(0, 65)
    integer byte1 = value:Get(0)
    output value:UnsignedIntegerFromByte(byte1)

Parameters

Return

integer: Returns the byte value as an unsigned integer.

UnsignedIntegerFromTwoBytes(integer byte1, integer byte2)

This action converts two bytes into an unsigned integer.

Example Code

use Libraries.Containers.ByteArray

    ByteArray value
    value:SetSize(2)
    value:Set(0, 65)
    value:Set(1, 66)
    integer byte1 = value:Get(0)
    integer byte2 = value:Get(1)
    output value:UnsignedIntegerFromTwoBytes(byte1, byte2)

Parameters

Return

integer: Returns the byte values as an unsigned integer.