com.google.api.services.drive.model.File.setModifiedTime()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(7.9k)|赞(0)|评价(0)|浏览(165)

本文整理了Java中com.google.api.services.drive.model.File.setModifiedTime()方法的一些代码示例,展示了File.setModifiedTime()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。File.setModifiedTime()方法的具体详情如下:
包路径:com.google.api.services.drive.model.File
类名称:File
方法名:setModifiedTime

File.setModifiedTime介绍

[英]The last time the file was modified by anyone (RFC 3339 date-time). Note that setting modifiedTime will also update modifiedByMeTime for the user.
[中]任何人上次修改文件的时间(RFC 3339日期时间)。请注意,设置modifiedTime还将为用户更新ModifiedByTime。

代码示例

代码示例来源:origin: apache/incubator-gobblin

private FileList createFileList(java.util.List<String> fileIds, String folderId) {
  FileList fileList = new FileList();
  java.util.List<File> list = Lists.newArrayList();
  for (String fileId : fileIds) {
   File f = new File();
   f.setId(fileId);
   f.setModifiedTime(new DateTime(System.currentTimeMillis()));
   list.add(f);
  }

  if (folderId != null) {
   File f = new File();
   f.setMimeType(FOLDER_MIME_TYPE);
   f.setId(folderId);
   f.setModifiedTime(new DateTime(System.currentTimeMillis()));
   list.add(f);
  }
  fileList.setFiles(list);
  return fileList;
 }
}

代码示例来源: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: apache/incubator-gobblin

final File file = new File();
file.setId("testId");
file.setModifiedTime(new DateTime(System.currentTimeMillis()));

代码示例来源:origin: andresoviedo/google-drive-ftp-adapter

private File mkdir_impl(GFile gFile, int retry) {
  try {
    // New file
    logger.info("Creating new directory...");
    File file = new File();
    file.setMimeType("application/vnd.google-apps.folder");
    file.setName(gFile.getName());
    file.setModifiedTime(new DateTime(System.currentTimeMillis()));
    file.setParents(new ArrayList<>(gFile.getParents()));
    file = drive.files().create(file).setFields(REQUEST_FILE_FIELDS).execute();
    logger.info("Directory created successfully: " + file.getId());
    return file;
  } catch (IOException e) {
    if (retry > 0) {
      try {
        Thread.sleep(1000);
      } catch (InterruptedException e1) {
        throw new RuntimeException(e1);
      }
      logger.warn("Uploading file failed. Retrying... '" + gFile.getId());
      return mkdir_impl(gFile, --retry);
    }
    throw new RuntimeException("Exception uploading file " + gFile.getId(), e);
  }
}

代码示例来源: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 void updateMetadata(SyncItem syncItem) {
  Drive drive = driveFactory.getDrive(this.credential);
  try {
    java.io.File localFile = syncItem.getLocalFile().get();
    File remoteFile = syncItem.getRemoteFile().get();
    BasicFileAttributes attr = Files.readAttributes(localFile.toPath(), BasicFileAttributes.class);
    if (isGoogleAppsDocument(remoteFile)) {
      return;
    }
    LOGGER.log(Level.FINE, "Updating metadata of remote file " + remoteFile.getId() + " (" + syncItem.getPath() + ").");
    if (!options.isDryRun()) {
      File newRemoteFile = new File();
      newRemoteFile.setModifiedTime(new DateTime(attr.lastModifiedTime().toMillis()));
      Drive.Files.Update updateRequest = drive.files().update(remoteFile.getId(), newRemoteFile).setFields("modifiedTime");
      File updatedFile = executeWithRetry(options, () -> updateRequest.execute());
      syncItem.setRemoteFile(Optional.of(updatedFile));
    }
  } catch (IOException e) {
    throw new JDriveSyncException(JDriveSyncException.Reason.IOException, "Failed to update file: " + e.getMessage(), e);
  }
}

代码示例来源:origin: andresoviedo/google-drive-ftp-adapter

file.setModifiedTime(new DateTime(gFile.getLastModified() != 0 ? gFile.getLastModified() : System.currentTimeMillis()));
file.setName(gFile.getName());

代码示例来源:origin: siom79/jdrivesync

public void updateFile(SyncItem syncItem) {
  Drive drive = driveFactory.getDrive(this.credential);
  try {
    java.io.File localFile = syncItem.getLocalFile().get();
    File remoteFile = syncItem.getRemoteFile().get();
    BasicFileAttributes attr = Files.readAttributes(localFile.toPath(), BasicFileAttributes.class);
    remoteFile.setModifiedTime(new DateTime(attr.lastModifiedTime().toMillis()));
    if (isGoogleAppsDocument(remoteFile)) {
      return;
    }
    LOGGER.log(Level.INFO, "Updating file " + remoteFile.getId() + " (" + syncItem.getPath() + ").");
    if (!options.isDryRun()) {
      Drive.Files.Update updateRequest = drive.files().update(remoteFile.getId(), remoteFile, new FileContent(determineMimeType(localFile), localFile));
      //updateRequest.setModifiedDate(true);
      File updatedFile = executeWithRetry(options, () -> updateRequest.execute());
      syncItem.setRemoteFile(Optional.of(updatedFile));
    }
  } catch (IOException e) {
    throw new JDriveSyncException(JDriveSyncException.Reason.IOException, "Failed to update file: " + e.getMessage(), e);
  }
}

代码示例来源: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: siom79/jdrivesync

remoteFile.setParents(createParentReferenceList(syncFile));
BasicFileAttributes attr = Files.readAttributes(localFile.toPath(), BasicFileAttributes.class);
remoteFile.setModifiedTime(new DateTime(attr.lastModifiedTime().toMillis()));
LOGGER.log(Level.INFO, "Uploading new file '" + syncFile.getPath() + "' (" + bytesWithUnit(attr.size()) + ").");
if (!options.isDryRun()) {

代码示例来源: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 void setTimestamp(final Path file, final Long modified) throws BackgroundException {
    try {
      final String fileid = this.fileid.getFileid(file, new DisabledListProgressListener());
      final File properties = new File();
      properties.setModifiedTime(new DateTime(modified));
      session.getClient().files().update(fileid, properties).setFields("modifiedTime").
        setSupportsTeamDrives(PreferencesFactory.get().getBoolean("googledrive.teamdrive.enable")).execute();
    }
    catch(IOException e) {
      throw new DriveExceptionMappingService().map("Failure to write attributes of {0}", e, file);
    }
  }
}

相关文章