本文整理汇总了Java中com.google.api.client.googleapis.media.MediaHttpUploader类的典型用法代码示例。如果您正苦于以下问题:Java MediaHttpUploader类的具体用法?Java MediaHttpUploader怎么用?Java MediaHttpUploader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MediaHttpUploader类属于com.google.api.client.googleapis.media包,在下文中一共展示了MediaHttpUploader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: progressChanged
import com.google.api.client.googleapis.media.MediaHttpUploader; //导入依赖的package包/类
@Override
public void progressChanged(MediaHttpUploader mediaHttpUploader) throws IOException {
switch (mediaHttpUploader.getUploadState()) {
case INITIATION_STARTED:
System.out.println("Initializing.");
break;
case INITIATION_COMPLETE:
System.out.println("Initiation Completed.");
break;
case MEDIA_IN_PROGRESS:
System.out.println("Upload in progress " +
NumberFormat.getPercentInstance().format(mediaHttpUploader.getProgress()) +
" uploaded!");
break;
case MEDIA_COMPLETE:
System.out.println("Upload Completed!");
break;
}
}
示例2: progressChanged
import com.google.api.client.googleapis.media.MediaHttpUploader; //导入依赖的package包/类
@Override
public void progressChanged(MediaHttpUploader uploader) throws IOException {
if (uploader == null) return;
switch (uploader.getUploadState()) {
case INITIATION_STARTED:
//System.out.println("Initiation has started!");
break;
case INITIATION_COMPLETE:
//System.out.println("Initiation is complete!");
break;
case MEDIA_IN_PROGRESS:
int percent = (int) (uploader.getProgress() * 100);
mBuilder.setProgress(100, percent, false);
mNotifyMgr.notify(NOTIFICATION_ID, mBuilder.build());
break;
case MEDIA_COMPLETE:
//System.out.println("Upload is complete!");
}
}
示例3: uploadFile
import com.google.api.client.googleapis.media.MediaHttpUploader; //导入依赖的package包/类
public static com.google.api.services.drive.model.File uploadFile(
java.io.File file, Credential credential, String parent)
throws IOException {
com.google.api.services.drive.model.File fileMetadata = new com.google.api.services.drive.model.File();
fileMetadata.setParents(Arrays.asList(new ParentReference()
.setId(parent)));
fileMetadata.setTitle(file.getName());
InputStreamContent mediaContent = new InputStreamContent(
"image/png", new BufferedInputStream(new FileInputStream(
file)));
mediaContent.setLength(file.length());
Drive.Files.Insert insert = drive.files().insert(fileMetadata,
mediaContent);
MediaHttpUploader uploader = insert.getMediaHttpUploader();
uploader.setDirectUploadEnabled(true);
return insert.execute();
}
示例4: progressChanged
import com.google.api.client.googleapis.media.MediaHttpUploader; //导入依赖的package包/类
public void progressChanged(MediaHttpUploader uploader) throws IOException {
switch (uploader.getUploadState()) {
case INITIATION_STARTED:
LOG.debug("Initiation Started");
break;
case INITIATION_COMPLETE:
LOG.debug("Initiation Completed");
break;
case MEDIA_IN_PROGRESS:
LOG.debug("Upload in progress");
LOG.debug("Upload percentage: ${uploader.getProgress()}");
break;
case MEDIA_COMPLETE:
LOG.debug("Upload Completed!");
break;
case NOT_STARTED:
LOG.debug("Upload Not Started!");
break;
}
}
示例5: createFile
import com.google.api.client.googleapis.media.MediaHttpUploader; //导入依赖的package包/类
@Override
public File createFile(String sParentID, String sName, java.io.File sFile, String sMimeType, Map<String, String> sProperties) throws IOException {
File aResult = null;
if (drive != null) {
File fileMetadata = new File();
fileMetadata.setTitle(sName);
ParentReference aParentReference = new ParentReference();
aParentReference.setId(sParentID);
fileMetadata.setParents(Arrays.asList(aParentReference));
FileContent mediaContent = new FileContent(sMimeType, sFile);
Drive.Files.Insert insert = drive.files().insert(fileMetadata, mediaContent);
MediaHttpUploader uploader = insert.getMediaHttpUploader();
uploader.setDirectUploadEnabled(false);
aResult = insert.execute();
setProperties(aResult.getId(), sProperties);
}
return aResult;
}
示例6: progressChanged
import com.google.api.client.googleapis.media.MediaHttpUploader; //导入依赖的package包/类
@Override
public void progressChanged(MediaHttpUploader uploader) {
switch (uploader.getUploadState()) {
case INITIATION_STARTED:
stopwatch.start();
log.info("Initiation has started!");
break;
case INITIATION_COMPLETE:
log.info("Initiation is complete!");
break;
case MEDIA_IN_PROGRESS:
log.info("Uploaded {} bytes of {}...", uploader.getNumBytesUploaded());
break;
case MEDIA_COMPLETE:
stopwatch.stop();
log.info(String.format("Upload is complete! (%s)", stopwatch));
break;
case NOT_STARTED:
break;
}
}
示例7: prepareUploader
import com.google.api.client.googleapis.media.MediaHttpUploader; //导入依赖的package包/类
private void prepareUploader(MediaHttpUploader uploader, long length)
{
int chunkSize = MediaHttpUploader.MINIMUM_CHUNK_SIZE * CHUNK_COUNT;
int chunkCount = (int) Math.ceil(length / (double) chunkSize);
if (showProgress && chunkCount > 1)
{
uploader.setDirectUploadEnabled(false);
uploader.setChunkSize(chunkSize);
uploader.setProgressListener(new RemoteGoogleDriveProgress(this, length));
}
else
{
uploader.setDirectUploadEnabled(true);
}
}
示例8: uploadFile
import com.google.api.client.googleapis.media.MediaHttpUploader; //导入依赖的package包/类
public File uploadFile(String name, String mimeType, java.io.File mediaFile, boolean onWifi)
throws IOException, JSONException {
// File Metadata
File fileMetadata = new File();
fileMetadata.setTitle(name);
fileMetadata.setMimeType(mimeType);
// Set the parent folder.
ParentReference uploadDir = new ParentReference();
uploadDir.setId(findUploadDirectory().getId());
fileMetadata.setParents(Arrays.asList(uploadDir));
InputStreamContent mediaContent = new InputStreamContent(mimeType, new BufferedInputStream(
new FileInputStream(mediaFile)));
mediaContent.setLength(mediaFile.length());
Drive.Files.Insert insert = drive.files().insert(fileMetadata, mediaContent);
insert.getMediaHttpUploader().setProgressListener(new ProgressListener(mediaFile));
insert.getMediaHttpUploader().setBackOffPolicyEnabled(true);
int chunkSize = onWifi ? MediaHttpUploader.MINIMUM_CHUNK_SIZE * 2
: MediaHttpUploader.MINIMUM_CHUNK_SIZE;
insert.getMediaHttpUploader().setChunkSize(chunkSize);
return insert.execute();
}
示例9: convertToSpreedSheet
import com.google.api.client.googleapis.media.MediaHttpUploader; //导入依赖的package包/类
public static boolean convertToSpreedSheet(Drive drive,
String path) {
com.google.api.services.drive.model.File fileMetaData = new com.google.api.services.drive.model.File();
java.io.File file = new java.io.File(path);
MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap();
fileMetaData.setName(file.getName());
String googleSheetMimeType = "application/vnd.google-apps.spreadsheet";
fileMetaData.setMimeType(googleSheetMimeType);
FileContent mediaContent = new FileContent(mimeTypesMap.getContentType(file), file);
com.google.api.services.drive.model.File f = null;
Drive.Files.Create create = null;
try {
System.out.println("Uploading file " + file.getName());
create = drive.files().create(fileMetaData, mediaContent)
.setFields("id, parents, mimeType, webViewLink");
create.getMediaHttpUploader().setProgressListener(new FileUpdateProgressListener());
// Using default chunk size of 10MB.
create.getMediaHttpUploader().setChunkSize(MediaHttpUploader.DEFAULT_CHUNK_SIZE);
f = create.execute();
} catch (IOException e) {
e.printStackTrace();
return false;
}
System.out.println("File ID: " + f.getId() + " Parent: " + f.getParents().toString()
+ " MimeType: " + f.getMimeType() + " link: " + f.getWebViewLink());
return true;
}
示例10: createFile
import com.google.api.client.googleapis.media.MediaHttpUploader; //导入依赖的package包/类
public File createFile(String parentId, String name, String mimeType, byte[] content, IProgressMonitor monitor) throws IOException {
File fileMetadata = new File();
fileMetadata.setTitle(name);
fileMetadata.setParents(Arrays.asList(new ParentReference().setId(parentId)));
ByteArrayContent mediaContent = new ByteArrayContent(mimeType, content);
Drive.Files.Insert insert = drive.files().insert(fileMetadata, mediaContent);
MediaHttpUploader uploader = insert.getMediaHttpUploader();
uploader.setDirectUploadEnabled(true);
FileUploadProgressListener uploadProgressListener = new FileUploadProgressListener(monitor);
uploader.setProgressListener(uploadProgressListener);
uploadProgressListener.begin();
try {
fileMetadata = insert.execute();
return fileMetadata;
} finally {
uploadProgressListener.done();
}
}
示例11: progressChanged
import com.google.api.client.googleapis.media.MediaHttpUploader; //导入依赖的package包/类
@Override
public void progressChanged(MediaHttpUploader uploader) throws IOException {
switch (uploader.getUploadState()) {
case NOT_STARTED:
break;
case INITIATION_STARTED:
worked = 0;
monitor.subTask("Upload Initiation has started");
break;
case INITIATION_COMPLETE:
monitor.subTask("Upload Initiation is complete");
break;
case MEDIA_IN_PROGRESS:
monitor.subTask("Upload in progress");
int progress = (int) (uploader.getProgress() * 100);
monitor.worked(progress - worked);
worked += progress - worked;
break;
case MEDIA_COMPLETE:
monitor.subTask("Upload completed");
monitor.done();
break;
default:
break;
}
}
示例12: notifyProgress
import com.google.api.client.googleapis.media.MediaHttpUploader; //导入依赖的package包/类
private void notifyProgress(YouTubeUploader.UploadProgress uploadProgress) {
Context context = application.getApplicationContext();
NotificationCompat.Builder builder = baseBuilder(context, message)
.setContentText(context.getString(R.string.sending_message))
.setOngoing(true);
// There are basically three states:
// 1. uploader == null: indeterminate progress, no info.
// 2. uploader != null AND uploader.getUploadState() in (INITIATION_STARTED, INITIATION_COMPLETE):
// indeterminate progress, no info.
// 3. progress, info.
double progress = 0;
String contentInfo = null;
boolean indeterminate = true;
MediaHttpUploader uploader = uploadProgress.getMediaHttpUploader();
if (uploader != null && (
uploader.getUploadState() == MediaHttpUploader.UploadState.MEDIA_COMPLETE
|| uploader.getUploadState() == MediaHttpUploader.UploadState.MEDIA_IN_PROGRESS)) {
try {
progress = uploader.getProgress();
} catch (IOException e) {
// Do nothing.
}
// TODO Use localized percentage string (I guess NumberFormat does it)
contentInfo = String.format("%.2f%%", progress * 100);
indeterminate = false;
}
// XXX 1000 to make it smoother than 100.
final int max = 1000;
builder.setProgress(max, (int) (progress * max), indeterminate);
builder.setContentInfo(contentInfo);
notify(context, builder.build());
}
示例13: handleUploadProgress
import com.google.api.client.googleapis.media.MediaHttpUploader; //导入依赖的package包/类
private void handleUploadProgress(YouTubeUploader.UploadProgress progress) {
// TODO Animate the progress bar in and out?
if (progress.getInsertedVideo() != null) {
progressBar.setVisibility(View.GONE);
} else {
double uploadProgress = 0;
boolean indeterminate = true;
MediaHttpUploader uploader = progress.getMediaHttpUploader();
if (uploader != null && (
uploader.getUploadState() == MediaHttpUploader.UploadState.MEDIA_IN_PROGRESS
|| uploader.getUploadState() == MediaHttpUploader.UploadState.MEDIA_COMPLETE)) {
try {
uploadProgress = uploader.getProgress();
indeterminate = false;
} catch (IOException e) {
// Do nothing.
}
}
// XXX 1000 to make it smoother than 100.
final int max = 1000;
progressBar.setMax(max);
progressBar.setProgress((int) (uploadProgress * max));
progressBar.setIndeterminate(indeterminate);
progressBar.setVisibility(View.VISIBLE);
}
}
示例14: doInBackground
import com.google.api.client.googleapis.media.MediaHttpUploader; //导入依赖的package包/类
@Override
protected Exception doInBackground(String... photos) {
try {
// Get output Directory
// Create the PDF and set some metadata
Document document = new Document(PageSize.A4, DOCUMENT_MARGIN, DOCUMENT_MARGIN, DOCUMENT_MARGIN, DOCUMENT_MARGIN);
Resources resources = mContext.getResources();
document.addTitle(mFilename);
document.addAuthor(resources.getString(R.string.app_name));
document.addSubject(resources.getString(R.string.file_subject));
// Open the file that we will write the pdf to.
java.io.File fileContent = new java.io.File(ImageUtils.getAlbumStorageDir(MainActivity.ALBUM_NAME) + mFilename);
OutputStream outputStream = new FileOutputStream(fileContent);
PdfWriter.getInstance(document, outputStream);
document.open();
// Get the document's size
Rectangle pageSize = document.getPageSize();
float pageWidth = pageSize.getWidth() - (document.leftMargin() + document.rightMargin());
float pageHeight = pageSize.getHeight();
//Loop through images and add them to the document
for (String path : photos) {
Image image = Image.getInstance(path);
image.scaleToFit(pageWidth, pageHeight);
document.add(image);
document.newPage();
}
// Cleanup
document.close();
outputStream.close();
// Upload time!
FileContent mediaContent = new FileContent("application/pdf", fileContent);
File body = new File();
if (mFolder != null)
body.setParents(Arrays.asList(new ParentReference().setId(mFolder.getId())));
body.setTitle(mFilename);
body.setDescription(resources.getString(R.string.file_subject));
body.setMimeType("application/pdf");
Drive.Files.Insert insert = mService.files().insert(body, mediaContent);
MediaHttpUploader uploader = insert.getMediaHttpUploader();
uploader.setDirectUploadEnabled(false);
uploader.setChunkSize(MediaHttpUploader.MINIMUM_CHUNK_SIZE);
uploader.setProgressListener(new FileProgressListener());
File file = insert.execute();
Log.d("C2P", "File Id: " + file.getId());
/* Database Code */
DateFormat format = new SimpleDateFormat("MM/dd/yyyy");
Date date = new Date();
//file.getFileSize().toString()
String parentFolder = mFolder != null ? mFolder.getId() : "root";
Long size = file.getFileSize();
String fileSizeString = humanReadableByteCount(size);
Upload upload = new Upload(-1, mFilename, mFolderPath, fileSizeString, parentFolder, format.format(date), mService.about().get().execute().getUser().getEmailAddress());
UploadDataAdapter mUploadDataAdapter = new UploadDataAdapter(mContext);
mUploadDataAdapter.open();
mUploadDataAdapter.addUpload(upload);
mUploadDataAdapter.close();
} catch (Exception e) {
Log.d("C2P", "ERROR", e);
return e;
}
return null;
}
示例15: performUploadWithRetry
import com.google.api.client.googleapis.media.MediaHttpUploader; //导入依赖的package包/类
/**
* We need our own storage retry logic because we must recreate the
* input stream for the media uploader.
*/
private void performUploadWithRetry(final Executor executor,
final Storage service, final Bucket bucket, final StorageObject object,
final FilePath include)
throws ExecutorException, IOException, InterruptedException {
Operation a = new Operation() {
public void act()
throws IOException, InterruptedException, ExecutorException {
// Create the insertion operation with the decorated object and
// an input stream of the file contents.
Storage.Objects.Insert insertion =
service.objects().insert(bucket.getName(), object,
new InputStreamContent(
object.getContentType(), include.read()));
// Make the operation non-resumable because we have seen a dramatic
// (e.g. 1000x) speedup from this.
MediaHttpUploader mediaUploader = insertion.getMediaHttpUploader();
if (mediaUploader != null) {
mediaUploader.setDirectUploadEnabled(true);
}
executor.execute(insertion);
}
};
RetryStorageOperation
.performRequestWithRetry(executor, a, module.getInsertRetryCount());
}