com.google.android.gms.drive.DriveContents |
A reference to a Drive file's contents. There are two types of DriveContents
:
DriveFile
. This type is obtained through
openFile(DriveFile, int)
.
createContents()
.
Any changes made to the DriveContents
through either their ParcelFileDescriptor
or OutputStream
will not be visible until either commitContents(DriveContents, MetadataChangeSet)
is executed (for existing contents already associated to a
DriveFile
), or a new file is created using this contents (through createFile(DriveFolder, MetadataChangeSet, DriveContents)
or CreateFileActivityOptions
, for new contents).
In both cases, the discardContents(DriveContents)
method can be
used to discard any changes to any kind of DriveContents
, so those changes will never be
applied to a DriveFile
or persisted in Drive.
Once this DriveContents
instance has been committed, used for creation, or discarded,
it becomes closed and any subsequent method call will throw an IllegalStateException
.
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
This method is deprecated.
Use
commitContents(DriveContents, MetadataChangeSet, ExecutionOptions) instead.
| |||||||||||
This method is deprecated.
Use
commitContents(DriveContents, MetadataChangeSet)
instead.
| |||||||||||
This method is deprecated.
Use
discardContents(DriveContents) instead.
| |||||||||||
Gets the
DriveId for the file that owns these contents. | |||||||||||
Returns an
InputStream that allows you to read this file's contents. | |||||||||||
Gets the mode the contents are opened in.
| |||||||||||
Returns an
OutputStream that allows you to write new contents. | |||||||||||
Returns a
ParcelFileDescriptor that points to the Drive file's contents. | |||||||||||
This method is deprecated.
Use
reopenContentsForWrite(DriveContents) instead.
|
This method is deprecated.
Use commitContents(DriveContents, MetadataChangeSet, ExecutionOptions)
instead.
Advanced version of commit which commits this contents and updates the metadata (if provided)
of the file associated to this DriveContents
instance and allows the client to specify
a conflict resolution strategy or request completion notifications via the executionOptions
parameter.
A file conflict happens when the written contents are not applied on top of the file revision that Drive originally provided when the contents were read by the application. A conflict could happen when an application reads contents at revision X, then writes revision X+1 and by the time X+1 is committed (or uploaded to the server), the file version is not X anymore (another app or a remote change already modified the file to revision X').
This method should only be used on DriveContents
that are already associated to a
particular file. See setConflictStrategy(int)
for details on
using each conflict strategy.
After this method returns, this instance will be closed and will no longer be usable.
Parameters | |
---|---|
apiClient |
GoogleApiClient : The GoogleApiClient to service the call. The client must be connected
before invoking this method. |
changeSet |
MetadataChangeSet : The set of changes that will be applied to the Metadata of the file associated
to this contents instance. Should only include the specific fields that should be updated.
Can be null if no metadata changes should be applied with this commit. |
executionOptions |
ExecutionOptions : Contains any extra settings for this commit action, such as the
strategy for handling conflicts or whether the client should be notified of failures when
applying this operation on the server. See ExecutionOptions for more info. When
null is provided, this method will use default ExecutionOptions , that is
CONFLICT_STRATEGY_OVERWRITE_REMOTE strategy, no completion event
requested and no operation tag. |
Returns | |
---|---|
PendingResult<Status> |
A PendingResult which can be used to verify the success of the operation. |
Throws | |
---|---|
IllegalStateException |
If one of the following is true:
|
This method is deprecated.
Use commitContents(DriveContents, MetadataChangeSet)
instead.
Commits this contents and updates the metadata (if provided) of the file associated to this
DriveContents
instance. This method should only be used on DriveContents
that
are already associated to a particular file (obtained through open(GoogleApiClient, int, DriveFile.DownloadProgressListener)
).
This method behaves like commit(GoogleApiClient, MetadataChangeSet, ExecutionOptions)
with null
ExecutionOptions
, which means CONFLICT_STRATEGY_OVERWRITE_REMOTE
strategy, no completion event requested
and no operation tag. Use the advanced version of commit
if you'd like to specify different ExecutionOptions
.
After this method returns, this instance will be closed and will no longer be usable.
Parameters | |
---|---|
apiClient |
GoogleApiClient : The GoogleApiClient to service the call. The client must be connected
before invoking this method. |
changeSet |
MetadataChangeSet : The set of changes that will be applied to the Metadata of the file associated
to this contents instance. Should only include the specific fields that should be updated.
Can be null if no metadata changes should be applied with this commit. |
Returns | |
---|---|
PendingResult<Status> |
A PendingResult which can be used to verify the success of the operation. |
Throws | |
---|---|
IllegalStateException |
If one of the following is true:
|
This method is deprecated.
Use discardContents(DriveContents)
instead.
Discards this contents and any changes that were performed. Calling this method will not save any changes performed through this object.
After this method returns, this instance will be closed and will no longer be usable.
Parameters | |
---|---|
apiClient |
GoogleApiClient : The GoogleApiClient to service the call. The client must be connected
before invoking this method. |
Gets the DriveId
for the file that owns these contents. Will be null
if this
instance corresponds to new contents (obtained through createContents()
}.
Returns | |
---|---|
DriveId |
Returns an InputStream
that allows you to read this file's contents. This method may
only be used with files opened with MODE_READ_ONLY
; to read/write from a file
opened with MODE_READ_WRITE
, use the file descriptor returned by getParcelFileDescriptor()
. This method may only be called once per DriveContents
instance.
Returns | |
---|---|
InputStream |
Gets the mode the contents are opened in.
Returns | |
---|---|
int |
Returns an OutputStream
that allows you to write new contents. This method may only be
used with files opened with MODE_WRITE_ONLY
; to read/write from a file opened
with MODE_READ_WRITE
, use the file descriptor returned by getParcelFileDescriptor()
. This method may only be called once per DriveContents
instance.
Returns | |
---|---|
OutputStream |
Returns a ParcelFileDescriptor
that points to the Drive file's contents. If this file
was opened with MODE_READ_ONLY
or MODE_READ_WRITE
, the file
referenced by the returned file descriptor will contain the most recent version of the file.
Otherwise, the returned file descriptor will point to an empty file.
Returns | |
---|---|
ParcelFileDescriptor |
This method is deprecated.
Use reopenContentsForWrite(DriveContents)
instead.
Closes this contents and returns a new contents opened in MODE_WRITE_ONLY
.
The returned DriveContents
are usable for conflict detection.
This method can only be called on MODE_READ_ONLY
contents. Calling it on
MODE_WRITE_ONLY
or MODE_READ_WRITE
contents, or on closed
contents throws an IllegalStateException
.
This method is useful for conflict detection, and often used in conjunction with commit(GoogleApiClient, MetadataChangeSet, ExecutionOptions)
, however it can also be used to
open contents in MODE_WRITE_ONLY
from an existing instance of MODE_READ_ONLY
contents.
After this method returns, this instance will be closed and will no longer be usable.
Parameters | |
---|---|
apiClient |
GoogleApiClient : The GoogleApiClient to service the call. |
Returns | |
---|---|
PendingResult<DriveApi.DriveContentsResult> |
A PendingResult which can be used to verify the success of the operation and
retrieve the MODE_WRITE_ONLY Contents when they are ready. |