Interface org.as2lib.io.file.FileLoader

Description

FileLoader is built to handle the loading of a external files.

A FileLoader allows to get a resource and create a representation of the certain file to allow proper access.

It is build to handle the loading of one file. But it can be executed twice or more often. This is because its possible to handle more than one request parallel in any system.

Example to handle the loading of a resource: import org.as2lib.io.file.AbstractFileLoader; import org.as2lib.io.file.FileLoader; import org.as2lib.io.file.LoadStartListener; import org.as2lib.io.file.LoadCompleteListener; import org.as2lib.io.file.LoadProgressListener; import org.as2lib.io.file.LoadErrorListener; class Main implements LoadStartListener, LoadCompleteListener, LoadErrorListener, LoadProgressListener { public function main(loader:FileLoader):Void { loader.addListener(this); loader.load("test.txt"); } public function onLoadComplete(loader:FileLoader):Void { var resource = loader.getFile(); // Do anything you like.... } public function onLoadError(loader:FileLoader, errorCode:String, error):Boolean { if (errorCode == AbstractFileLoader.FILE_NOT_FOUND_ERROR) { trace("Resource could not be found"+error); } return false } public function onLoadProgress(loader:FileLoader):Void { trace("loaded: "+loader.getPercentage()+"% of "+loader.getUri()); } public function onLoadStart(loader:FileLoader):Void { trace("started loading: "+loader.getUri()); } }

Method Index

getBytesLoaded(), getBytesTotal(), getDuration(), getEstimatedRestTime(), getEstimatedTotalTime(), getFile(), getParameters(), getParameterSubmitMethod(), getPercentage(), getTransferRate(), getUri(), load()

Inherited from EventListenerSource

Inherited from BasicInterface

Method Detail

load

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

Loads a certain resource.

It sends http request by using the passed-in uri, method and parameters.

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

Example of using the callback: import org.as2lib.io.file.FileLoader; import org.as2lib.app.exec.Call; class Main { public function main(loader:FileLoader) { loader.load("test.txt", null, null, new Call(this, resource); } public function finish(resource:Resource):Void { // Processing the resource ... } }

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.
callBack(optional) Executable to be executed after the the resource was loaded.

getUri

public function getUri(Void):String

Returns the URI of the resource that was requested to load.

Return

URI of the resource to load

getParameterSubmitMethod

public function getParameterSubmitMethod(Void):String

Returns the method to pass request parameters for request.

Return

method to pass request parameters

getParameters

public function getParameters(Void):Map

Sets the parameters for the request to the resource.

Returns null if no parameters has been set.

Return

parameters to be passed with the resource request

getFile

public function getFile(Void):File

Returns the loaded file.

Return

the loaded file

Throws

org.as2lib.io.file.ResourceNotLoadedExceptionif the resource has not been loaded yet

getPercentage

public function getPercentage(Void):Number

Returns the percentage of the execution of null if its not evaluable.

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

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

getTransferRate

public function getTransferRate(Void):Bit

Returns the current transfer rate for the execution.

Return

transfer rate in bit (per second)

getEstimatedRestTime

public function getEstimatedRestTime(Void):Time

Estimates the approximate time until the resource was loaded.

Return

estimated time until finish of loading

getEstimatedTotalTime

public function getEstimatedTotalTime(Void):Time

Estimates the approximate time for the complete loading.

Return

estimated duration at the end of the loading

getDuration

public function getDuration(Void):Time

Returns the duration it loads the certain resource.

Return

time difference between start time and end time/current time.