Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Update RxDrive.java
Browse files Browse the repository at this point in the history
  • Loading branch information
mcelotti committed Aug 16, 2016
1 parent 622a927 commit c524138
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions rxdrive/src/main/java/com/francescocervone/rxdrive/RxDrive.java
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,37 @@ public Observable<DriveId> call() {
}
}).subscribeOn(Schedulers.io());
}

/**
* Updates a file on Drive
*
* @param driveFile drive file
* @param content the content to write
* @return an Observable with the DriveId
*/
public Observable<DriveFile> updateFile(final DriveFile driveFile, final ByteArrayInputStream content) {
return Observable.defer(new Func0<Observable<DriveFile>>() {
@Override
public Observable<DriveFile> call() {
DriveApi.DriveContentsResult driveContentsResult = driveFile
.open(getGoogleApiClient(), DriveFile.MODE_WRITE_ONLY, null)
.await();
DriveContents driveContents = driveContentsResult.getDriveContents();
try {
IOUtils.copy(content, driveContents.getOutputStream());
Status status = driveContents.commit(getGoogleApiClient(), null).await();
if (status.isSuccess()) {
return Observable.just(driveFile);
} else {
return Observable.error(new RxDriveException(status));
}
} catch (IOException e) {
e.printStackTrace();
return Observable.error(e);
}
}
});
}

/**
* Creates a new folder
Expand Down Expand Up @@ -550,6 +581,21 @@ public Observable<Boolean> call() {
}
}).subscribeOn(Schedulers.io());
}

/**
* Do sync
*
* @return nothing
*/
public Observable<Void> sync() {
return Observable.defer(new Func0<Observable<Void>>() {
@Override
public Observable<Void> call() {
Drive.DriveApi.requestSync(mClient).await();
return Observable.just(null);
}
}).subscribeOn(Schedulers.io());
}

/**
* Returns the Metadata of a DriveResource
Expand Down

0 comments on commit c524138

Please sign in to comment.