本文整理汇总了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;
}
示例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;
}
示例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());
}
}
}
示例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) {}
}
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
}
}
示例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;
}
示例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());
}
示例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);
}
示例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;
}
示例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();
}
});
}
}
示例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;
}
}
}
示例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;
}