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
Actions Documentation
CharacterFromByte(integer byte)
This action converts a byte into a character.
Parameters
- integer byte: The byte value to convert to a character.
Return
text: Returns the character as text.
Example
use Libraries.Containers.ByteArray
ByteArray value
value:SetSize(1)
value:Set(0, 65)
integer byte = value:Get(0)
output value:CharacterFromByte(byte)
CharacterFromTwoBytes(integer byte1, integer byte2)
This action converts two bytes into a character.
Parameters
- integer byte1: The first byte value to use for conversion.
- integer byte2: The second byte value to use for conversion.
Return
text: Returns the character as text.
Example
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)
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.
Parameters
- Libraries.Language.Object: The object to compare to.
Return
integer: The Compare result, Smaller, Equal, or Larger.
Example
Object o
Object t
integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smaller)
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.
Return
Libraries.Containers.ByteArray: Returns a ByteArray containing all of the decompressed data.
Example
use Libraries.System.File
use Libraries.Containers.ByteArray
File file
file:SetPath("files/Quorum.png")
ByteArray value = file:ReadBytes()
value = value:Decompress()
Equals(Libraries.Language.Object object)
This action determines if two objects are equal based on their hash code values.
Parameters
- Libraries.Language.Object: The to be compared.
Return
boolean: True if the hash codes are equal and false if they are not equal.
Example
use Libraries.Language.Object
use Libraries.Language.Types.Text
Object o
Text t
boolean result = o:Equals(t)
Get(integer location)
This action returns the byte, in integer form, in the array at the given location.
Parameters
- integer location: The index of where you want to read the array from.
Return
integer: Returns the byte, as an integer, at the specified location.
Example
use Libraries.Containers.ByteArray
ByteArray value
value:SetSize(1)
value:Set(0, 65)
integer byte = value:Get(0)
output byte
GetByteReader()
This action gets a ByteReader for this ByteArray.
Return
Libraries.Containers.Support.ByteReader: Returns a ByteReader.
Example
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()
GetHashCode()
This action gets the hash code for an object.
Return
integer: The integer hash code of the object.
Example
Object o
integer hash = o:GetHashCode()
GetSize()
This action gets the size of the array.
Return
integer:
Example
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
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.
Parameters
- integer begin: The index location to begin creating the new ByteArray.
- integer finish: The index location to finish creating the new ByteArray.
Return
Libraries.Containers.ByteArray: Returns a ByteArray containing all elements from the original ByteArray between begin and finish, inclusive.
Example
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)
IntegerFromByte(integer byte)
This action converts a byte into an integer.
Parameters
- integer byte: The byte value to convert to an integer.
Return
integer: Returns the byte value as an integer.
Example
use Libraries.Containers.ByteArray
ByteArray value
value:SetSize(1)
value:Set(0, 65)
integer byte = value:Get(0)
output value:IntegerFromByte(byte)
IntegerFromFourBytes(integer byte1, integer byte2, integer byte3, integer byte4)
This action converts four bytes into an integer.
Parameters
- integer byte1: The first byte value to use for conversion.
- integer byte2: The second byte value to use for conversion.
- integer byte3: The third byte value to use for conversion.
- integer byte4: The fourth byte value to use for conversion.
Return
integer: Returns the byte values as an integer.
Example
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)
IntegerFromTwoBytes(integer byte1, integer byte2)
This action converts two bytes into an integer.
Parameters
- integer byte1: The first byte value to use for conversion.
- integer byte2: The second byte value to use for conversion.
Return
integer: Returns the byte values as an integer.
Example
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)
IsBigEndian()
This action checks if the data file is in Big Endian format or not.
Return
boolean: Returns true if the file is in Big Endian and false if not.
Example
use Libraries.Containers.ByteArray
ByteArray value
value:SetBigEndian(true)
output value:IsBigEndian()
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.
Parameters
- integer byte1: The first byte value to use for conversion.
- integer byte2: The second byte value to use for conversion.
- integer byte3: The third byte value to use for conversion.
- integer byte4: The fourth byte value to use for conversion.
- integer byte5: The fifth byte value to use for conversion.
- integer byte6: The sixth byte value to use for conversion.
- integer byte7: The seventh byte value to use for conversion.
- integer byte8: The eighth byte value to use for conversion.
Return
number: Returns the byte values as a number.
Example
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)
NumberFromFourBytes(integer byte1, integer byte2, integer byte3, integer byte4)
This action converts four bytes into a number.
Parameters
- integer byte1: The first byte value to use for conversion.
- integer byte2: The second byte value to use for conversion.
- integer byte3: The third byte value to use for conversion.
- integer byte4: The fourth byte value to use for conversion.
Return
number: Returns the byte values as a number.
Example
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)
Set(integer location, integer value)
This action sets the byte at the given location in the array to the value given.
Parameters
- integer location: The index of where you want to read the array from.
- integer value: The value to set the byte at the location to.
Example
use Libraries.Containers.ByteArray
ByteArray value
value:SetSize(1)
value:Set(0, 65)
output value:Get(0)
SetBigEndian(boolean yes)
This action sets the file to be in Big Endian format or not.
Parameters
- boolean yes: Sets the format to Big Endian if true, Little Endian if false.
Example
use Libraries.Containers.ByteArray
ByteArray value
value:SetBigEndian(false)
output value:IsBigEndian()
SetSize(integer size)
This action sets the size of the byte array to the value given.
Parameters
- integer size: The size to set the byte array.
Example
use Libraries.Containers.ByteArray
ByteArray value
value:SetSize(4)
output value:GetSize()
SignedIntegerFromFourUnsignedBytes(integer byte1, integer byte2, integer byte3, integer byte4)
This action converts four unsigned bytes into a signed integer.
Parameters
- integer byte1: The first byte value to use for conversion.
- integer byte2: The second byte value to use for conversion.
- integer byte3: The third byte value to use for conversion.
- integer byte4: The fourth byte value to use for conversion.
Return
integer: Returns the byte values as a signed integer.
Example
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)
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.
Parameters
- integer byte1: The first byte value to use for conversion.
- integer byte2: The second byte value to use for conversion.
- integer byte3: The third byte value to use for conversion.
- integer byte4: The fourth byte value to use for conversion.
- integer byte5: The fifth byte value to use for conversion.
- integer byte6: The sixth byte value to use for conversion.
- integer byte7: The seventh byte value to use for conversion.
- integer byte8: The eighth byte value to use for conversion.
Return
text: Returns the byte values as text.
Example
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)
TextFromFourBytes(integer byte1, integer byte2, integer byte3, integer byte4)
This action converts four bytes into text as a sequence of numbers.
Parameters
- integer byte1: The first byte value to use for conversion.
- integer byte2: The second byte value to use for conversion.
- integer byte3: The third byte value to use for conversion.
- integer byte4: The fourth byte value to use for conversion.
Return
text: Returns the byte values as text.
Example
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)
UnsignedIntegerFromByte(integer byte)
This action converts a byte into an unsigned integer.
Parameters
- integer byte: The byte value to convert to an unsigned integer.
Return
integer: Returns the byte value as an unsigned integer.
Example
use Libraries.Containers.ByteArray
ByteArray value
value:SetSize(1)
value:Set(0, 65)
integer byte1 = value:Get(0)
output value:UnsignedIntegerFromByte(byte1)
UnsignedIntegerFromTwoBytes(integer byte1, integer byte2)
This action converts two bytes into an unsigned integer.
Parameters
- integer byte1: The first byte value to use for conversion.
- integer byte2: The second byte value to use for conversion.
Return
integer: Returns the byte values as an unsigned integer.
Example
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)
On this page
Variables TableAction Documentation- CharacterFromByte(integer byte)
- CharacterFromTwoBytes(integer byte1, integer byte2)
- Compare(Libraries.Language.Object object)
- Decompress()
- Equals(Libraries.Language.Object object)
- Get(integer location)
- GetByteReader()
- GetHashCode()
- GetSize()
- GetSubArray(integer begin, integer finish)
- IntegerFromByte(integer byte)
- IntegerFromFourBytes(integer byte1, integer byte2, integer byte3, integer byte4)
- IntegerFromTwoBytes(integer byte1, integer byte2)
- IsBigEndian()
- NumberFromEightBytes(integer byte1, integer byte2, integer byte3, integer byte4, integer byte5, integer byte6, integer byte7, integer byte8)
- NumberFromFourBytes(integer byte1, integer byte2, integer byte3, integer byte4)
- Set(integer location, integer value)
- SetBigEndian(boolean yes)
- SetSize(integer size)
- SignedIntegerFromFourUnsignedBytes(integer byte1, integer byte2, integer byte3, integer byte4)
- TextFromEightBytes(integer byte1, integer byte2, integer byte3, integer byte4, integer byte5, integer byte6, integer byte7, integer byte8)
- TextFromFourBytes(integer byte1, integer byte2, integer byte3, integer byte4)
- UnsignedIntegerFromByte(integer byte)
- UnsignedIntegerFromTwoBytes(integer byte1, integer byte2)