public class FileReader extends Object implements com.google.gwt.event.dom.client.HasLoadHandlers, HasLoadStartHandlers, HasLoadEndHandlers, HasAbortHandlers, HasProgressHandlers, HasErrorHandlers
FileReader
object lets web applications
asynchronously read the contents of files (or raw data buffers) stored on the
user's computer, using File
or
Blob
objects to specify the file or data to read.
File objects may be obtained in one of two ways: from a FileList object
returned as a result of a user selecting files using the <input> element, or
from a drag and drop operation's DataTransferExt
object.
To create a FileReader
, simply do the following:
FileReader reader = new FileReader();
Modifier and Type | Class and Description |
---|---|
static class |
FileReader.State
Enum to represent FileReader state constants.
|
Modifier and Type | Field and Description |
---|---|
protected static com.google.gwt.event.shared.EventBus |
eventBus |
Constructor and Description |
---|
FileReader()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
abort()
Aborts the read operation.
|
com.google.gwt.event.shared.HandlerRegistration |
addAbortHandler(AbortHandler handler)
Adds a
AbortHandler handler. |
protected <H extends com.google.gwt.event.shared.EventHandler> |
addDomHandler(H handler,
com.google.gwt.event.dom.client.DomEvent.Type<H> type) |
com.google.gwt.event.shared.HandlerRegistration |
addErrorHandler(ErrorHandler handler)
Adds a
ErrorHandler handler. |
com.google.gwt.event.shared.HandlerRegistration |
addLoadEndHandler(LoadEndHandler handler)
Adds a
LoadEndHandler handler. |
com.google.gwt.event.shared.HandlerRegistration |
addLoadHandler(com.google.gwt.event.dom.client.LoadHandler handler) |
com.google.gwt.event.shared.HandlerRegistration |
addLoadStartHandler(LoadStartHandler handler)
Adds a
LoadStartHandler handler. |
com.google.gwt.event.shared.HandlerRegistration |
addProgressHandler(ProgressHandler handler)
Adds a
ProgressHandler handler. |
void |
dispatch(com.google.gwt.dom.client.NativeEvent event)
Dispatches the specified event to this node
event handlers
|
void |
fireEvent(com.google.gwt.event.shared.GwtEvent<?> event) |
com.google.gwt.typedarrays.shared.ArrayBuffer |
getArrayBufferResult()
Returns the file's contents.
|
FileError |
getError() |
FileReader.State |
getReadyState()
Indicates the state of the FileReader.
|
String |
getResult()
Deprecated.
As of version 0.3, users should use the
getStringResult()
or getArrayBufferResult() depending on the kind of return which is
expected. |
String |
getStringResult()
Returns the file's contents.
|
void |
readAsArrayBuffer(Blob fileBlob)
|
void |
readAsBinaryString(Blob fileBlob)
|
void |
readAsDataURL(Blob fileBlob)
|
void |
readAsText(Blob fileBlob)
|
void |
readAsText(Blob fileBlob,
String encoding)
|
public FileReader.State getReadyState()
FileReader.State
constants. Read only.public String getResult()
getStringResult()
or getArrayBufferResult()
depending on the kind of return which is
expected.public String getStringResult()
readAsBinaryString(org.vectomatic.file.Blob)
,
readAsText(org.vectomatic.file.Blob)
,
readAsText(org.vectomatic.file.Blob, java.lang.String)
or
readAsDataURL(org.vectomatic.file.Blob)
).public com.google.gwt.typedarrays.shared.ArrayBuffer getArrayBufferResult()
readAsArrayBuffer(org.vectomatic.file.Blob)
) is
complete.public FileError getError()
public void abort()
FileReader.State.DONE
.public void readAsBinaryString(Blob fileBlob)
Blob
, which may be a
File
. When the read operation is finished,
the getReadyState()
will become
FileReader.State.DONE
, and the
LoadEndEvent
event, if any, will be
fired. At that time, the getStringResult()
provides access to
the raw binary data from the file.public void readAsText(Blob fileBlob)
Blob
, which may be a
File
. When the read operation is finished,
the getReadyState()
will become
FileReader.State.DONE
, and the
LoadEndEvent
event, if any, will be
fired. At that time, the getStringResult()
provides access to
the contents of the file as a text string.public void readAsText(Blob fileBlob, String encoding)
Blob
, which may be a
File
. When the read operation is finished,
the getReadyState()
will become
FileReader.State.DONE
, and the
LoadEndEvent
event, if any, will be
fired. At that time, the getStringResult()
provides access to
the contents of the file as a text string.public void readAsDataURL(Blob fileBlob)
Blob
, which may be a
File
. When the read operation is finished,
the getReadyState()
will become
FileReader.State.DONE
, and the
LoadEndEvent
event, if any, will be
fired. At that time, the getStringResult()
provides access to
the contents of the file as a data: URL representing the file's data.public void readAsArrayBuffer(Blob fileBlob)
Blob
, which may be a
File
. When the read operation is finished,
the getReadyState()
will become
FileReader.State.DONE
, and the
LoadEndEvent
event, if any, will be
fired. At that time, the getArrayBufferResult()
provides access to
an ArrayBuffer
representing the file's data.public void dispatch(com.google.gwt.dom.client.NativeEvent event)
event
- The event to dispatchpublic void fireEvent(com.google.gwt.event.shared.GwtEvent<?> event)
fireEvent
in interface com.google.gwt.event.shared.HasHandlers
protected final <H extends com.google.gwt.event.shared.EventHandler> com.google.gwt.event.shared.HandlerRegistration addDomHandler(H handler, com.google.gwt.event.dom.client.DomEvent.Type<H> type)
public com.google.gwt.event.shared.HandlerRegistration addErrorHandler(ErrorHandler handler)
HasErrorHandlers
ErrorHandler
handler.addErrorHandler
in interface HasErrorHandlers
handler
- the begin handlerHandlerRegistration
used to remove this handlerpublic com.google.gwt.event.shared.HandlerRegistration addProgressHandler(ProgressHandler handler)
HasProgressHandlers
ProgressHandler
handler.addProgressHandler
in interface HasProgressHandlers
handler
- the begin handlerHandlerRegistration
used to remove this handlerpublic com.google.gwt.event.shared.HandlerRegistration addAbortHandler(AbortHandler handler)
HasAbortHandlers
AbortHandler
handler.addAbortHandler
in interface HasAbortHandlers
handler
- the begin handlerHandlerRegistration
used to remove this handlerpublic com.google.gwt.event.shared.HandlerRegistration addLoadEndHandler(LoadEndHandler handler)
HasLoadEndHandlers
LoadEndHandler
handler.addLoadEndHandler
in interface HasLoadEndHandlers
handler
- the begin handlerHandlerRegistration
used to remove this handlerpublic com.google.gwt.event.shared.HandlerRegistration addLoadStartHandler(LoadStartHandler handler)
HasLoadStartHandlers
LoadStartHandler
handler.addLoadStartHandler
in interface HasLoadStartHandlers
handler
- the begin handlerHandlerRegistration
used to remove this handlerpublic com.google.gwt.event.shared.HandlerRegistration addLoadHandler(com.google.gwt.event.dom.client.LoadHandler handler)
addLoadHandler
in interface com.google.gwt.event.dom.client.HasLoadHandlers
Copyright © 2017. All Rights Reserved.