-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathFileReader.java
More file actions
44 lines (39 loc) · 1.14 KB
/
FileReader.java
File metadata and controls
44 lines (39 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package snap.webapi;
/**
* This class is a wrapper for Web API FileReader (https://developer.mozilla.org/en-US/docs/Web/API/FileReader).
*/
public class FileReader extends JSProxy implements EventTarget {
/**
* Constructor.
*/
public FileReader()
{
super(WebEnv.get().newFileReaderJS());
}
/**
* Starts reading the contents of a specified Blob or File.
* When the read operation is finished, the readyState becomes DONE, and the loadend is triggered.
* At that time, the result attribute contains an ArrayBuffer representing the file's data.
*/
public void readAsArrayBuffer(Blob aBlob)
{
call("readAsArrayBuffer", aBlob._jsObj);
}
/**
* Returns the bytes.
*/
public byte[] getResultBytes()
{
Object arrayBufferJS = getMember("result");
ArrayBuffer arrayBuffer = new ArrayBuffer(arrayBufferJS);
return arrayBuffer.getBytes();
}
/**
* readBytesAndWait
*/
public void readBytesAndRunLater(Blob aBlob, Runnable aRun)
{
addEventListener("loadend", e -> aRun.run());
readAsArrayBuffer(aBlob);
}
}