Skip to content

Reader


abstract class Reader < Iterator<Buffer>

Read data from a file.

classDiagram class Iterator~Buffer~ { hasNext() Boolean next() Buffer } Iterator~Buffer~ <|-- Reader Reader <|-- YAMLReader Reader <|-- JSONReader YAMLReader -- JSONReader link Iterator "../Iterator/" link Reader "../Reader/" link YAMLReader "../YAMLReader/" link JSONReader "../JSONReader/"

Typical use is to use the Reader factory function to instantiate an object of an appropriate derived class based on the file extension of the given path:

let reader <- make_reader(path);

The whole contents of the file can be read at once with:

let buffer <- reader.slurp();

Alternatively, where the root element of the file is an array, the contents may be read sequentially, one element at a time, using the Iterator interface, from which Reader derives.

Finally, close the file:

reader.close();

Member Functions

Name Description
open Open a file.
slurp Read the whole contents of the file into a buffer.
close Close the file.

Member Function Details

close

abstract function close()

Close the file.

open

abstract function open(path:String)

Open a file.

  • path: Path of the file.

slurp

abstract function slurp() -> Buffer

Read the whole contents of the file into a buffer.

Returns: Buffer with the file contents.