com.google.api.services.drive.Drive.files()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(8.1k)|赞(0)|评价(0)|浏览(180)

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

Drive.files介绍

[英]An accessor for creating requests from the Files collection.

The typical use is:

Drive drive = new Drive(...); Drive.Files.List request = drive.files().list(parameters ...)

[中]用于从文件集合创建请求的访问器。
典型用途是:

Drive drive = new Drive(...); Drive.Files.List request = drive.files().list(parameters ...)

代码示例

代码示例来源:origin: pentaho/pentaho-kettle

protected InputStream doGetInputStream() throws Exception {
 ByteArrayOutputStream out = new ByteArrayOutputStream();
 driveService.files().get( id ).executeMediaAndDownloadTo( out );
 ByteArrayInputStream in = new ByteArrayInputStream( out.toByteArray() );
 return in;
}

代码示例来源:origin: pentaho/pentaho-kettle

protected void doDelete() throws Exception {
 driveService.files().delete( id ).execute();
 id = null;
 mimeType = null;
}

代码示例来源:origin: pentaho/pentaho-kettle

private File searchFile( String fileName, String parentId ) throws Exception {
 File file = null;
 StringBuffer fileQuery = new StringBuffer();
 fileQuery.append( "name = '" + fileName + "'" );
 if ( parentId != null ) {
  fileQuery.append( " and '" + parentId + "' in parents and trashed=false" );
 }
 FileList fileList = driveService.files().list().setQ( fileQuery.toString() ).execute();
 if ( !fileList.getFiles().isEmpty() ) {
  file = fileList.getFiles().get( 0 );
 }
 return file;
}

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

private void setUp() {
 client = mock(Drive.class);
 files = mock(Files.class);
 when(client.files()).thenReturn(files);
}

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

@Override
public FSDataInputStream open(Path path, int bufferSize) throws IOException {
 return closer.register(new FSDataInputStream(
   new SeekableFSInputStream(
     new BufferedInputStream(
       client.files().get(toFileId(path)).executeMediaAsInputStream(), bufferSize))));
}

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

@Override
public FSDataInputStream open(Path path) throws IOException {
 return closer.register(new FSDataInputStream(
   new SeekableFSInputStream(
     new BufferedInputStream(
       client.files().get(toFileId(path)).executeMediaAsInputStream()))));
}

代码示例来源:origin: pentaho/pentaho-kettle

protected String[] doListChildren() throws Exception {
 String[] children = null;
 if ( isFolder() ) {
  id = id == null ? "root" : id;
  String fileQuery = "'" + id + "' in parents and trashed=false";
  FileList files = driveService.files().list().setQ( fileQuery ).execute();
  List<String> fileNames = new ArrayList<String>();
  for ( File file : files.getFiles() ) {
   fileNames.add( file.getName() );
  }
  children = fileNames.toArray( new String[0] );
 }
 return children;
}

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

@Override
public boolean delete(Path path, boolean recursive) throws IOException {
 Preconditions.checkArgument(recursive, "Non-recursive is not supported.");
 String fileId = toFileId(path);
 LOG.debug("Deleting file: " + fileId);
 try {
  client.files().delete(fileId).execute();
 } catch (GoogleJsonResponseException e) {
  GoogleJsonError error = e.getDetails();
  if (404 == error.getCode()) { //Non-existing file id
   return false;
  }
  throw e;
 }
 return true;
}

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

@Override
public FileStatus getFileStatus(Path p) throws IOException {
 Preconditions.checkNotNull(p);
 String fileId = toFileId(p);
 File metadata = client.files().get(fileId)
                .setFields("id,mimeType,modifiedTime,size,permissions")
                .execute();
 return toFileStatus(metadata);
}

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

public void closeTest() throws IOException, FileBasedHelperException {
 State state = new State();
 setUp();
 GoogleDriveFsHelper fsHelper = new GoogleDriveFsHelper(state, client, Closer.create());
 Get getResult = mock(Get.class);
 InputStream is = mock(InputStream.class);
 when(client.files()).thenReturn(files);
 when(files.get(anyString())).thenReturn(getResult);
 when(getResult.executeMediaAsInputStream()).thenReturn(is);
 fsHelper.getFileStream("test");
 fsHelper.close();
 verify(is, times(1)).close();
}

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

Drive.Files.List request = client.files()
  .list()
  .setFields("files/id,files/mimeType,files/modifiedTime,files/size,files/permissions")

代码示例来源: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: google/data-transfer-project

throws Exception {
Drive driveInterface = getDriveInterface((authData));
List driveListOperation = driveInterface.files().list();
    inputStream =
      driveInterface
        .files()
        .export(file.getId(), newMimeType)
        .executeMedia()
    inputStream =
      driveInterface
        .files()
        .get(file.getId())
        .setAlt("media")

代码示例来源:origin: com.github.robozonky/robozonky-integration-stonky

public static com.google.api.services.drive.model.File getFile(final Drive driveService,
                                final String id) throws IOException {
  LOGGER.debug("Loading file: {}.", id);
  return driveService.files().get(id)
      .setFields("id,name,modifiedTime")
      .execute();
}

代码示例来源:origin: org.apache.gobblin/google-ingestion

@Override
public FSDataInputStream open(Path path, int bufferSize) throws IOException {
 return closer.register(new FSDataInputStream(
   new SeekableFSInputStream(
     new BufferedInputStream(
       client.files().get(toFileId(path)).executeMediaAsInputStream(), bufferSize))));
}

代码示例来源:origin: org.apache.gobblin/google-ingestion

@Override
public FSDataInputStream open(Path path) throws IOException {
 return closer.register(new FSDataInputStream(
   new SeekableFSInputStream(
     new BufferedInputStream(
       client.files().get(toFileId(path)).executeMediaAsInputStream()))));
}

代码示例来源:origin: com.github.robozonky/robozonky-integration-stonky

private static Stream<File> getFilesInFolder(final Drive driveService, final String parentId) throws IOException {
  LOGGER.debug("Listing files in folder {}.", parentId);
  return driveService.files().list()
      .setQ("'" + parentId + "' in parents and trashed = false")
      .setFields("nextPageToken, files(" + getFields("mimeType") + ")")
      .execute()
      .getFiles()
      .stream()
      .peek(f -> LOGGER.debug("Found '{}' ({}) as {}.", f.getName(), f.getMimeType(), f.getId()));
}

相关文章