ByteReader
Package: Libraries.Containers.Support · Inherits from: Libraries.Language.Object
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
Actions
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.
Returns
boolean: Returns true if the file is in .ttc format, and false otherwise.
Example
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()
GetByteArray()
This action returns the ByteArray that is currently being read from.
Returns
Libraries.Containers.ByteArray: Returns the ByteArray that is currently being read from.
Example
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()
GetPosition()
This action returns the current index position from which the ByteReader is currently reading.
Returns
integer: Returns the index value of the current position within
the ByteArray.
Example
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()
HasNextInteger()
This action checks if there are enough bytes remaining in the ByteArray to be assigned to an integer.
Returns
boolean: Returns true if there are at least four bytes still in
the array, and false if not.
Example
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()
NextByteAsBoolean()
This action reads the next byte from the ByteArray and converts it to a boolean.
Returns
boolean: Returns the next byte in the ByteArray as a boolean value.
Example
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()
NextByteAsInteger()
This action reads the next byte from the ByteArray and converts it to an integer.
Returns
integer: Returns the next byte in the ByteArray as an integer.
Example
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()
NextByteAsUnsignedInteger()
This action reads the next byte from the ByteArray and converts it to an unsigned integer.
Returns
integer: Returns the next byte in the ByteArray as an unsigned integer.
Example
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()
NextInteger()
This action reads the next four bytes from the ByteArray and converts them to an integer.
Returns
integer: Returns the next four bytes in the ByteArray as an integer.
Example
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()
NextIntegerConvertFromUnsigned()
This action reads the next four bytes from the ByteArray and converts them to a signed integer.
Returns
integer: Returns the next four bytes in the ByteArray as a signed
integer.
Example
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()
NextLong()
This action reads the next eight bytes from the ByteArray and converts them to a BigInteger.
Returns
Libraries.Compute.BigInteger: Returns the next eight bytes in the ByteArray as a BigInteger.
Example
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()
NextNumber()
This action reads the next eight bytes from the ByteArray and converts them to a number.
Returns
number: Returns the next eight bytes in the ByteArray as a number.
Example
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()
NextNumber4Byte()
This action reads the next four bytes from the ByteArray and converts them to a number.
Returns
number: Returns the next four bytes in the ByteArray as a number.
Example
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()
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.
Parameters
amountinteger: The number of items to grab from the ByteArray and store in the new sub-array.
Returns
Libraries.Containers.ByteArray: Returns a sub-array of the ByteArray.
Example
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)
NextTextRead(integer amount)
This action reads the next amount of characters from the ByteArray, sets them to a text object, and then returns it.
Parameters
amountinteger: The number of characters to read from the ByteArray.
Returns
text: Returns the characters read from the ByteArray as a text.
Example
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)
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.
Parameters
amountinteger: The number of characters to read from the ByteArray
Returns
text: Returns the characters read from the ByteArray as text.
Example
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)
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'.
Parameters
charactertext: The character that signifies when you want to stop reading the file.
Returns
text: Returns the text of all characters read.
Example
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")
NextTwoByteInteger()
This action reads the next two bytes from the ByteArray and converts them to an integer.
Returns
integer: Returns the next two bytes in the ByteArray as an integer.
Example
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()
NextTwoByteUnsignedInteger()
This action reads the next two bytes from the ByteArray and converts them to an unsigned integer.
Returns
integer: Returns the next two bytes in the ByteArray as an unsigned
integer.
Example
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()
SetByteArray(Libraries.Containers.ByteArray byteArray)
This action sets the ByteArray that the ByteReader will read from.
Parameters
byteArrayLibraries.Containers.ByteArray: The ByteArray to set as the array to read from.
Example
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)
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.
Parameters
newPositioninteger: The array index to set the current reading position to.
Returns
boolean: Returns true if the index is valid and was set properly,
or false if the index provided is illegal.
Example
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)
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.
Parameters
amountinteger: The number of items to skip over in the ByteArray.
Example
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)