本文整理匯總了Java中com.google.api.services.drive.model.File.getParents方法的典型用法代碼示例。如果您正苦於以下問題:Java File.getParents方法的具體用法?Java File.getParents怎麽用?Java File.getParents使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.api.services.drive.model.File
的用法示例。
在下文中一共展示了File.getParents方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: isInMyTracks
import com.google.api.services.drive.model.File; //導入方法依賴的package包/類
/**
* Returns true if a drive file is a KML or KMZ file in the My Tracks folder.
*
* @param driveFile the drive file
* @param folderId the My Tracks folder id
*/
public static boolean isInMyTracks(File driveFile, String folderId) {
if (driveFile == null) {
return false;
}
String mimeType = driveFile.getMimeType();
if (!SyncUtils.KML_MIME_TYPE.equals(mimeType) && !SyncUtils.KMZ_MIME_TYPE.equals(mimeType)) {
return false;
}
if (driveFile.getSharedWithMeDate() != null) {
return false;
}
for (ParentReference parentReference : driveFile.getParents()) {
String id = parentReference.getId();
if (id != null && id.equals(folderId)) {
return true;
}
}
return false;
}
示例2: move
import com.google.api.services.drive.model.File; //導入方法依賴的package包/類
@Override
public Path move(final Path file, final Path renamed, final TransferStatus status, final Delete.Callback callback, final ConnectionCallback connectionCallback) throws BackgroundException {
try {
if(status.isExists()) {
delete.delete(Collections.singletonList(renamed), connectionCallback, callback);
}
final String fileid = new DriveFileidProvider(session).getFileid(file, new DisabledListProgressListener());
if(!StringUtils.equals(file.getName(), renamed.getName())) {
// Rename title
final File properties = new File();
properties.setName(renamed.getName());
properties.setMimeType(status.getMime());
session.getClient().files().update(fileid, properties).
setSupportsTeamDrives(PreferencesFactory.get().getBoolean("googledrive.teamdrive.enable")).execute();
}
// Retrieve the existing parents to remove
final StringBuilder previousParents = new StringBuilder();
final File reference = session.getClient().files().get(fileid)
.setFields("parents")
.setSupportsTeamDrives(PreferencesFactory.get().getBoolean("googledrive.teamdrive.enable"))
.execute();
for(String parent : reference.getParents()) {
previousParents.append(parent);
previousParents.append(',');
}
// Move the file to the new folder
session.getClient().files().update(fileid, null)
.setAddParents(new DriveFileidProvider(session).getFileid(renamed.getParent(), new DisabledListProgressListener()))
.setRemoveParents(previousParents.toString())
.setFields("id, parents")
.setSupportsTeamDrives(PreferencesFactory.get().getBoolean("googledrive.teamdrive.enable"))
.execute();
return new Path(renamed.getParent(), renamed.getName(), renamed.getType(),
new PathAttributes(renamed.attributes()).withVersionId(fileid));
}
catch(IOException e) {
throw new DriveExceptionMappingService().map("Cannot rename {0}", e, file);
}
}