Search in sources :

Example 1 with FilePart

use of im.actor.runtime.files.FilePart in project actor-platform by actorapp.

the class JsFileInput method read.

@Override
public Promise<FilePart> read(int fileOffset, int len) {
    return new Promise<>(resolver -> {
        JsFileReader fileReader = JsFileReader.create();
        fileReader.setOnLoaded(message -> {
            Uint8Array array = TypedArrays.createUint8Array(message);
            byte[] data = new byte[len];
            for (int i = 0; i < len; i++) {
                data[i] = (byte) (array.get(i));
            }
            resolver.result(new FilePart(fileOffset, len, data));
        });
        fileReader.readAsArrayBuffer(jsFile.slice(fileOffset, fileOffset + len));
    });
}
Also used : Promise(im.actor.runtime.promise.Promise) Uint8Array(com.google.gwt.typedarrays.shared.Uint8Array) FilePart(im.actor.runtime.files.FilePart)

Example 2 with FilePart

use of im.actor.runtime.files.FilePart in project actor-platform by actorapp.

the class AndroidInputFile method read.

@Override
public Promise<FilePart> read(int fileOffset, int len) {
    return new Promise<>(resolver -> {
        executor.execute(() -> {
            try {
                byte[] data = new byte[len];
                randomAccessFile.seek(fileOffset);
                randomAccessFile.read(data, 0, len);
                resolver.result(new FilePart(fileOffset, len, data));
            } catch (Exception e) {
                e.printStackTrace();
                resolver.error(e);
            }
        });
    });
}
Also used : Promise(im.actor.runtime.promise.Promise) FilePart(im.actor.runtime.files.FilePart) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

FilePart (im.actor.runtime.files.FilePart)2 Promise (im.actor.runtime.promise.Promise)2 Uint8Array (com.google.gwt.typedarrays.shared.Uint8Array)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1