本文整理了Java中com.google.api.services.drive.model.File.setName()
方法的一些代码示例,展示了File.setName()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。File.setName()
方法的具体详情如下:
包路径:com.google.api.services.drive.model.File
类名称:File
方法名:setName
[英]The name of the file. This is not necessarily unique within a folder. Note that for immutable items such as the top level folders of Team Drives, My Drive root folder, and Application Data folder the name is constant.
[中]文件名。这在文件夹中不一定是唯一的。请注意,对于不可变项,例如团队驱动器的顶级文件夹、我的驱动器根文件夹和应用程序数据文件夹,名称是常量。
代码示例来源:origin: google/data-transfer-project
private String importSingleFolder(
UUID jobId,
Drive driveInterface,
String folderName,
String folderId,
String parentId) throws IOException {
File newFolder = new File()
.setName(folderName)
.setMimeType(DriveExporter.FOLDER_MIME_TYPE);
if (!Strings.isNullOrEmpty(parentId)) {
newFolder.setParents(ImmutableList.of(parentId));
}
File resultFolder = driveInterface.files().create(newFolder).execute();
DriveFolderMapping mapping = new DriveFolderMapping(folderId, resultFolder.getId());
jobStore.update(jobId, folderId, mapping);
return resultFolder.getId();
}
代码示例来源:origin: pentaho/pentaho-kettle
protected void doCreateFolder() throws Exception {
if ( !getName().getBaseName().isEmpty() ) {
File folder = new File();
folder.setName( getName().getBaseName() );
folder.setMimeType( MIME_TYPES.FOLDER.mimeType );
folder = driveService.files().create( folder ).execute();
if ( folder != null ) {
id = folder.getId();
mimeType = MIME_TYPES.get( folder.getMimeType() );
}
}
}
代码示例来源:origin: google/data-transfer-project
private void importSingleFile(
UUID jobId,
Drive driveInterface,
DigitalDocumentWrapper file,
String parentId)
throws IOException {
InputStreamContent content = new InputStreamContent(
null,
jobStore.getStream(jobId, file.getCachedContentId()));
DtpDigitalDocument dtpDigitalDocument = file.getDtpDigitalDocument();
File driveFile = new File().setName(dtpDigitalDocument.getName());
if (!Strings.isNullOrEmpty(parentId)) {
driveFile.setParents(ImmutableList.of(parentId));
}
if (!Strings.isNullOrEmpty(dtpDigitalDocument.getDateModified())) {
driveFile.setModifiedTime(DateTime.parseRfc3339(dtpDigitalDocument.getDateModified()));
}
if (!Strings.isNullOrEmpty(file.getOriginalEncodingFormat())
&& file.getOriginalEncodingFormat().startsWith("application/vnd.google-apps.")) {
driveFile.setMimeType(file.getOriginalEncodingFormat());
}
driveInterface.files().create(
driveFile,
content
).execute();
}
代码示例来源:origin: pentaho/pentaho-kettle
public void close() throws IOException {
File file = new File();
file.setName( getName().getBaseName() );
if ( parent != null ) {
file.setParents( Collections.singletonList( parent.getId() ) );
}
ByteArrayContent fileContent = new ByteArrayContent( "application/octet-stream", toByteArray() );
if ( count > 0 ) {
driveService.files().create( file, fileContent ).execute();
( (GoogleDriveFileSystem) getFileSystem() ).clearFileFromCache( getName() );
}
}
};
代码示例来源:origin: com.github.robozonky/robozonky-integration-stonky
public static com.google.api.services.drive.model.File copyFile(final Drive driveService,
final com.google.api.services.drive.model.File upstream,
final com.google.api.services.drive.model.File parent,
final String name) throws IOException {
LOGGER.debug("Cloning master spreadsheet '{}', setting name: {}.", upstream.getId(), name);
final com.google.api.services.drive.model.File f = new com.google.api.services.drive.model.File();
f.setName(name);
f.setParents(Collections.singletonList(parent.getId()));
final com.google.api.services.drive.model.File result = driveService.files().copy(upstream.getId(), f)
.setFields("id,name,modifiedTime")
.execute();
LOGGER.debug("Created a copy: {}.", result.getId());
return result;
}
代码示例来源:origin: RoboZonky/robozonky
public static com.google.api.services.drive.model.File copyFile(final Drive driveService,
final com.google.api.services.drive.model.File upstream,
final com.google.api.services.drive.model.File parent,
final String name) throws IOException {
LOGGER.debug("Cloning master spreadsheet '{}', setting name: {}.", upstream.getId(), name);
final com.google.api.services.drive.model.File f = new com.google.api.services.drive.model.File();
f.setName(name);
f.setParents(Collections.singletonList(parent.getId()));
final com.google.api.services.drive.model.File result = driveService.files().copy(upstream.getId(), f)
.setFields("id,name,modifiedTime")
.execute();
LOGGER.debug("Created a copy: {}.", result.getId());
return result;
}
代码示例来源:origin: gsuitedevs/java-samples
public String copyPresentation(String presentationId, String copyTitle) throws IOException {
Drive driveService = this.driveService;
// [START slides_copy_presentation]
File copyMetadata = new File().setName(copyTitle);
File presentationCopyFile =
driveService.files().copy(presentationId, copyMetadata).execute();
String presentationCopyId = presentationCopyFile.getId();
// [END slides_copy_presentation]
return presentationCopyId;
}
代码示例来源:origin: siom79/jdrivesync
public void store(SyncDirectory syncDirectory) {
Drive drive = driveFactory.getDrive(this.credential);
try {
java.io.File localFile = syncDirectory.getLocalFile().get();
File remoteFile = new File();
remoteFile.setName(localFile.getName());
remoteFile.setMimeType(MIME_TYPE_FOLDER);
remoteFile.setParents(createParentReferenceList(syncDirectory));
BasicFileAttributes attr = Files.readAttributes(localFile.toPath(), BasicFileAttributes.class);
remoteFile.setModifiedTime(new DateTime(attr.lastModifiedTime().toMillis()));
LOGGER.log(Level.FINE, "Inserting new directory '" + syncDirectory.getPath() + "'.");
if (!options.isDryRun()) {
File insertedFile = executeWithRetry(options, () -> drive.files().create(remoteFile).execute());
syncDirectory.setRemoteFile(Optional.of(insertedFile));
}
} catch (IOException e) {
throw new JDriveSyncException(JDriveSyncException.Reason.IOException, "Failed to update file: " + e.getMessage(), e);
}
}
代码示例来源:origin: siom79/jdrivesync
public File createDirectory(File parentDirectory, String title) {
File returnValue = null;
Drive drive = driveFactory.getDrive(this.credential);
try {
File remoteFile = new File();
remoteFile.setName(title);
remoteFile.setMimeType(MIME_TYPE_FOLDER);
remoteFile.setParents(Arrays.asList(parentDirectory.getId()));
LOGGER.log(Level.FINE, "Creating new directory '" + title + "'.");
if (!options.isDryRun()) {
returnValue = executeWithRetry(options, () -> drive.files().create(remoteFile).execute());
}
} catch (IOException e) {
throw new JDriveSyncException(JDriveSyncException.Reason.IOException, "Failed to create directory: " + e.getMessage(), e);
}
return returnValue;
}
代码示例来源:origin: andresoviedo/google-drive-ftp-adapter
/**
* Touches the file, changing the name or date modified
*
* @param fileId the file id to patch
* @param newName the new file name
* @param newLastModified the new last modified date
* @return the patched file
*/
public GFile patchFile(String fileId, String newName, long newLastModified) {
File patch = new File();
if (newName != null) {
patch.setName(newName);
}
if (newLastModified > 0) {
patch.setModifiedTime(new DateTime(newLastModified));
}
return create(patchFile(fileId, patch, 3));
}
代码示例来源:origin: org.talend.components/components-googledrive-runtime
/**
* @param fileId ID of the fileName to copy
* @param destinationFolderId folder ID where to copy the fileId
* @param newName if not empty rename copy to this name
* @param deleteOriginal remove original fileName (aka mv)
* @return copied fileName ID
* @throws IOException when copy fails
*/
public String copyFile(String fileId, String destinationFolderId, String newName, boolean deleteOriginal) throws IOException {
LOG.debug("[copyFile] fileId: {}; destinationFolderId: {}, newName: {}; deleteOriginal: {}.", fileId, destinationFolderId,
newName, deleteOriginal);
File copy = new File();
copy.setParents(Collections.singletonList(destinationFolderId));
if (!newName.isEmpty()) {
copy.setName(newName);
}
File resultFile = drive.files().copy(fileId, copy).setFields("id, parents").execute();
String copiedResourceId = resultFile.getId();
if (deleteOriginal) {
drive.files().delete(fileId).execute();
}
return copiedResourceId;
}
代码示例来源:origin: com.github.robozonky/robozonky-integration-stonky
private File createSpreadsheet(final String name, final java.io.File export, final String mime) throws IOException {
final FileContent fc = new FileContent(mime, export);
final File parent = getOrCreateRoboZonkyFolder(); // retrieve Google folder in which to place the spreadsheet
// convert the spreadsheet to Google Spreadsheet
final File f = new File();
f.setName(name);
f.setParents(Collections.singletonList(parent.getId()));
f.setMimeType(MIME_TYPE_GOOGLE_SPREADSHEET);
LOGGER.debug("Creating a new Google spreadsheet: {}.", f);
final File result = driveService.files().create(f, fc)
.setFields(getFields())
.execute();
// and mark the time when the file was last updated
LOGGER.debug("New Google spreadsheet created: {}.", result.getId());
return result;
}
代码示例来源:origin: RoboZonky/robozonky
private File createSpreadsheet(final String name, final java.io.File export, final String mime) throws IOException {
final FileContent fc = new FileContent(mime, export);
final File parent = getOrCreateRoboZonkyFolder(); // retrieve Google folder in which to place the spreadsheet
// convert the spreadsheet to Google Spreadsheet
final File f = new File();
f.setName(name);
f.setParents(Collections.singletonList(parent.getId()));
f.setMimeType(MIME_TYPE_GOOGLE_SPREADSHEET);
LOGGER.debug("Creating a new Google spreadsheet: {}.", f);
final File result = driveService.files().create(f, fc)
.setFields(getFields())
.execute();
// and mark the time when the file was last updated
LOGGER.debug("New Google spreadsheet created: {}.", result.getId());
return result;
}
代码示例来源:origin: org.talend.components/components-googledrive-runtime
/**
* Create a folder in the specified parent folder
*
* @param parentFolderId folder ID where to create folderName
* @param folderName new folder's name
* @return folder ID value
* @throws IOException when operation fails
*/
public String createFolder(String parentFolderId, String folderName) throws IOException {
File createdFolder = new File();
createdFolder.setName(folderName);
createdFolder.setMimeType(MIME_TYPE_FOLDER);
createdFolder.setParents(Collections.singletonList(parentFolderId));
return drive.files().create(createdFolder).setFields("id").execute().getId();
}
代码示例来源:origin: Talend/components
/**
* Create a folder in the specified parent folder
*
* @param parentFolderId folder ID where to create folderName
* @param folderName new folder's name
* @return folder ID value
* @throws IOException when operation fails
*/
public String createFolder(String parentFolderId, String folderName) throws IOException {
File createdFolder = new File();
createdFolder.setName(folderName);
createdFolder.setMimeType(MIME_TYPE_FOLDER);
createdFolder.setParents(Collections.singletonList(parentFolderId));
return drive.files().create(createdFolder).setFields("id").execute().getId();
}
代码示例来源:origin: com.github.robozonky/robozonky-integration-stonky
private File createRoboZonkyFolder(final Drive driveService) throws IOException {
final File fileMetadata = new File();
fileMetadata.setName(getFolderName(sessionInfo));
fileMetadata.setDescription("RoboZonky aktualizuje obsah tohoto adresáře jednou denně brzy ráno.");
fileMetadata.setMimeType(MIME_TYPE_FOLDER);
final File result = driveService.files().create(fileMetadata)
.setFields(getFields())
.execute();
LOGGER.debug("Created a new Google folder '{}'.", result.getId());
return result;
}
代码示例来源:origin: RoboZonky/robozonky
private File createRoboZonkyFolder(final Drive driveService) throws IOException {
final File fileMetadata = new File();
fileMetadata.setName(getFolderName(sessionInfo));
fileMetadata.setDescription("RoboZonky aktualizuje obsah tohoto adresáře jednou denně brzy ráno.");
fileMetadata.setMimeType(MIME_TYPE_FOLDER);
final File result = driveService.files().create(fileMetadata)
.setFields(getFields())
.execute();
LOGGER.debug("Created a new Google folder '{}'.", result.getId());
return result;
}
代码示例来源:origin: RoboZonky/robozonky
public static File getFile(final String name, final String id) {
final File result = new File();
result.setId(id);
result.setMimeType("application/vnd.google-apps.files");
result.setName(name);
result.setModifiedTime(new DateTime(System.currentTimeMillis()));
return result;
}
代码示例来源:origin: iterate-ch/cyberduck
@Override
public Path touch(final Path file, final TransferStatus status) throws BackgroundException {
try {
final Drive.Files.Create insert = session.getClient().files().create(new File()
.setName(file.getName())
.setMimeType(status.getMime())
.setParents(Collections.singletonList(fileid.getFileid(file.getParent(), new DisabledListProgressListener()))));
final File execute = insert.setSupportsTeamDrives(PreferencesFactory.get().getBoolean("googledrive.teamdrive.enable")).execute();
return new Path(file.getParent(), file.getName(), file.getType(),
new DriveAttributesFinderFeature(session, fileid).toAttributes(execute));
}
catch(IOException e) {
throw new DriveExceptionMappingService().map("Cannot create file {0}", e, file);
}
}
代码示例来源:origin: iterate-ch/cyberduck
@Override
public Path copy(final Path source, final Path target, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException {
try {
final File copy = session.getClient().files().copy(fileid.getFileid(source, new DisabledListProgressListener()), new File()
.setParents(Collections.singletonList(fileid.getFileid(target.getParent(), new DisabledListProgressListener())))
.setName(target.getName()))
.setSupportsTeamDrives(PreferencesFactory.get().getBoolean("googledrive.teamdrive.enable")).execute();
return new Path(target.getParent(), target.getName(), target.getType(),
new PathAttributes(target.attributes()).withVersionId(copy.getId()));
}
catch(IOException e) {
throw new DriveExceptionMappingService().map("Cannot copy {0}", e, source);
}
}
内容来源于网络,如有侵权,请联系作者删除!