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));
});
}
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);
}
});
});
}
Aggregations