本文整理汇总了Java中com.google.android.gms.drive.DriveContents.discard方法的典型用法代码示例。如果您正苦于以下问题:Java DriveContents.discard方法的具体用法?Java DriveContents.discard怎么用?Java DriveContents.discard使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.android.gms.drive.DriveContents
的用法示例。
在下文中一共展示了DriveContents.discard方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getContentsFromDrive
import com.google.android.gms.drive.DriveContents; //导入方法依赖的package包/类
public String getContentsFromDrive(DriveId id) throws IOException {
DriveFile theFile = Drive.DriveApi.getFile(mGoogleApiClient, id);
DriveApi.DriveContentsResult result =
theFile.open(mGoogleApiClient, DriveFile.MODE_READ_ONLY, null).await();
DriveContents driveContents = result.getDriveContents();
try {
if (driveContents != null) {
return IOUtils.readAsString(driveContents.getInputStream());
}
} finally {
if (driveContents != null) {
driveContents.discard(mGoogleApiClient);
}
}
return null;
}
示例2: doInBackgroundConnected
import com.google.android.gms.drive.DriveContents; //导入方法依赖的package包/类
@Override
protected String doInBackgroundConnected(DriveId... params) {
String contents = null;
DriveFile file = params[0].asDriveFile();
DriveApi.DriveContentsResult driveContentsResult =
file.open(getGoogleApiClient(), DriveFile.MODE_READ_ONLY, null).await();
if (!driveContentsResult.getStatus().isSuccess()) {
return null;
}
DriveContents driveContents = driveContentsResult.getDriveContents();
BufferedReader reader = new BufferedReader(
new InputStreamReader(driveContents.getInputStream()));
StringBuilder builder = new StringBuilder();
String line;
try {
while ((line = reader.readLine()) != null) {
builder.append(line);
}
contents = builder.toString();
} catch (IOException e) {
Log.e(TAG, "IOException while reading from the stream", e);
}
driveContents.discard(getGoogleApiClient());
return contents;
}
示例3: doInBackgroundConnected
import com.google.android.gms.drive.DriveContents; //导入方法依赖的package包/类
@Override
protected String doInBackgroundConnected(DriveId... params) {
String contents = null;
DriveFile file = Drive.DriveApi.getFile(getGoogleApiClient(), params[0]);
DriveContentsResult driveContentsResult =
file.open(getGoogleApiClient(), DriveFile.MODE_READ_ONLY, null).await();
if (!driveContentsResult.getStatus().isSuccess()) {
return null;
}
DriveContents driveContents = driveContentsResult.getDriveContents();
BufferedReader reader = new BufferedReader(
new InputStreamReader(driveContents.getInputStream()));
StringBuilder builder = new StringBuilder();
String line;
try {
while ((line = reader.readLine()) != null) {
builder.append(line);
}
contents = builder.toString();
} catch (IOException e) {
}
driveContents.discard(getGoogleApiClient());
return contents;
}
示例4: getCouponsJson
import com.google.android.gms.drive.DriveContents; //导入方法依赖的package包/类
/**
* Returns the string representation of the coupons json that was stored
* in {@link DriveFile} passed to this method.
*/
private String getCouponsJson(DriveFile driveFile) {
DebugLog.logMethod();
// Open file in read mode
DriveApi.DriveContentsResult driveContentsResult = driveFile
.open(getGoogleApiClient(), DriveFile.MODE_READ_ONLY, null)
.await();
DebugLog.logMessage("Status code: " + driveContentsResult.getStatus().getStatusCode()
+ "\nStatus message: " + driveContentsResult.getStatus().getStatusMessage());
if (!driveContentsResult.getStatus().isSuccess()) {
DebugLog.logMessage("DriveContentsResult failure");
return null;
}
// Read the contents of the file line by line and generate the json.
DriveContents driveContents = driveContentsResult.getDriveContents();
BufferedReader reader = new BufferedReader(new InputStreamReader(driveContents.getInputStream()));
StringBuilder builder = new StringBuilder();
String line;
try {
while ((line = reader.readLine()) != null) {
builder.append(line);
}
} catch (IOException e) {
e.printStackTrace();
DebugLog.logMessage(e.getMessage());
}
driveContents.discard(getGoogleApiClient());
DebugLog.logMessage("Coupons json: " + builder.toString());
return builder.toString();
}
示例5: doInBackgroundConnected
import com.google.android.gms.drive.DriveContents; //导入方法依赖的package包/类
@Override
protected String doInBackgroundConnected(DriveId... params) {
String state = null;
DriveFile file = params[0].asDriveFile();
DriveApi.DriveContentsResult driveContentsResult =
file.open(getGoogleApiClient(), DriveFile.MODE_READ_ONLY, null).await();
if (!driveContentsResult.getStatus().isSuccess()) {
return null;
}
DriveContents driveContents = driveContentsResult.getDriveContents();
BufferedReader reader = new BufferedReader(
new InputStreamReader(driveContents.getInputStream()));
StringBuilder builder = new StringBuilder();
String line;
try {
while ((line = reader.readLine()) != null) {
builder.append(line);
builder.append("\n");
}
state = builder.toString();
reader.close();
} catch (IOException e) {
Log.e(TAG, "IOException while reading from the stream", e);
}
driveContents.discard(getGoogleApiClient());
String validState=UIUtils.stripMagicSequence(state);
return validState;
}
示例6: handleIntent
import com.google.android.gms.drive.DriveContents; //导入方法依赖的package包/类
@Override
protected boolean handleIntent() {
DebugLog.logMethod();
try {
/*
First retrieve the json representation of all coupons in
the app. If this data is null, return false.
*/
String couponsJson = getCouponsJson();
if (couponsJson == null) {
showError("No coupon data");
return false;
}
// Get the drive app specific drive file to write data into.
DriveFile driveFile = getDriveFile();
boolean isNewFile = driveFile == null;
// Get the driveContents to write data to.
DriveContents driveContents = driveFile == null
? createDriveFileContents()
: openDriveContentsFileInEditMode(driveFile);
if (driveContents == null) {
showError("Failed to create drive file");
return false;
}
// Write the couponsJson to the app specific file in google drive
if (!writeToDriveFile(driveContents, couponsJson, isNewFile)) {
driveContents.discard(getGoogleApiClient());
showError("Error occurred while exporting to Google drive");
return false;
}
return true;
} catch (Exception e) {
e.printStackTrace();
DebugLog.logMessage(e.getMessage());
showError("Error: " + e.getMessage());
return false;
}
}
示例7: uploadFile
import com.google.android.gms.drive.DriveContents; //导入方法依赖的package包/类
@Override
public int uploadFile(File tempFile) {
DriveFile driveFile;
MetadataResult metadataResult;
Metadata metadata;
DriveContents driveContents = null;
DriveContentsResult driveContentsResult;
OutputStream outputStream;
ExecutionOptions executionOptions;
int complentionStatus;
Log.i(TAG, "start upload of DB file temp:" + tempFile.getName());
try {
driveFile = mDriveId.asDriveFile();
// Get metadata
metadataResult = driveFile.getMetadata(mGoogleApiClient).await();
checkStatus(metadataResult);
metadata = metadataResult.getMetadata();
Log.i(TAG, "try to upload of DB file:" + metadata.getOriginalFilename());
if (!metadata.isPinned()) {
pinFile(driveFile);
}
// Writing file
driveContentsResult = mDriveContent.reopenForWrite(mGoogleApiClient).await();
checkStatus(driveContentsResult);
driveContents = driveContentsResult.getDriveContents();
outputStream = driveContents.getOutputStream();
// Copio il file
FileUtils.copyFile(tempFile, outputStream);
Log.i(TAG, "try to commit file copy done");
// Commit del file
executionOptions = new ExecutionOptions.Builder()
.setNotifyOnCompletion(true)
.setConflictStrategy(ExecutionOptions.CONFLICT_STRATEGY_KEEP_REMOTE)
.build();
driveContents.commit(mGoogleApiClient, null, executionOptions);
Log.i(TAG, "file committed - wait for complention");
// Wait for complention
complentionStatus = mGDriveCompletionRecevier.waitCompletion();
Log.i(TAG, "received complention status:" + complentionStatus);
if (complentionStatus == CompletionEvent.STATUS_CONFLICT) {
return UPLOAD_CONFLICT;
} else if (complentionStatus == CompletionEvent.STATUS_FAILURE) {
throw new SyncException(SyncStatus.Code.ERROR_UPLOAD_CLOUD, "Error writing file to GDrive (FAILURE of commit)");
}
return UPLOAD_OK;
} catch (IOException e) {
if (driveContents != null) {
driveContents.discard(mGoogleApiClient);
}
throw new SyncException(SyncStatus.Code.ERROR_UPLOAD_CLOUD, "Error writing file to GDrive message:" + e.getMessage());
}
}
示例8: discardChangesAndClose
import com.google.android.gms.drive.DriveContents; //导入方法依赖的package包/类
/**
* Discards the changes to the file contents and close.
*
* @param driveContent the file content changes to discard
*/
public void discardChangesAndClose(DriveContents driveContent) {
driveContent.discard(getGoogleApiClient());
}