Class org.as2lib.io.file.TextFileLoader

Implemented Interfaces

FileLoader

Description

TextFileLoader is a implementation of FileLoader for text resources.

Any ASCII/Unicode readable resource is ment as "Text resource". TextFileLoader is a implementation for those resources and generates a TextFile implementation with the loaded content.

TextFileFactory allows to generate different TextFile implementations for the loaded content.

TextFileLoader represents the time consuming part of accessing files ( TextFile is the handleable part} and therefore contains a event system to add listeners to listen to the concrete events. It is possible to add listeners using addListener.

Example listener: import org.as2lib.io.file.AbstractFileLoader; import org.as2lib.io.file.LoadProgressListener; import org.as2lib.io.file.LoadStartListener; import org.as2lib.io.file.LoadCompleteListener; import org.as2lib.io.file.LoadErrorListener; import org.as2lib.io.file.FileLoader; import org.as2lib.io.file.TextFile; class MyFileListener implements LoadProgressListener, LoadStartListener, LoadCompleteListener, LoadErrorListener { public function onLoadComplete(fileLoader:FileLoader):Void { var file:TextFile = TextFile(fileLoader.getFile()); if (file != null) { // Proper file available } else { // Wrong event handled } } public function onLoadError(fileLoader:FileLoader, errorCode:String, error):Void { if (errorCode == AbstractFileLoader.FILE_NOT_FOUND) { var notExistantUrl = error; // Use that url } } public function onLoadStart(fileLoader:FileLoader) { // show that this file just gets loaded } public function onLoadProgress(fileLoader:FileLoader) { // update the percentage display with resourceLoader.getPercentage(); } }

Example of the usage: import org.as2lib.io.file.TextFileLoader; var fileLoader:TextFileLoader = new TextFileLoader(); fileLoader.addListener(new MyFileListener()); fileLoader.load("test.txt");

Field Index

Inherited from AbstractFileLoader

Inherited from LogSupport

Method Index

new TextFileLoader()
getBytesLoaded(), getBytesTotal(), getFile(), getTextFile(), load()

Inherited from AbstractFileLoader

Inherited from AbstractTimeConsumer

Inherited from EventSupport

Inherited from LogSupport

Inherited from BasicClass

Constructor Detail

TextFileLoader

public function TextFileLoader(textFileFactory:TextFileFactory)

Constructs a new TextFileLoader.

Parameters

textFileFactory(optional)
 TextFileFactory to create the
implementations, SimpleTextFileFactory gets used if no custom TextFileFactory gets passed-in

Method Detail

load

public function load(uri:String, method:String, parameters:Map, callBack:Executable):Void

Loads a certain text file by a http request.

It sends http request by using the passed-in uri, method and parameters. The responding file will be passed to the set TextFileFactory.

If you only need to listen if the TextFile finished loading you can apply a callBack that gets called if the TextFile is loaded.

Parameters

urilocation of the resource to load
method(optional) POST/GET as method for submitting the parameters, default method used if method was not passed-in is POST.
parameters(optional) parameters for loading the resource
callBack(optional) Executable to be executed after the the resource was loaded.

Specified By

load() in org.as2lib.io.file.FileLoader

Overrides

load() in org.as2lib.io.file.AbstractFileLoader

getFile

public function getFile(Void):File

Returns the loaded File.

Return

File that has been loaded

Throws

FileNotLoadedExceptionif the resource has not been loaded yet

Specified By

getFile() in org.as2lib.io.file.FileLoader

Overrides

getFile() in org.as2lib.io.file.AbstractFileLoader

getTextFile

public function getTextFile(Void):TextFile

Returns the loaded TextFile.

Return

TextFile that has been loaded

Throws

FileNotLoadedExceptionif the resource has not been loaded yet

getBytesLoaded

public function getBytesLoaded(Void):Byte

Returns the total amount of bytes that has been loaded.

Returns null if its not possible to get the loaded bytes.

Return

amount of bytes that has been loaded

Specified By

getBytesLoaded() in org.as2lib.io.file.FileLoader

Overrides

getBytesLoaded() in org.as2lib.io.file.AbstractFileLoader

getBytesTotal

public function getBytesTotal(Void):Byte

Returns the total amount of bytes that will approximately be loaded.

Returns null if its not possible to get the total amount of bytes.

Return

amount of bytes to load

Specified By

getBytesTotal() in org.as2lib.io.file.FileLoader

Overrides

getBytesTotal() in org.as2lib.io.file.AbstractFileLoader