当前位置: 首页>>代码示例>>Java>>正文


Java Path.startsWith方法代码示例

本文整理汇总了Java中java.nio.file.Path.startsWith方法的典型用法代码示例。如果您正苦于以下问题:Java Path.startsWith方法的具体用法?Java Path.startsWith怎么用?Java Path.startsWith使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.nio.file.Path的用法示例。


在下文中一共展示了Path.startsWith方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getWorkingSetId

import java.nio.file.Path; //导入方法依赖的package包/类
private String getWorkingSetId(final IProject project) {
	final Path projectPath = project.getLocation().toFile().toPath();
	final Path parentPath = projectPath.getParent();

	if (WS_ROOT_PATH.equals(parentPath)) {
		return OTHERS_WORKING_SET_ID;
	}

	if (parentPath.startsWith(WS_ROOT_PATH)) {
		return parentPath.toFile().getName();
	}

	if (!project.isOpen()) { // closed project appear under Other Projects WS
		return OTHERS_WORKING_SET_ID;
	}

	for (final Path repositoryPath : repositoryPaths) {
		if (repositoryPath.equals(projectPath)) {
			return projectPath.toFile().getName();
		} else if (projectPath.startsWith(repositoryPath)) {
			return parentPath.toFile().getName();
		}
	}

	return OTHERS_WORKING_SET_ID;
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:27,代码来源:ProjectLocationAwareWorkingSetManager.java

示例2: findModule

import java.nio.file.Path; //导入方法依赖的package包/类
/**
 * Finds the module at the given location defined to the boot loader.
 * The module is either in runtime image or exploded image.
 * Otherwise this method returns null.
 */
private static Module findModule(String location) {
    String mn = null;
    if (location.startsWith("jrt:/")) {
        // named module in runtime image ("jrt:/".length() == 5)
        mn = location.substring(5, location.length());
    } else if (location.startsWith("file:/")) {
        // named module in exploded image
        Path path = Paths.get(URI.create(location));
        Path modulesDir = Paths.get(JAVA_HOME, "modules");
        if (path.startsWith(modulesDir)) {
            mn = path.getFileName().toString();
        }
    }

    if (mn != null) {
        // named module from runtime image or exploded module
        Optional<Module> om = ModuleLayer.boot().findModule(mn);
        if (!om.isPresent())
            throw new InternalError(mn + " not in boot layer");
        return om.get();
    }

    return null;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:BootLoader.java

示例3: updateTabs

import java.nio.file.Path; //导入方法依赖的package包/类
void updateTabs(Path newPath, Path toRename) {
    ObservableList<Tab> tabs = tabPane.getTabs();

    for (Tab tab : tabs) {
        Path path = (Path) tab.getUserData();

        if (Files.isDirectory(newPath) && path.startsWith(newPath.getParent())) {
            Path newPathRecord = mergeDifferences(path, newPath);
            tab.setUserData(newPathRecord);
        } else if (!Files.isDirectory(newPath) && path.equals(toRename)) {
            Platform.runLater(() -> tab.setText(newPath.getFileName().toString()));
            tab.setUserData(newPath);

            ((CustomCodeArea) ((VirtualizedScrollPane) tab.getContent()).getContent()).setName(newPath.getFileName().toString());
        }
    }
}
 
开发者ID:MrChebik,项目名称:Coconut-IDE,代码行数:18,代码来源:TabUpdater.java

示例4: run

import java.nio.file.Path; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void run() {
	while (running) {
		try {
			final WatchKey watchKey = watcher.take();
			for (final WatchEvent<?> event : watchKey.pollEvents()) {
				Path changed = (Path) event.context();
				if (changed == null || event.kind() == StandardWatchEventKinds.OVERFLOW) {
					System.out.println("bad file watch event: " + event);
					continue;
				}
				changed = watchedDirectory.resolve(changed);
				for (final ListenerAndPath x : listeners) {
					if (Thread.interrupted() && !running)
						return;
					if (changed.startsWith(x.startPath)) {
						x.listener.fileChanged(changed, (Kind<Path>) event.kind());
					}
				}
			}
			watchKey.reset();
		} catch (final InterruptedException e) {}
	}
}
 
开发者ID:Njol,项目名称:Motunautr,代码行数:26,代码来源:FileWatcher.java

示例5: notifyChangedEditedFile

import java.nio.file.Path; //导入方法依赖的package包/类
/**
 * Notify about changed the edited file.
 *
 * @param prevFile the prev file.
 * @param newFile  the new file.
 */
@FXThread
private void notifyChangedEditedFile(final @NotNull Path prevFile, final @NotNull Path newFile) {

    final Path editFile = getEditFile();

    if (editFile.equals(prevFile)) {
        setEditFile(newFile);
        return;
    }

    if (!editFile.startsWith(prevFile)) return;

    final Path relativeFile = editFile.subpath(prevFile.getNameCount(), editFile.getNameCount());
    final Path resultFile = newFile.resolve(relativeFile);

    setEditFile(resultFile);
}
 
开发者ID:JavaSaBr,项目名称:jmonkeybuilder,代码行数:24,代码来源:AbstractFileEditor.java

示例6: notifyCreated

import java.nio.file.Path; //导入方法依赖的package包/类
/**
 * Handle a created file.
 *
 * @param file the created file.
 */
@FXThread
public void notifyCreated(@NotNull final Path file) {

    final EditorConfig editorConfig = EditorConfig.getInstance();
    final Path currentAsset = editorConfig.getCurrentAsset();
    final Path folder = file.getParent();
    if (!folder.startsWith(currentAsset)) return;

    final ResourceElement element = createFor(folder);

    TreeItem<ResourceElement> folderItem = findItemForValue(getRoot(), element);

    if (folderItem == null) {
        notifyCreated(folder);
        folderItem = findItemForValue(getRoot(), folder);
    }

    if (folderItem == null) return;

    final TreeItem<ResourceElement> newItem = new TreeItem<>(createFor(file));

    fill(newItem);

    final ObservableList<TreeItem<ResourceElement>> children = folderItem.getChildren();
    children.add(newItem);

    FXCollections.sort(children, ITEM_COMPARATOR);
}
 
开发者ID:JavaSaBr,项目名称:jmonkeybuilder,代码行数:34,代码来源:ResourceTree.java

示例7: findProjectWith

import java.nio.file.Path; //导入方法依赖的package包/类
@Override
public URI findProjectWith(URI nestedLocation) {
	final String path = nestedLocation.toFileString();
	if (null == path) {
		return null;
	}

	final File nestedResource = new File(path);
	if (!nestedResource.exists()) {
		return null;
	}

	final Path nestedResourcePath = nestedResource.toPath();

	final Iterable<URI> registeredProjectUris = projectCache.asMap().keySet();
	for (final URI projectUri : registeredProjectUris) {
		if (projectUri.isFile()) {
			final File projectRoot = new File(projectUri.toFileString());
			final Path projectRootPath = projectRoot.toPath();
			if (nestedResourcePath.startsWith(projectRootPath)) {
				return projectUri;
			}
		}
	}

	return null;
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:28,代码来源:EclipseExternalLibraryWorkspace.java

示例8: save

import java.nio.file.Path; //导入方法依赖的package包/类
void save() throws IOException {
	for (EnigmaMappingClass cls : classes.values()) {
		String name = cls.mappedName != null ? cls.mappedName : cls.name;
		Path path = dstPath.resolve(name+".mapping").toAbsolutePath();
		if (!path.startsWith(dstPath)) throw new RuntimeException("invalid mapped name: "+name);

		Files.createDirectories(path.getParent());

		try (Writer writer = Files.newBufferedWriter(path, StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE)) {
			processClass(cls, writer);
		}
	}
}
 
开发者ID:sfPlayer1,项目名称:Matcher,代码行数:14,代码来源:EnigmaMappingState.java

示例9: isOtherRoot

import java.nio.file.Path; //导入方法依赖的package包/类
private boolean isOtherRoot(Path dir) throws IOException {
    if (!dir.toFile().isDirectory() || Files.isHidden(dir)) {
        return false;
    }

    // Walk through the other roots and check if a parent of this dir is
    // already available in other roots to avoid folder duplication
    for (Path path : otherRoots) {
        if (dir.startsWith(path)) {
            return false;
        }
    }
    return true;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:NbMavenProjectImpl.java

示例10: pasteInto

import java.nio.file.Path; //导入方法依赖的package包/类
@Override public void pasteInto(Clipboard clipboard, Operation operation) {
    if (clipboard.hasFiles()) {
        List<File> files = clipboard.getFiles();
        List<Path> paths = new ArrayList<>();
        for (File file : files) {
            paths.add(file.toPath().toAbsolutePath());
        }
        Collections.sort(paths);
        Path lastCopiedPath = null;
        for (Path path : paths) {
            try {
                if (lastCopiedPath == null || !path.startsWith(lastCopiedPath)) {
                    Path newPath = Copy.copy(path, this.path, operation);
                    if (newPath == null) {
                        continue;
                    }
                    Resource to;
                    if (Files.isDirectory(newPath)) {
                        to = new FolderResource(newPath.toFile(), watcher);
                    } else {
                        to = new FileResource(newPath.toFile());
                    }
                    lastCopiedPath = path;
                    Resource from;
                    if (path.toFile().isDirectory()) {
                        from = new FolderResource(path.toFile(), watcher);
                    } else {
                        from = new FileResource(path.toFile());
                    }
                    Event.fireEvent(this, new ResourceView.ResourceModificationEvent(
                            operation == Operation.CUT ? ResourceModificationEvent.MOVED : ResourceModificationEvent.COPIED,
                            from, to));
                }
            } catch (IOException e) {
                FXUIUtils.showMessageDialog(null, "Error in copying files.", e.getMessage(), AlertType.ERROR);
            }
        }
    }
    Platform.runLater(() -> refresh());
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:41,代码来源:FolderResource.java

示例11: makeRelative

import java.nio.file.Path; //导入方法依赖的package包/类
private Path makeRelative(Path testJarFile, Path classFile) {
  Path regularParent =
      testJarFile.getParent().resolve(Paths.get("classes"));
  Path legacyParent = regularParent.resolve(Paths.get("..",
      regularParent.getFileName().toString() + "Legacy", "classes"));

  if (classFile.startsWith(regularParent)) {
    return regularParent.relativize(classFile);
  }
  Assert.assertTrue(classFile.startsWith(legacyParent));
  return legacyParent.relativize(classFile);
}
 
开发者ID:inferjay,项目名称:r8,代码行数:13,代码来源:D8IncrementalRunExamplesAndroidOTest.java

示例12: get

import java.nio.file.Path; //导入方法依赖的package包/类
/**
 * Tries to resolve the given path against the list of available roots.
 *
 * If path starts with one of the listed roots, it returned back by this method, otherwise null is returned.
 */
public static Path get(Path[] roots, String path) {
    for (Path root : roots) {
        Path normalizedRoot = root.normalize();
        Path normalizedPath = normalizedRoot.resolve(path).normalize();
        if(normalizedPath.startsWith(normalizedRoot)) {
            return normalizedPath;
        }
    }
    return null;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:16,代码来源:PathUtils.java

示例13: deleteFile

import java.nio.file.Path; //导入方法依赖的package包/类
@SneakyThrows(IOException.class)
public void deleteFile(Path path) {
    if (Files.exists(path) && path.startsWith(this.path)) {
        Files.walk(path)
                .collect(Collectors.toCollection(LinkedList::new))
                .descendingIterator()
                .forEachRemaining(p -> {
                    try {
                        Files.delete(p);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                });
    }
}
 
开发者ID:MrChebik,项目名称:Coconut-IDE,代码行数:16,代码来源:Project.java

示例14: removeSubPaths

import java.nio.file.Path; //导入方法依赖的package包/类
private static void removeSubPaths(final SortedSet<Path> sortedPaths) {
    final Iterator<Path> iterator = sortedPaths.iterator();
    Path current = null;
    while (iterator.hasNext()) {
        Path next = iterator.next();
        if (current != null && next.startsWith(current)) {
            iterator.remove();
        } else {
            current = next;
        }
    }
}
 
开发者ID:openweb-nl,项目名称:hippo-groovy-updater,代码行数:13,代码来源:SubDirectoriesWatcher.java

示例15: contains

import java.nio.file.Path; //导入方法依赖的package包/类
private boolean contains(Collection<Path> searchPath, Path file) throws IOException {

        if (searchPath == null) {
            return false;
        }

        Path enclosingJar = null;
        if (file.getFileSystem().provider() == fsInfo.getJarFSProvider()) {
            URI uri = file.toUri();
            if (uri.getScheme().equals("jar")) {
                String ssp = uri.getSchemeSpecificPart();
                int sep = ssp.lastIndexOf("!");
                if (ssp.startsWith("file:") && sep > 0) {
                    enclosingJar = Paths.get(URI.create(ssp.substring(0, sep)));
                }
            }
        }

        Path nf = normalize(file);
        for (Path p : searchPath) {
            Path np = normalize(p);
            if (np.getFileSystem() == nf.getFileSystem()
                    && Files.isDirectory(np)
                    && nf.startsWith(np)) {
                return true;
            }
            if (enclosingJar != null
                    && Files.isSameFile(enclosingJar, np)) {
                return true;
            }
        }

        return false;
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:35,代码来源:Locations.java


注:本文中的java.nio.file.Path.startsWith方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。