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

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

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

File.getMd5Checksum介绍

[英]The MD5 checksum for the content of the file. This is only applicable to files with binary content in Drive.
[中]文件内容的MD5校验和。这仅适用于驱动器中包含二进制内容的文件。

代码示例

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

private void performChecksumCheck(File file, SyncItem syncItem, com.google.api.services.drive.model.File remoteFile, boolean updateMetadata) {
    String remoteFileMd5Checksum = remoteFile.getMd5Checksum();
    String localFileMd5Checksum = computeMd5Checksum(file);
    if (remoteFileMd5Checksum.equals(localFileMd5Checksum)) {
      syncItem.setLocalFile(Optional.of(file));
      if (!updateMetadata) {
        LOGGER.log(Level.FINE, "Not downloading file '" + syncItem.getPath() + "' because MD5 checksums are equal (local: " + localFileMd5Checksum + ", remote: " + remoteFileMd5Checksum + ").");
        ReportFactory.getInstance(options).log(new ReportEntry(syncItem.getPath(), ReportEntry.Status.Synchronized, ReportEntry.Action.Unchanged));
      } else {
        try {
          fileSystemAdapter.setLastModifiedTime(file, remoteFile.getModifiedTime().getValue());
          ReportFactory.getInstance(options).log(new ReportEntry(syncItem.getPath(), ReportEntry.Status.Synchronized, ReportEntry.Action.UpdatedMetadata));
        } catch (Exception e) {
          LOGGER.log(Level.WARNING, "Could not update last modification date of local file '" + file.getAbsolutePath() + "':" + e.getMessage(), e);
          ReportFactory.getInstance(options).log(new ReportEntry(syncItem.getPath(), ReportEntry.Status.Error, ReportEntry.Action.Skipped, e.getMessage()));
        }
      }
    } else {
      LOGGER.log(Level.FINE, "Downloading file '" + syncItem.getPath() + "' because MD5 checksums are not equal (local: " + localFileMd5Checksum + ", remote: " + remoteFileMd5Checksum + ").");
      try {
        InputStream stream = googleDriveAdapter.downloadFile(syncItem);
        fileSystemAdapter.storeFile(stream, syncItem);
        ReportFactory.getInstance(options).log(new ReportEntry(syncItem.getPath(), ReportEntry.Status.Synchronized, ReportEntry.Action.Updated));
      } catch (Exception e) {
        LOGGER.log(Level.SEVERE, "Failed to store file '" + syncItem.getPath() + "': " + e.getMessage());
        ReportFactory.getInstance(options).log(new ReportEntry(syncItem.getPath(), ReportEntry.Status.Error, ReportEntry.Action.Skipped));
      }
    }
  }
});

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

private void performChecksumCheck(SyncItem syncItemFound, File localFile, boolean updateMetadata) {
    com.google.api.services.drive.model.File remoteFile = syncItemFound.getRemoteFile().get();
    String md5ChecksumLocal = computeMd5Checksum(localFile);
    String md5ChecksumRemote = remoteFile.getMd5Checksum();
    if (!md5ChecksumLocal.equals(md5ChecksumRemote)) {
      if (!googleDriveAdapter.isGoogleAppsDocument(remoteFile)) {
        LOGGER.log(Level.FINE, "MD5 checksums are not equal for file '" + syncItemFound.getPath() + "' (local: " + md5ChecksumLocal + "; remote: " + md5ChecksumRemote + "). Updating file.");
        googleDriveAdapter.updateFile(syncItemFound);
        ReportFactory.getInstance(options).log(new ReportEntry(syncItemFound.getPath(), ReportEntry.Status.Synchronized, ReportEntry.Action.Updated));
      }
    } else {
      if (!updateMetadata) {
        LOGGER.log(Level.FINE, "MD5 checksums are equal for file '" + syncItemFound.getPath() + "' (local: " + md5ChecksumLocal + "; remote: " + md5ChecksumRemote + "). Not updating file.");
        ReportFactory.getInstance(options).log(new ReportEntry(syncItemFound.getPath(), ReportEntry.Status.Synchronized, ReportEntry.Action.Unchanged));
      } else {
        if (!googleDriveAdapter.isGoogleAppsDocument(remoteFile)) {
          LOGGER.log(Level.FINE, "MD5 checksums are equal for file '" + syncItemFound.getPath() + "' (local: " + md5ChecksumLocal + "; remote: " + md5ChecksumRemote + "). Updating metadata of remote file.");
          googleDriveAdapter.updateMetadata(syncItemFound);
          ReportFactory.getInstance(options).log(new ReportEntry(syncItemFound.getPath(), ReportEntry.Status.Synchronized, ReportEntry.Action.UpdatedMetadata));
        }
      }
    }
  }
});

代码示例来源:origin: iterate-ch/cyberduck

attributes.setCreationDate(f.getCreatedTime().getValue());
attributes.setChecksum(Checksum.parse(f.getMd5Checksum()));
if(StringUtils.isNotBlank(f.getWebViewLink())) {
  attributes.setLink(new DescriptiveUrl(URI.create(f.getWebViewLink()),

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

private GFile create(File file) {
  GFile newFile = new GFile(file.getName() != null ? file.getName() : file.getOriginalFilename());
  newFile.setId(file.getId());
  newFile.setLastModified(file.getModifiedTime() != null ? file.getModifiedTime().getValue() : 0);
  newFile.setDirectory(GFile.MIME_TYPE.GOOGLE_FOLDER.getValue().equals(file.getMimeType()));
  newFile.setSize(file.getSize() != null ? file.getSize() : 0); // null for directories
  newFile.setMimeType(file.getMimeType());
  newFile.setMd5Checksum(file.getMd5Checksum());
  if (file.getParents() != null) {
    Set<String> newParents = new HashSet<>();
    for (String newParent : file.getParents()) {
      newParents.add(newParent.equals(ROOT_FOLDER_ID) ? "root" : newParent);
    }
    newFile.setParents(newParents);
  } else {
    // does this happen?
    newFile.setParents(Collections.singleton("root"));
  }
  newFile.setTrashed(file.getTrashed() != null && file.getTrashed());
  return newFile;
}

相关文章