Libraries.Data.Formats.SeparatedValueFileReader Documentation

This class reads in text and separates it into lines. It loads the text from the file when the first ReadLine or ReadLines call is issued and not before.

Example Code

use Libraries.Data.Formats.SeparatedValueFileReader
    use Libraries.Containers.Array
    use Libraries.System.File

    SeparatedValueFileReader reader
    File file
    file:SetPath("file.csv")
    reader:OpenForRead(file)
    Array<text> value = reader:ReadLines

Inherits from: Libraries.System.FileReader, Libraries.System.Blueprints.FileReaderBlueprint, Libraries.Language.Object

Summary

Actions Summary Table

ActionsDescription
Close()When we open a file for reading, it is marked by the operating system as being in use by our application.
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.
GetCharacterIndex()If ReadLine is being called, this returns the current index being processe
GetCharacterSize()This returns the number of characters that were read in the file.
GetHashCode()This action gets the hash code for an object.
GetStoreLines()Returns true if we store lines on every call to ReadLin
IsAtEndOfFile()This action returns true if we have finished reading the file.
OpenForRead(Libraries.System.File file)Open a file for sequential reading.
Read(integer numberOfBytes)This action reads the specified number of bytes after our current position.
Read()This action reads all of the contents of our file from the current position.
ReadLine()This action reads one line from the loaded text.
ReadLines()This class reads the entire file into an array.
SetStoreLines(boolean storeLines)Sets whether or not we store lines on every call to ReadLin

Actions Documentation

Close()

When we open a file for reading, it is marked by the operating system as being in use by our application. To make it possible for other files to use this file at a later point in time, it is necessary to tell the operating system when we are done with this file. To do this, we use the Close() action. We should call Close() as soon as we know that a file is no longer needed. If no file is open, Close() will do nothing. After Close() is called, a FileReader object is considered invalid, and no actions should be called on it, other than OpenForRead(), to open the same (or different) file.

Example Code

use Libraries.System.File
        use Libraries.System.FileReader

        // Open a file, read all the contents and close it.
        File f
        f:SetPath("To Do List.txt")
        FileReader reader
        reader:OpenForRead(f)

        output "Tim, your to do list says:"
        output reader:Read()
        
        // Close the file, as we no longer need it.
        reader:Close

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 (smalle

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(

Parameters

Return

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

GetCharacterIndex()

If ReadLine is being called, this returns the current index being processe

Return

integer:

GetCharacterSize()

This returns the number of characters that were read in the file.

Return

integer: the number of characte

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.

GetStoreLines()

Returns true if we store lines on every call to ReadLin

Return

boolean:

IsAtEndOfFile()

This action returns true if we have finished reading the file.

Return

boolean: true if we have finished readin

OpenForRead(Libraries.System.File file)

Open a file for sequential reading. By "sequential reading," it is meant that it is impossible to go backwards in the file--we must make progress toward the end of the file with each successive read. This is extremely useful for reading plain text documents, but is much less useful for reading binary files. Binary files should use the FileRandomAccess class.

Example Code

use Libraries.System.File
        use Libraries.System.FileReader

        // Open the file for reading.
        File f
        f:SetPath("homework.txt")
        
        // Read the first two lines and then be done.
        FileReader reader
        reader:OpenForRead(f)
        output reader:ReadLine()
        output reader:ReadLine()

        // Always close the file.
        reader:Close

Parameters

Read(integer numberOfBytes)

This action reads the specified number of bytes after our current position. When we open a file, we start at the beginning--calling this action with a parameter of, for example, 2, would read the first two bytes of the file. If we perform some other reading action such as ReadLine(), and then call this action, the specified number of bytes will be read after our current position. If the number of bytes specified exceeds the end of the file, content up to the end of the file will be returned. If the end of the file has been reached before this action is called, an EndOfFileError will be raised.

Example Code

use Libraries.System.File
        use Libraries.System.FileReader

        // Open a file, output the first four bytes.
        File f
        f:SetPath("Settings.dat")
        FileReader reader
        reader:OpenForRead(f)
        output "The first four bytes are " + reader:Read(4)
        reader:Close

Parameters

Return

text: the file contents we have read

Read()

This action reads all of the contents of our file from the current position. When we open a file, we start at the beginning--so calling this action immediately after opening a file will read the entire file. If we perform some other reading action, such as ReadLine(), and then call this action, we will receive all file contents after the point where we have read. If the end of file has already been reached before calling this action, an EndOfFileError will be raised.

Example Code

use Libraries.System.File
        use Libraries.System.FileReader

        // Open a file, read all of its contents to a text value and then  output the text value.
        File f
        f:SetPath("Settings.dat")
        FileReader reader
        reader:OpenForRead(f)
        text settings = reader:Read()

        output "The settings are:"
        output settings
        reader:Close

Return

text: the file contents from our current position to the end of the file.

ReadLine()

This action reads one line from the loaded text. By default, it stores the line in an array, in addition to returning it. This can be turned off by calling SetStoreLines(false)

Example Code

use Libraries.Data.Formats.SeparatedValueFileReader
        use Libraries.Containers.Array
        use Libraries.System.File
    
        SeparatedValueFileReader reader
        File file
        file:SetPath("file.csv")
        reader:OpenForRead(file)
        output reader:ReadLine

Return

text:

ReadLines()

This class reads the entire file into an array. If ReadLine has been called prior to this action being called, with SetStoreLines set to false, then this begins filling the array from this point. If called from the beginning, this action ignores the value of SetStoreLines, because otherwise this would be guaranteed to return an empty array.

Example Code

use Libraries.Data.Formats.SeparatedValueFileReader
        use Libraries.Containers.Array
        use Libraries.System.File
    
        SeparatedValueFileReader reader
        File file
        file:SetPath("file.csv")
        reader:OpenForRead(file)
        Array<text> value = reader:ReadLines

Return

Libraries.Containers.Array: an array with all lines in the file.

SetStoreLines(boolean storeLines)

Sets whether or not we store lines on every call to ReadLin

Parameters