Libraries.Containers.Support.ByteReader Documentation

The ByteReader class is designed to read through ByteArrays that store low level byte information 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. The ByteReader can be used to easily retrieve bytes as well as numbers, booleans, and integers.

Example Code

use Libraries.Containers.Support.ByteReader
    use Libraries.System.File
    use Libraries.Containers.ByteArray
    
    class Main
        action main
            File file
            file:SetPath("files/Quorum.png")
            ByteArray value = file:ReadBytes()
            ByteReader reader
            reader:SetByteArray(value)
            integer nextByte = reader:NextByteAsInteger()
        end
    end

Inherits from: Libraries.Language.Object

Summary

Actions Summary Table

ActionsDescription
CheckIfTrueTypeCollection()This action checks if the font file being read is a .
Compare(Libraries.Language.Object object)This action compares two object hash codes and returns an integer.
Equals(Libraries.Language.Object object)This action determines if two objects are equal based on their hash code values.
GetByteArray()This action returns the ByteArray that is currently being read from.
GetHashCode()This action gets the hash code for an object.
GetPosition()This action returns the current index position from which the ByteReader is currently reading.
HasNextInteger()This action checks if there are enough bytes remaining in the ByteArray to be assigned to an integer.
NextByteAsBoolean()This action reads the next byte from the ByteArray and converts it to a boolean.
NextByteAsInteger()This action reads the next byte from the ByteArray and converts it to an integer.
NextByteAsUnsignedInteger()This action reads the next byte from the ByteArray and converts it to an unsigned integer.
NextInteger()This action reads the next four bytes from the ByteArray and converts them to an integer.
NextIntegerConvertFromUnsigned()This action reads the next four bytes from the ByteArray and converts them to a signed integer.
NextLong()This action reads the next eight bytes from the ByteArray and converts them to a BigInteger.
NextNumber()This action reads the next eight bytes from the ByteArray and converts them to a number.
NextNumber4Byte()This action reads the next four bytes from the ByteArray and converts them to a number.
NextSubArray(integer amount)This action creates a sub-array of the ByteArray, starting from the current position, and then moves the position to read from to the next position in the array that comes after the end of this sub-array.
NextTextRead(integer amount)This action reads the next amount of characters from the ByteArray, sets them to a text object, and then returns it.
NextTextReadUnicode(integer amount)This action reads the next amount of characters from the ByteArray, sets them to a text object, and then returns it.
NextTextUntilCharacter(text character)This action reads the ByteArray up until it reads the specified character.
NextTwoByteInteger()This action reads the next two bytes from the ByteArray and converts them to an integer.
NextTwoByteUnsignedInteger()This action reads the next two bytes from the ByteArray and converts them to an unsigned integer.
SetByteArray(Libraries.Containers.ByteArray byteArray)This action sets the ByteArray that the ByteReader will read from.
SetPosition(integer newPosition)This action sets the current position within the ByteArray, used for moving around the array when reading various amounts of data, such as a byte, two bytes, and so on.
SkipBytes(integer amount)This action moves the current array reading position by the amount specified, either forward or backward.

Actions Documentation

CheckIfTrueTypeCollection()

This action checks if the font file being read is a .ttc file or not. If it is .ttc instead of .ttf, it has a different structure and must be read differently than a .ttf file. .ttc files always have the tag "ttcf" at the start of the file. Returns true if the file being read is a .ttc file, and false if it is a .ttf file.

Example Code

use Libraries.Containers.Support.ByteReader
        use Libraries.System.File
        use Libraries.Containers.ByteArray
        File file
        file:SetPath("files/Quorum.png")
        ByteArray value = file:ReadBytes()
        ByteReader reader
        reader:SetByteArray(value)
        boolean result = reader:CheckIfTrueTypeCollection()

Return

boolean: Returns true if the file is in .ttc format, and false otherwise.

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.

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.

GetByteArray()

This action returns the ByteArray that is currently being read from.

Example Code

use Libraries.Containers.Support.ByteReader
    use Libraries.System.File
    use Libraries.Containers.ByteArray
    File file
    file:SetPath("files/Quorum.png")
    ByteArray value = file:ReadBytes()
    ByteReader reader
    reader:SetByteArray(value)
    ByteArray copy = reader:GetByteArray()

Return

Libraries.Containers.ByteArray: Returns the ByteArray that is currently being read from.

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.

GetPosition()

This action returns the current index position from which the ByteReader is currently reading.

Example Code

use Libraries.Containers.Support.ByteReader
    use Libraries.System.File
    use Libraries.Containers.ByteArray
    File file
    file:SetPath("files/Quorum.png")
    ByteArray value = file:ReadBytes()
    ByteReader reader
    reader:SetByteArray(value)
    integer location = reader:GetPosition()

Return

integer: Returns the index value of the current position within the ByteArray.

HasNextInteger()

This action checks if there are enough bytes remaining in the ByteArray to be assigned to an integer.

Example Code

use Libraries.Containers.Support.ByteReader
    use Libraries.System.File
    use Libraries.Containers.ByteArray
    File file
    file:SetPath("files/Quorum.png")
    ByteArray value = file:ReadBytes()
    ByteReader reader
    reader:SetByteArray(value)
    boolean canRead = reader:HasNextInteger()

Return

boolean: Returns true if there are at least four bytes still in the array, and false if not.

NextByteAsBoolean()

This action reads the next byte from the ByteArray and converts it to a boolean.

Example Code

use Libraries.Containers.Support.ByteReader
    use Libraries.System.File
    use Libraries.Containers.ByteArray
    File file
    file:SetPath("files/Quorum.png")
    ByteArray value = file:ReadBytes()
    ByteReader reader
    reader:SetByteArray(value)
    boolean value = reader:NextByteAsBoolean()

Return

boolean: Returns the next byte in the ByteArray as a boolean value.

NextByteAsInteger()

This action reads the next byte from the ByteArray and converts it to an integer.

Example Code

use Libraries.Containers.Support.ByteReader
    use Libraries.System.File
    use Libraries.Containers.ByteArray
    File file
    file:SetPath("files/Quorum.png")
    ByteArray value = file:ReadBytes()
    ByteReader reader
    reader:SetByteArray(value)
    integer value = reader:NextByteAsInteger()

Return

integer: Returns the next byte in the ByteArray as an integer.

NextByteAsUnsignedInteger()

This action reads the next byte from the ByteArray and converts it to an unsigned integer.

Example Code

use Libraries.Containers.Support.ByteReader
    use Libraries.System.File
    use Libraries.Containers.ByteArray
    File file
    file:SetPath("files/Quorum.png")
    ByteArray value = file:ReadBytes()
    ByteReader reader
    reader:SetByteArray(value)
    integer value = reader:NextByteAsUnsignedInteger()

Return

integer: Returns the next byte in the ByteArray as an unsigned integer.

NextInteger()

This action reads the next four bytes from the ByteArray and converts them to an integer.

Example Code

use Libraries.Containers.Support.ByteReader
    use Libraries.System.File
    use Libraries.Containers.ByteArray
    File file
    file:SetPath("files/Quorum.png")
    ByteArray value = file:ReadBytes()
    ByteReader reader
    reader:SetByteArray(value)
    integer value = reader:NextInteger()

Return

integer: Returns the next four bytes in the ByteArray as an integer.

NextIntegerConvertFromUnsigned()

This action reads the next four bytes from the ByteArray and converts them to a signed integer.

Example Code

use Libraries.Containers.Support.ByteReader
    use Libraries.System.File
    use Libraries.Containers.ByteArray
    File file
    file:SetPath("files/Quorum.png")
    ByteArray value = file:ReadBytes()
    ByteReader reader
    reader:SetByteArray(value)
    integer value = reader:NextIntegerConvertFromUnsigned()

Return

integer: Returns the next four bytes in the ByteArray as a signed integer.

NextLong()

This action reads the next eight bytes from the ByteArray and converts them to a BigInteger.

Example Code

use Libraries.Containers.Support.ByteReader
    use Libraries.System.File
    use Libraries.Containers.ByteArray
    use Libraries.Compute.BigInteger
    File file
    file:SetPath("files/Quorum.png")
    ByteArray value = file:ReadBytes()
    ByteReader reader
    reader:SetByteArray(value)
    BigInteger largeNumber = reader:NextLong()

Return

Libraries.Compute.BigInteger: Returns the next eight bytes in the ByteArray as a BigInteger.

NextNumber()

This action reads the next eight bytes from the ByteArray and converts them to a number.

Example Code

use Libraries.Containers.Support.ByteReader
    use Libraries.System.File
    use Libraries.Containers.ByteArray
    File file
    file:SetPath("files/Quorum.png")
    ByteArray value = file:ReadBytes()
    ByteReader reader
    reader:SetByteArray(value)
    number value = reader:NextNumber()

Return

number: Returns the next eight bytes in the ByteArray as a number.

NextNumber4Byte()

This action reads the next four bytes from the ByteArray and converts them to a number.

Example Code

use Libraries.Containers.Support.ByteReader
    use Libraries.System.File
    use Libraries.Containers.ByteArray
    File file
    file:SetPath("files/Quorum.png")
    ByteArray value = file:ReadBytes()
    ByteReader reader
    reader:SetByteArray(value)
    number value = reader:NextNumber4Byte()

Return

number: Returns the next four bytes in the ByteArray as a number.

NextSubArray(integer amount)

This action creates a sub-array of the ByteArray, starting from the current position, and then moves the position to read from to the next position in the array that comes after the end of this sub-array.

Example Code

use Libraries.Containers.Support.ByteReader
    use Libraries.System.File
    use Libraries.Containers.ByteArray
    File file
    file:SetPath("files/Quorum.png")
    ByteArray value = file:ReadBytes()
    ByteReader reader
    reader:SetByteArray(value)
    ByteArray small = reader:NextSubArray(1)

Parameters

Return

Libraries.Containers.ByteArray: Returns a sub-array of the ByteArray.

NextTextRead(integer amount)

This action reads the next amount of characters from the ByteArray, sets them to a text object, and then returns it.

Example Code

use Libraries.Containers.Support.ByteReader
    use Libraries.System.File
    use Libraries.Containers.ByteArray
    File file
    file:SetPath("files/Quorum.png")
    ByteArray value = file:ReadBytes()
    ByteReader reader
    reader:SetByteArray(value)
    text word = reader:NextTextRead(5)

Parameters

Return

text: Returns the characters read from the ByteArray as a text.

NextTextReadUnicode(integer amount)

This action reads the next amount of characters from the ByteArray, sets them to a text object, and then returns it. Unicode encoding uses 2 bytes per character.

Example Code

use Libraries.Containers.Support.ByteReader
        use Libraries.System.File
        use Libraries.Containers.ByteArray
        File file
        file:SetPath("files/Quorum.png")
        ByteArray value = file:ReadBytes()
        ByteReader reader
        reader:SetByteArray(value)
        text word = reader:NextTextReadUnicode(5)

Parameters

Return

text: Returns the characters read from the ByteArray as text.

NextTextUntilCharacter(text character)

This action reads the ByteArray up until it reads the specified character. Once found, it returns all of the characters that were read as a text. For example, if you want to read up until 'g', you may read 'd', then 'o', then 'g', at which point it will stop reading the file and return 'dog'.

Example Code

use Libraries.Containers.Support.ByteReader
    use Libraries.System.File
    use Libraries.Containers.ByteArray
    File file
    file:SetPath("files/Quorum.png")
    ByteArray value = file:ReadBytes()
    ByteReader reader
    reader:SetByteArray(value)
    text word = reader:NextTextUntilCharacter("z")

Parameters

Return

text: Returns the text of all characters read.

NextTwoByteInteger()

This action reads the next two bytes from the ByteArray and converts them to an integer.

Example Code

use Libraries.Containers.Support.ByteReader
    use Libraries.System.File
    use Libraries.Containers.ByteArray
    File file
    file:SetPath("files/Quorum.png")
    ByteArray value = file:ReadBytes()
    ByteReader reader
    reader:SetByteArray(value)
    integer value = reader:NextTwoByteInteger()

Return

integer: Returns the next two bytes in the ByteArray as an integer.

NextTwoByteUnsignedInteger()

This action reads the next two bytes from the ByteArray and converts them to an unsigned integer.

Example Code

use Libraries.Containers.Support.ByteReader
    use Libraries.System.File
    use Libraries.Containers.ByteArray
    File file
    file:SetPath("files/Quorum.png")
    ByteArray value = file:ReadBytes()
    ByteReader reader
    reader:SetByteArray(value)
    integer value = reader:NextTwoBytesUnsignedInteger()

Return

integer: Returns the next two bytes in the ByteArray as an unsigned integer.

SetByteArray(Libraries.Containers.ByteArray byteArray)

This action sets the ByteArray that the ByteReader will read from.

Example Code

use Libraries.Containers.Support.ByteReader
    use Libraries.System.File
    use Libraries.Containers.ByteArray
    File file
    file:SetPath("files/Quorum.png")
    ByteArray value = file:ReadBytes()
    ByteReader reader
    reader:SetByteArray(value)

Parameters

SetPosition(integer newPosition)

This action sets the current position within the ByteArray, used for moving around the array when reading various amounts of data, such as a byte, two bytes, and so on.

Example Code

use Libraries.Containers.Support.ByteReader
    use Libraries.System.File
    use Libraries.Containers.ByteArray
    File file
    file:SetPath("files/Quorum.png")
    ByteArray value = file:ReadBytes()
    ByteReader reader
    reader:SetByteArray(value)
    reader:SetPosition(1)

Parameters

Return

boolean: Returns true if the index is valid and was set properly, or false if the index provided is illegal.

SkipBytes(integer amount)

This action moves the current array reading position by the amount specified, either forward or backward. Useful for skipping data that you do not need to read.

Example Code

use Libraries.Containers.Support.ByteReader
    use Libraries.System.File
    use Libraries.Containers.ByteArray
    File file
    file:SetPath("files/Quorum.png")
    ByteArray value = file:ReadBytes()
    ByteReader reader
    reader:SetByteArray(value)
    reader:SkipBytes(10)

Parameters