本文整理了Java中com.google.api.services.drive.model.File.getName()
方法的一些代码示例,展示了File.getName()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。File.getName()
方法的具体详情如下:
包路径:com.google.api.services.drive.model.File
类名称:File
方法名:getName
[英]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: 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: google/data-transfer-project
folders.add(new BlobbyStorageContainerResource(file.getName(), file.getId(), null, null));
} else if (FUSION_TABLE_MIME_TYPE.equals(file.getMimeType())) {
monitor.info(() -> "Exporting of fusion tables is not yet supported: " + file);
new DigitalDocumentWrapper(
new DtpDigitalDocument(
file.getName(), file.getModifiedTime().toStringRfc3339(), newMimeType),
file.getMimeType(),
file.getId()));
代码示例来源:origin: siom79/jdrivesync
public boolean fileNameValid(File file) {
String title = file.getName();
if (title == null || title.contains("/") || title.contains("\\")) {
return false;
}
return true;
}
代码示例来源:origin: RoboZonky/robozonky
private static Optional<File> getSpreadsheetWithName(final Stream<File> all, final String name) {
LOGGER.debug("Looking up spreadsheet with name: {}.", name);
return listSpreadsheets(all)
.filter(f -> Objects.equals(f.getName(), name))
.findFirst();
}
代码示例来源:origin: com.github.robozonky/robozonky-integration-stonky
private static Optional<File> getSpreadsheetWithName(final Stream<File> all, final String name) {
LOGGER.debug("Looking up spreadsheet with name: {}.", name);
return listSpreadsheets(all)
.filter(f -> Objects.equals(f.getName(), name))
.findFirst();
}
代码示例来源:origin: siom79/jdrivesync
private String toRelativePath(File file, SyncDirectory syncDirectory) {
if (syncDirectory.isRootDirectory()) {
return "/" + file.getName();
} else {
String parentPath = syncDirectory.getPath();
return parentPath + "/" + file.getName();
}
}
代码示例来源:origin: siom79/jdrivesync
private void removeDuplicates(List<File> resultList) {
Map<String, File> fileNameMap = new HashMap<>();
Iterator<File> iterator = resultList.iterator();
while (iterator.hasNext()) {
File file = iterator.next();
String title = file.getName();
File titleFound = fileNameMap.get(title);
if (titleFound == null) {
fileNameMap.put(title, file);
} else {
LOGGER.log(Level.WARNING, "Ignoring remote file '" + title + "' (id: '" + file.getId() + "') because its title/name appears more than once in this folder.");
iterator.remove();
}
}
}
代码示例来源:origin: RoboZonky/robozonky
public static DriveOverview create(final SessionInfo sessionInfo, final Drive driveService,
final Sheets sheetService) throws IOException {
final String folderName = getFolderName(sessionInfo);
LOGGER.debug("Listing all files in the root of Google Drive, looking up folder: {}.", folderName);
final List<File> files = getFilesInFolder(driveService, "root").collect(Collectors.toList());
final Optional<File> result = files.stream()
.peek(f -> LOGGER.debug("Found '{}' ({}) as {}.", f.getName(), f.getMimeType(), f.getId()))
.filter(f -> Objects.equals(f.getMimeType(), MIME_TYPE_FOLDER))
.filter(f -> Objects.equals(f.getName(), folderName))
.findFirst();
if (result.isPresent()) {
return create(sessionInfo, driveService, sheetService, result.get());
} else {
return new DriveOverview(sessionInfo, driveService, sheetService);
}
}
代码示例来源:origin: com.github.robozonky/robozonky-integration-stonky
public static DriveOverview create(final SessionInfo sessionInfo, final Drive driveService,
final Sheets sheetService) throws IOException {
final String folderName = getFolderName(sessionInfo);
LOGGER.debug("Listing all files in the root of Google Drive, looking up folder: {}.", folderName);
final List<File> files = getFilesInFolder(driveService, "root").collect(Collectors.toList());
final Optional<File> result = files.stream()
.peek(f -> LOGGER.debug("Found '{}' ({}) as {}.", f.getName(), f.getMimeType(), f.getId()))
.filter(f -> Objects.equals(f.getMimeType(), MIME_TYPE_FOLDER))
.filter(f -> Objects.equals(f.getName(), folderName))
.findFirst();
if (result.isPresent()) {
return create(sessionInfo, driveService, sheetService, result.get());
} else {
return new DriveOverview(sessionInfo, driveService, sheetService);
}
}
代码示例来源:origin: siom79/jdrivesync
public Iterator<SyncItem> getChildrenIterator() {
Collections.sort(children, (o1, o2) -> {
if(o1.getLocalFile().isPresent() && o2.getLocalFile().isPresent()) {
return o1.getLocalFile().get().getName().compareTo(o2.getLocalFile().get().getName());
} else if(o1.getRemoteFile().isPresent() && o2.getRemoteFile().isPresent()) {
return o1.getRemoteFile().get().getName().compareTo(o2.getRemoteFile().get().getName());
} else if(o1.getLocalFile().isPresent() && o2.getRemoteFile().isPresent()) {
return o1.getLocalFile().get().getName().compareTo(o2.getRemoteFile().get().getName());
} else if(o2.getLocalFile().isPresent() && o1.getRemoteFile().isPresent()) {
return o2.getLocalFile().get().getName().compareTo(o1.getRemoteFile().get().getName());
}
return 0;
});
return children.iterator();
}
代码示例来源:origin: com.github.robozonky/robozonky-integration-stonky
private File createOrReuseStonky() throws IOException {
final String masterId = Properties.STONKY_MASTER.getValue()
.orElseGet(() -> Util.wrap(this::autodetectLatestStonkyVersion).get());
LOGGER.debug("Will look for Stonky master spreadsheet: {}.", masterId);
final File upstream = Util.getFile(driveService, masterId);
final File parent = getOrCreateRoboZonkyFolder();
final String expectedName = "My " + upstream.getName(); // such as "My Stonky 0.8 [Public Beta Release]"
final Optional<File> stonky = listSpreadsheets(getFilesInFolder(driveService, parent))
.filter(s -> Objects.equals(s.getName(), expectedName))
.findFirst();
if (stonky.isPresent()) {
final File result = stonky.get();
LOGGER.debug("Found a copy of Stonky: {}.", result.getId());
return result;
} else {
return Util.copyFile(driveService, upstream, parent, expectedName);
}
}
代码示例来源:origin: RoboZonky/robozonky
private File createOrReuseStonky() throws IOException {
final String masterId = Properties.STONKY_MASTER.getValue()
.orElseGet(() -> Util.wrap(this::autodetectLatestStonkyVersion).get());
LOGGER.debug("Will look for Stonky master spreadsheet: {}.", masterId);
final File upstream = Util.getFile(driveService, masterId);
final File parent = getOrCreateRoboZonkyFolder();
final String expectedName = "My " + upstream.getName(); // such as "My Stonky 0.8 [Public Beta Release]"
final Optional<File> stonky = listSpreadsheets(getFilesInFolder(driveService, parent))
.filter(s -> Objects.equals(s.getName(), expectedName))
.findFirst();
if (stonky.isPresent()) {
final File result = stonky.get();
LOGGER.debug("Found a copy of Stonky: {}.", result.getId());
return result;
} else {
return Util.copyFile(driveService, upstream, parent, expectedName);
}
}
代码示例来源:origin: siom79/jdrivesync
public File getFile(String id) {
Drive drive = driveFactory.getDrive(this.credential);
try {
File file = executeWithRetry(options, () -> drive.files().get(id).execute());
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, "Got file : " + file.getId() + ":" + file.getName());
}
return file;
} catch (IOException e) {
throw new JDriveSyncException(JDriveSyncException.Reason.IOException, "Failed to execute get file request: " + e.getMessage(), e);
}
}
代码示例来源:origin: RoboZonky/robozonky
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()));
}
代码示例来源:origin: siom79/jdrivesync
private void processRemoteChildNotFound(com.google.api.services.drive.model.File remoteChild, SyncDirectory syncDirectory) {
LOGGER.log(Level.FINE, "Deleting remote file/directory '" + remoteChild.getName() + "' because locally it does not exist any more.");
if (googleDriveAdapter.isDirectory(remoteChild)) {
googleDriveAdapter.deleteDirectory(remoteChild);
ReportFactory.getInstance(options).log(new ReportEntry(syncDirectory.getPath() + "/" + remoteChild.getName(), ReportEntry.Status.Synchronized, ReportEntry.Action.Deleted));
} else {
if (!googleDriveAdapter.isGoogleAppsDocument(remoteChild)) {
googleDriveAdapter.deleteFile(remoteChild);
ReportFactory.getInstance(options).log(new ReportEntry(syncDirectory.getPath() + "/" + remoteChild.getName(), ReportEntry.Status.Synchronized, ReportEntry.Action.Deleted));
}
}
}
代码示例来源: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()));
}
代码示例来源:origin: MrStahlfelge/gdx-gamesvcs
/**
* Blocking version of {@link #fetchGameStatesSync()}
*
* @return game states
* @throws IOException
*/
public Array<String> fetchGameStatesSync() throws IOException {
if (!driveApiEnabled)
throw new UnsupportedOperationException();
Array<String> games = new Array<String>();
FileList l = GApiGateway.drive.files().list()
.setSpaces("appDataFolder")
.setFields("files(name)")
.execute();
for (File f : l.getFiles()) {
games.add(f.getName());
}
return games;
}
代码示例来源: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;
}
代码示例来源:origin: Talend/components
private IndexedRecord convertSearchResultToIndexedRecord(File file) {
// Main record
IndexedRecord main = new GenericData.Record(schema);
main.put(0, file.getId());
main.put(1, file.getName());
main.put(2, file.getMimeType());
main.put(3, file.getModifiedTime().getValue());
main.put(4, file.getSize());
main.put(5, file.getKind());
main.put(6, file.getTrashed());
main.put(7, file.getParents().toString()); // TODO This should be a List<String>
main.put(8, file.getWebViewLink());
return main;
}
代码示例来源:origin: org.talend.components/components-googledrive-runtime
private IndexedRecord convertSearchResultToIndexedRecord(File file) {
// Main record
IndexedRecord main = new GenericData.Record(schema);
main.put(0, file.getId());
main.put(1, file.getName());
main.put(2, file.getMimeType());
main.put(3, file.getModifiedTime().getValue());
main.put(4, file.getSize());
main.put(5, file.getKind());
main.put(6, file.getTrashed());
main.put(7, file.getParents().toString()); // TODO This should be a List<String>
main.put(8, file.getWebViewLink());
return main;
}
内容来源于网络,如有侵权,请联系作者删除!