本文整理汇总了Java中com.google.android.gms.drive.Contents.getOutputStream方法的典型用法代码示例。如果您正苦于以下问题:Java Contents.getOutputStream方法的具体用法?Java Contents.getOutputStream怎么用?Java Contents.getOutputStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.android.gms.drive.Contents
的用法示例。
在下文中一共展示了Contents.getOutputStream方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createFile
import com.google.android.gms.drive.Contents; //导入方法依赖的package包/类
boolean createFile(InputStream input, String filename, DriveFolder target, String mimetype) {
// New content
DriveApi.ContentsResult contentsResult =
Drive.DriveApi.newContents(mClient).await(3, TimeUnit.SECONDS);
if (!contentsResult.getStatus().isSuccess()) {
// We failed, stop the task and return.
return false;
}
// Write content
Contents originalContents = contentsResult.getContents();
OutputStream os = originalContents.getOutputStream();
try {
int read;
byte[] bytes = new byte[1024];
while ((read = input.read(bytes)) != -1) {
os.write(bytes, 0, read);
}
} catch (IOException e) {
e.printStackTrace();
return false;
}
// Create the metadata
MetadataChangeSet originalMetadata = new MetadataChangeSet.Builder()
.setTitle(filename)
.setMimeType(mimetype).build();
// Create the file
DriveFolder.DriveFileResult fileResult = target.createFile(
mClient, originalMetadata, originalContents).await(3, TimeUnit.SECONDS);
return fileResult.getStatus().isSuccess();
}
示例2: doInBackgroundConnected
import com.google.android.gms.drive.Contents; //导入方法依赖的package包/类
@Override
protected Metadata doInBackgroundConnected(Void... arg0) {
// First we start by creating a new contents, and blocking on the
// result by calling await().
ContentsResult contentsResult =
Drive.DriveApi.newContents(getGoogleApiClient()).await();
if (!contentsResult.getStatus().isSuccess()) {
// We failed, stop the task and return.
return null;
}
// Read the contents and open its output stream for writing, then
// write a short message.
Contents originalContents = contentsResult.getContents();
OutputStream os = originalContents.getOutputStream();
try {
os.write("Hello world!\n".getBytes());
} catch (IOException e) {
e.printStackTrace();
return null;
}
// Create the metadata for the new file including title and MIME
// type.
MetadataChangeSet originalMetadata = new MetadataChangeSet.Builder()
.setTitle("AsyncTaskFile.txt")
.setMimeType("text/plain").build();
// Create the file in the root folder, again calling await() to
// block until the request finishes.
DriveFolder rootFolder = Drive.DriveApi.getRootFolder(getGoogleApiClient());
DriveFileResult fileResult = rootFolder.createFile(
getGoogleApiClient(), originalMetadata, originalContents).await();
if (!fileResult.getStatus().isSuccess()) {
// We failed, stop the task and return.
return null;
}
// Finally, fetch the metadata for the newly created file, again
// calling await to block until the request finishes.
MetadataResult metadataResult = fileResult.getDriveFile()
.getMetadata(getGoogleApiClient())
.await();
if (!metadataResult.getStatus().isSuccess()) {
// We failed, stop the task and return.
return null;
}
// We succeeded, return the newly created metadata.
return metadataResult.getMetadata();
}