本文整理汇总了Java中com.google.gdata.data.media.MediaFileSource类的典型用法代码示例。如果您正苦于以下问题:Java MediaFileSource类的具体用法?Java MediaFileSource怎么用?Java MediaFileSource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MediaFileSource类属于com.google.gdata.data.media包,在下文中一共展示了MediaFileSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import com.google.gdata.data.media.MediaFileSource; //导入依赖的package包/类
@Override
public void execute() throws Exception {
MediaFileSource media = new MediaFileSource(new File(attachmentFile), attachmentMimeType);
Service service = createService();
Service.GDataRequest request = service.createRequest(GDataRequest.RequestType.INSERT,
new URL(itemMediaUrl), new ContentType(attachmentMimeType));
if (caption != null) {
request.setHeader("Slug", caption);
}
MediaSource.Output.writeTo(media, request.getRequestStream());
// Send the request (HTTP POST)
request.execute();
// Save the response
outputRawResponse(request);
}
示例2: createEntryFromArgs
import com.google.gdata.data.media.MediaFileSource; //导入依赖的package包/类
private GlossaryEntry createEntryFromArgs(String[] args)
throws IOException {
SimpleCommandLineParser parser = new SimpleCommandLineParser(args);
System.out.println("You asked to add a glossary...");
GlossaryEntry entry = new GlossaryEntry();
String title = parser.getValue("title");
System.out.println("...with title " + title);
entry.setTitle(new PlainTextConstruct(title));
String filename = parser.getValue("file");
System.out.println("...with contents from " + filename);
File file = new File(filename);
String mimeType = "text/csv";
MediaFileSource fileSource = new MediaFileSource(file, mimeType);
MediaContent content = new MediaContent();
content.setMediaSource(fileSource);
content.setMimeType(new ContentType(mimeType));
entry.setContent(content);
return entry;
}
示例3: createResumableUploadSession
import com.google.gdata.data.media.MediaFileSource; //导入依赖的package包/类
/**
* Creates a resumable upload session for a new media.
*
* @param createMediaUrl resumable put/post url.
* @param title media title for new upload or {@code null} for updating
* media part of existing media resource.
* @param file new media file to upload.
* @return resumable upload url to upload the media to.
* @throws IOException error communicating with the GData service.
* @throws ServiceException insert request failed due to system error.
*/
URL createResumableUploadSession(
URL createMediaUrl, String title, MediaFileSource file)
throws IOException, ServiceException {
String mimeType = file.getContentType();
GDataRequest request = createRequest(GDataRequest.RequestType.INSERT,
createMediaUrl, new ContentType(mimeType));
initResumableMediaRequest(request, file, title);
try {
startVersionScope();
request.execute();
return new URL(request.getResponseHeader("Location"));
} finally {
endVersionScope();
request.end();
}
}
示例4: uploadVideo
import com.google.gdata.data.media.MediaFileSource; //导入依赖的package包/类
/**
* Metóda uploadVideo slúži na odovzdanie multimediálneho video a súboru na server YouTube. Taktiež priradzuje k videu aj detaily o videosúbore a detaily o serveri s kadiaľ je odovzdávaný.
* @param file - video multimediálny súbor, zapísaný v štruktúre FileImpl
* @param user - používateľ (majiteľ), ktorý daný video multimediálnych súbor odovzdáva z potálu
* @param name - názov vytváranej trasy ku ktorej daný súbor patrí
* @param ID - poradove číslo multimediálneho súboru v danej trase
* @return Navratová hodnota je ID daného odovzdaneho multimedialneho súboru, pomocou ktoreho sa ten da vyvolať na serveri YouTube
* @throws YouTubeAgentException je vyhodená ppri problemoch s odovzdaním video multimediálneho súboru
*/
public String uploadVideo (FileImpl file, String user, String name, String ID) throws YouTubeAgentException{
try {
VideoEntry newEntry = new VideoEntry();
YouTubeMediaGroup mg = newEntry.getOrCreateMediaGroup();
mg.setTitle(new MediaTitle());
mg.getTitle().setPlainTextContent(user + "=" + name + "=" + ID);
mg.addCategory(new MediaCategory(YouTubeNamespace.CATEGORY_SCHEME, "Autos"));
mg.setKeywords(new MediaKeywords());
mg.getKeywords().addKeyword("GPSWebApp");
mg.setDescription(new MediaDescription());
mg.getDescription().setPlainTextContent("This video has been uploaded from GPSWebApp server, and it is property of GPSWebApp server.");
//mg.setPrivate(true);
//mg.addCategory(new MediaCategory(YouTubeNamespace.DEVELOPER_TAG_SCHEME, "mydevtag"));
//mg.addCategory(new MediaCategory(YouTubeNamespace.DEVELOPER_TAG_SCHEME, "anotherdevtag"));
MediaFileSource ms = new MediaFileSource(new File(file.getPath()), "video/quicktime");
newEntry.setMediaSource(ms);
String uploadUrl = "http://uploads.gdata.youtube.com/feeds/api/users/default/uploads";
//
XmlBlob xmlBlob = new XmlBlob();
xmlBlob.setBlob("<yt:accessControl action='list' permission='denied'/>");
newEntry.setXmlBlob(xmlBlob);
//
VideoEntry createdEntry = service.insert(new URL(uploadUrl), newEntry);
System.out.println("Video has been uploaded to YouTube: " + createdEntry.getMediaGroup().getPlayer().getUrl());
FileLogger.getInstance().createNewLog("Successfully uploaded video to YouTube with URL " + createdEntry.getMediaGroup().getPlayer().getUrl() + " .");
return createdEntry.getMediaGroup().getVideoId();
} catch (Exception ex) {
ex.printStackTrace();
System.out.println("ERROR: Cannot upload video to YouTube server!!!");
FileLogger.getInstance().createNewLog("ERROR: Cannot upload video to YouTube with ID !!!");
throw new YouTubeAgentException();
}
}
示例5: getMediaFileSource
import com.google.gdata.data.media.MediaFileSource; //导入依赖的package包/类
private MediaFileSource getMediaFileSource(String fileName) {
File file = new File(fileName);
MediaFileSource mediaFile = new MediaFileSource(file,
DocumentListEntry.MediaType.fromFileName(file.getName())
.getMimeType());
return mediaFile;
}
示例6: executeUpdate
import com.google.gdata.data.media.MediaFileSource; //导入依赖的package包/类
/**
* Execute 'update' command.
*/
private void executeUpdate(String[] args)
throws IOException, ServiceException, InterruptedException {
String docIdToUpdate = args[1];
String filePath = args[2];
// retrieve latest entry
DocumentListEntry currentEntry = docs.service.getEntry(
new URL(DEFAULT_DOCLIST_FEED_URL + "/" + docIdToUpdate),
DocumentListEntry.class);
MediaFileSource mediaFile = getMediaFileSource(filePath);
ResumableGDataFileUploader uploader =
new ResumableGDataFileUploader
.Builder(docs.service, mediaFile, currentEntry)
.title(mediaFile.getName())
.requestType(
ResumableGDataFileUploader.RequestType.UPDATE_MEDIA_ONLY)
.build();
uploader.start();
// wait for upload to complete
while (!uploader.isDone()) {
try {
Thread.sleep(100);
} catch (InterruptedException ie) {
output.println("Media update interrupted at: "
+ String.format("%3.0f", uploader.getProgress() * 100) + "%");
throw ie; // rethrow
}
}
DocumentListEntry updatedEntry =
uploader.getResponse(DocumentListEntry.class);
output.println("Finished update");
}
示例7: uploadAttachment
import com.google.gdata.data.media.MediaFileSource; //导入依赖的package包/类
/**
* Uploads an attachment to a parent page.
*
* @param file The file contents to upload
* @param parentLink Full self id of the parent entry to upload the attach to.
* @param title A title for the attachment.
* @param description A description for the attachment.
* @return The created attachment entry.
* @throws ServiceException
* @throws IOException
*/
public AttachmentEntry uploadAttachment(File file, String parentLink, String title,
String description) throws IOException, ServiceException {
String fileMimeType = mediaTypes.getContentType(file);
AttachmentEntry newAttachment = new AttachmentEntry();
newAttachment.setMediaSource(new MediaFileSource(file, fileMimeType));
newAttachment.setTitle(new PlainTextConstruct(title));
newAttachment.setSummary(new PlainTextConstruct(description));
newAttachment.addLink(SitesLink.Rel.PARENT, Link.Type.ATOM, parentLink);
return service.insert(new URL(getContentFeedUrl()), newAttachment);
}
示例8: updateAttachment
import com.google.gdata.data.media.MediaFileSource; //导入依赖的package包/类
/**
* Updates an existing attachment's metadata and content.
*
* @param entry Attachment entry to update.
* @param newFile The replacement file content.
* @param newTitle A new title for the attachment.
* @param newDescription A new description for the attachment.
* @return The created attachment.
* @throws ServiceException
* @throws IOException
*/
public AttachmentEntry updateAttachment(AttachmentEntry entry, File newFile,
String newTitle, String newDescription) throws IOException, ServiceException {
entry.setMediaSource(new MediaFileSource(newFile, mediaTypes.getContentType(newFile)));
if (newTitle != null) {
entry.setTitle(new PlainTextConstruct(newTitle));
}
if (newDescription != null) {
entry.setSummary(new PlainTextConstruct(newDescription));
}
return entry.updateMedia(true);
}
示例9: createEntryFromArgs
import com.google.gdata.data.media.MediaFileSource; //导入依赖的package包/类
private TranslationMemoryEntry createEntryFromArgs(String[] args)
throws IOException {
SimpleCommandLineParser parser = new SimpleCommandLineParser(args);
System.out.println("You asked to add translation memory...");
TranslationMemoryEntry entry = new TranslationMemoryEntry();
String title = parser.getValue("title");
System.out.println("...with title " + title);
entry.setTitle(new PlainTextConstruct(title));
if (parser.containsKey("file")) {
String filename = parser.getValue("file");
System.out.println("...with contents from " + filename);
File file = new File(filename);
String mimeType = "text/xml";
MediaFileSource fileSource = new MediaFileSource(file, mimeType);
MediaContent content = new MediaContent();
content.setMediaSource(fileSource);
content.setMimeType(new ContentType(mimeType));
entry.setContent(content);
}
if (parser.containsKey("private")) {
System.out.println("...with private access");
entry.setScope(new ScopeEntry(ScopeEntry.Value.PRIVATE));
} else {
System.out.println("...with public access");
entry.setScope(new ScopeEntry(ScopeEntry.Value.PUBLIC));
}
return entry;
}
示例10: setFile
import com.google.gdata.data.media.MediaFileSource; //导入依赖的package包/类
/**
* Associate a File with this entry with the specified mime type
*/
public void setFile(File file, String mimeType) {
MediaFileSource fileSource = new MediaFileSource(file, mimeType);
MediaContent content = new MediaContent();
content.setMediaSource(fileSource);
content.setMimeType(new ContentType(mimeType));
setContent(content);
}
示例11: initResumableMediaRequest
import com.google.gdata.data.media.MediaFileSource; //导入依赖的package包/类
/**
* Initialize a resumable media upload request.
*
* @param request {@link GDataRequest} to initialize.
* @param file media file that needs to be upload.
* @param title title of uploaded media or {@code null} if no title.
*/
private void initResumableMediaRequest(
GDataRequest request, MediaFileSource file, String title) {
initMediaRequest(request, title);
request.setHeader(
GDataProtocol.Header.X_UPLOAD_CONTENT_TYPE, file.getContentType());
request.setHeader(GDataProtocol.Header.X_UPLOAD_CONTENT_LENGTH,
new Long(file.getContentLength()).toString());
}
示例12: createResumableUpdateSession
import com.google.gdata.data.media.MediaFileSource; //导入依赖的package包/类
/**
* Creates a resumable upload session to update existing media.
*
* @param editMediaUrl resumable put/post url.
* @param entry media entry to update.
* @param file updated media file to upload.
* @param isMediaOnly whether to update media only or both media and metadata.
* {@code true} if media-only or {@code false} for both.
* @return resumable upload url to upload the media to.
* @throws IOException error communicating with the GData service.
* @throws ServiceException insert request failed due to system error.
*/
URL createResumableUpdateSession(
URL editMediaUrl, IEntry entry, MediaFileSource file, boolean isMediaOnly)
throws IOException, ServiceException {
GDataRequest request;
if (isMediaOnly) {
request = createRequest(GDataRequest.RequestType.UPDATE, editMediaUrl,
new ContentType(file.getContentType()));
} else {
request = createUpdateRequest(editMediaUrl);
}
initResumableMediaRequest(request, file, null);
if (entry.getEtag() != null) {
request.setEtag(entry.getEtag());
}
try {
startVersionScope();
if (!isMediaOnly) {
writeRequestData(request, entry);
}
request.execute();
return new URL(request.getResponseHeader("Location"));
} finally {
endVersionScope();
request.end();
}
}
示例13: createPhotoEntry
import com.google.gdata.data.media.MediaFileSource; //导入依赖的package包/类
public PhotoEntry createPhotoEntry (String title, String description, File fileImage) {
PhotoEntry myPhoto = new PhotoEntry();
myPhoto.setTitle(new PlainTextConstruct(title));
myPhoto.setDescription(new PlainTextConstruct(description));
myPhoto.setClient( QuizParserConstant.SYNC_CLIENT_NAME );
MediaFileSource myMedia = new MediaFileSource(fileImage, "image/jpeg");
myPhoto.setMediaSource(myMedia);
return myPhoto;
}
示例14: writeEndWiki
import com.google.gdata.data.media.MediaFileSource; //导入依赖的package包/类
@Override
public void writeEndWiki() throws IOException {
progressListener.setStatus("Processing Attachments.");
progressListener.setProgress(.5); // Arbitrarily chosen.
allImages.removeAll(attachments.keySet());
for (String image : allImages) {
attachments.put(image, Lists.<BasePageEntry<?>>newLinkedList());
}
for (Map.Entry<String, List<BasePageEntry<?>>>
entry : attachments.entrySet()) {
String name = entry.getKey();
progressListener.setStatus("Attachment: " + name);
AttachmentEntry attachment = new AttachmentEntry();
File file = new File(imagesDirectory, name);
String type = URLConnection.guessContentTypeFromName(file.getName());
MediaSource mediaSource = new MediaFileSource(file, type);
attachment.setMediaSource(mediaSource);
attachment.setTitle(TextConstruct.plainText(name));
pageImporter.importAttachment(
attachment, entry.getValue(),
feedUrl, sitesService);
}
progressListener.setStatus("Processed End of Wiki.");
progressListener.setProgress(.9); // Arbitrarily chosen.
}
示例15: execute
import com.google.gdata.data.media.MediaFileSource; //导入依赖的package包/类
public void execute(GttService service, String[] args)
throws IOException, ServiceException {
SimpleCommandLineParser parser = new SimpleCommandLineParser(args);
String id = parser.getValue("id");
URL feedUrl = FeedUris.getTranslationMemoryFeedUrl(id);
TranslationMemoryEntry requestEntry = service.getEntry(feedUrl,
TranslationMemoryEntry.class);
System.out.println("You want to update translation memory with id:"
+ id + " ...");
if (parser.containsKey("title")) {
String title = parser.getValue("title");
System.out.println("...by changing title to " + title);
requestEntry.setTitle(new PlainTextConstruct(title));
}
if (parser.containsKey("file")) {
String filename = parser.getValue("file");
System.out.println("...by appending contents from file " + filename);
File file = new File(filename);
String mimeType = "text/xml";
MediaFileSource fileSource = new MediaFileSource(file, mimeType);
MediaContent content = new MediaContent();
content.setMediaSource(fileSource);
content.setMimeType(new ContentType(mimeType));
requestEntry.setContent(content);
}
System.out.print("Updating translation memory....");
System.out.flush();
TranslationMemoryEntry resultEntry = null;
if (requestEntry.getContent() == null) {
resultEntry = service.update(feedUrl, requestEntry);
} else {
resultEntry = service.updateMedia(feedUrl, requestEntry);
}
printResults(resultEntry);
}