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


Java Path.relativize方法代码示例

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


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

示例1: contains0

import java.nio.file.Path; //导入方法依赖的package包/类
static void contains0(String s1, String s2, int expected) throws Exception {
    Path p1 = Paths.get(s1);
    Path p2 = Paths.get(s2);
    int d = (int)containsMethod.invoke(null, p1, p2);
    Path p;
    try {
        p = p2.relativize(p1);
    } catch (Exception e) {
        p = null;
    }
    System.out.printf("%-20s -> %-20s: %20s %5d %5d %s\n", s1, s2, p,
            d, expected, d==expected?"":" WRONG");
    if (d != expected) {
        err = true;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:Correctness.java

示例2: saveDockableState

import java.nio.file.Path; //导入方法依赖的package包/类
public JSONObject saveDockableState() {
    JSONArray a = new JSONArray();
    DockableState[] dockables = getDockables();
    Path projectPath = Constants.getProjectPath();
    for (DockableState dockableState : dockables) {
        String path = dockableState.getDockable().getDockKey().getKey();
        if (path.contains(File.separator)) {
            Path filePath = new File(path).toPath().toAbsolutePath();
            Path relativize = projectPath.relativize(filePath);
            a.put(relativize.toString().replace('\\', '/'));
        } else {
            a.put(path);
        }
    }
    JSONObject o = new JSONObject();
    o.put("dockables", a);
    return o;
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:19,代码来源:DockingDesktop.java

示例3: getSuiteName

import java.nio.file.Path; //导入方法依赖的package包/类
private String getSuiteName(Description description) {
    Test test = (Test) TestAttributes.get("test_object");
    if (test == null) {
        return "<ERROR GETTING TEST>";
    }
    if (test instanceof MarathonTestCase) {
        try {
            Path path = ((MarathonTestCase) test).getFile().toPath();
            Path testPath = Constants.getMarathonDirectory(Constants.PROP_TEST_DIR).toPath();
            if (!path.isAbsolute()) {
                return "root";
            }
            Path relativePath = testPath.relativize(path);
            int nameCount = relativePath.getNameCount();
            StringBuilder sb = new StringBuilder("root");
            for (int i = 0; i < nameCount - 1; i++) {
                sb.append("::").append(relativePath.getName(i));
            }
            return sb.toString();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return "My Own Test Cases";
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:26,代码来源:AllureMarathonRunListener.java

示例4: getAssetFile

import java.nio.file.Path; //导入方法依赖的package包/类
/**
 * Get the path to the file from the current asset folder.
 *
 * @param file the file.
 * @return the relative path.
 */
@FromAnyThread
public static @Nullable Path getAssetFile(@NotNull final Path file) {

    final EditorConfig editorConfig = EditorConfig.getInstance();
    final Path currentAsset = editorConfig.getCurrentAsset();
    if (currentAsset == null) {
        return null;
    }

    try {
        return currentAsset.relativize(file);
    } catch (final IllegalArgumentException e) {
        LOGGER.warning("Can't create asset file of the " + file + " for asset folder " + currentAsset);
        LOGGER.warning(e);
        return null;
    }
}
 
开发者ID:JavaSaBr,项目名称:jmonkeybuilder,代码行数:24,代码来源:EditorUtil.java

示例5: saveCustomDirectoryLocation

import java.nio.file.Path; //导入方法依赖的package包/类
private void saveCustomDirectoryLocation(final Project project) {
    final HybrisProjectSettings hybrisProjectSettings = HybrisProjectSettingsComponent.getInstance(project)
                                                                                      .getState();
    final File customDirectory = hybrisProjectDescriptor.getExternalExtensionsDirectory();
    final File hybrisDirectory = hybrisProjectDescriptor.getHybrisDistributionDirectory();
    final File baseDirectory = VfsUtilCore.virtualToIoFile(project.getBaseDir());
    final Path projectPath = Paths.get(baseDirectory.getAbsolutePath());
    final Path hybrisPath = Paths.get(hybrisDirectory.getAbsolutePath());
    final Path relativeHybrisPath = projectPath.relativize(hybrisPath);
    hybrisProjectSettings.setHybrisDirectory(relativeHybrisPath.toString());
    if (customDirectory != null) {
        final Path customPath = Paths.get(customDirectory.getAbsolutePath());
        final Path relativeCustomPath = hybrisPath.relativize(customPath);
        hybrisProjectSettings.setCustomDirectory(relativeCustomPath.toString());
    }
}
 
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:17,代码来源:ImportProjectProgressModalWindow.java

示例6: createSimplePathFileObject

import java.nio.file.Path; //导入方法依赖的package包/类
/**
 * Create a PathFileObject whose binary name might be inferred from its
 * position on a search path.
 */
static PathFileObject createSimplePathFileObject(JavacPathFileManager fileManager,
        final Path path) {
    return new PathFileObject(fileManager, path) {
        @Override
        String inferBinaryName(Iterable<? extends Path> paths) {
            Path absPath = path.toAbsolutePath();
            for (Path p: paths) {
                Path ap = p.toAbsolutePath();
                if (absPath.startsWith(ap)) {
                    try {
                        Path rp = ap.relativize(absPath);
                        if (rp != null) // maybe null if absPath same as ap
                            return toBinaryName(rp);
                    } catch (IllegalArgumentException e) {
                        // ignore this p if cannot relativize path to p
                    }
                }
            }
            return null;
        }
    };
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:27,代码来源:PathFileObject.java

示例7: configureBuildContext

import java.nio.file.Path; //导入方法依赖的package包/类
private BuildContext configureBuildContext(Path workspaceDir) throws IOException {

    // locate and deserialize configuration files
    Optional<Path> pathToAppYaml = appYamlFinder.findAppYamlFile(workspaceDir);

    AppYaml appYaml = pathToAppYaml.isPresent()
        ? parseAppYaml(pathToAppYaml.get())
        : appYamlParser.getEmpty();

    appYaml.applyOverrideSettings(overrideSettings);

    BuildContext buildContext = buildContextFactory.createBuildContext(appYaml, workspaceDir);

    // if the path to app.yaml is known, add it to the .gitignore
    if (pathToAppYaml.isPresent()) {
      Path relativeAppYamlPath = workspaceDir.relativize(pathToAppYaml.get());
      buildContext.getDockerignore().appendLine(relativeAppYamlPath.toString());
    }

    return buildContext;
  }
 
开发者ID:GoogleCloudPlatform,项目名称:runtime-builder-java,代码行数:22,代码来源:BuildPipelineConfigurator.java

示例8: preVisitDirectory

import java.nio.file.Path; //导入方法依赖的package包/类
@Override
public FileVisitResult preVisitDirectory(Path file,
        BasicFileAttributes attrs) throws IOException {
    Path relativePath = file.relativize(copyFrom);
    Path destination = copyTo.resolve(relativePath);
    if (!destination.toFile().exists()) {
        Files.createDirectories(destination);
    }
    return FileVisitResult.CONTINUE;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:FileInstaller.java

示例9: loadJsonResourceFiles

import java.nio.file.Path; //导入方法依赖的package包/类
public static <T extends NamedTest> List<T> loadJsonResourceFiles(String packageName, Class<T> cls) throws IOException {
//    Preconditions.checkNotNull(packageName, "packageName cannot be null");
    Reflections reflections = new Reflections(packageName, new ResourcesScanner());
    Set<String> resources = reflections.getResources(new FilterBuilder.Include(".*"));
    List<T> datas = new ArrayList<>(resources.size());
    Path packagePath = Paths.get("/" + packageName.replace(".", "/"));
    for (String resource : resources) {
      log.trace("Loading resource {}", resource);
      Path resourcePath = Paths.get("/" + resource);
      Path relativePath = packagePath.relativize(resourcePath);
      File resourceFile = new File("/" + resource);
      T data;
      try (InputStream inputStream = cls.getResourceAsStream(resourceFile.getAbsolutePath())) {
        data = ObjectMapperFactory.INSTANCE.readValue(inputStream, cls);
      } catch (IOException ex) {
        if (log.isErrorEnabled()) {
          log.error("Exception thrown while loading {}", resourcePath, ex);
        }
        throw ex;
      }
      String nameWithoutExtension = Files.getNameWithoutExtension(resource);
      if (null != relativePath.getParent()) {
        String parentName = relativePath.getParent().getFileName().toString();
        data.testName(parentName + "/" + nameWithoutExtension);
      } else {
        data.testName(nameWithoutExtension);
      }
      datas.add(data);
    }
    return datas;
  }
 
开发者ID:jcustenborder,项目名称:kafka-connect-transform-cef,代码行数:32,代码来源:TestDataUtils.java

示例10: pathFileObject

import java.nio.file.Path; //导入方法依赖的package包/类
/**
 * Creates an {@link InferableJavaFileObject} for NIO {@link Path}.
 * @param file the {@link Path} to create file object for
 * @param root the root
 * @param rootUri the root {@link URI} or null if the {@link URI} should be taken from file
 * @param encoding the optional encoding or null for system encoding
 * @return the {@link InferableJavaFileObject}
 */
@NonNull
public static InferableJavaFileObject pathFileObject(
    @NonNull final Path file,
    @NonNull final Path root,
    @NullAllowed final String rootUri,
    @NullAllowed Charset encoding) {
    final char separator = file.getFileSystem().getSeparator().charAt(0);
    final Path relPath = root.relativize(file);
    final String[] path = getFolderAndBaseName(relPath.toString(), separator);
    String fileUri;
    if (rootUri != null) {
        fileUri = relPath.toUri().getRawPath();
        if (fileUri.charAt(0) == FileObjects.NBFS_SEPARATOR_CHAR) {
            fileUri = fileUri.substring(1);
        }
        fileUri = rootUri + fileUri;
    } else {
        fileUri = null;
    }
    return new PathFileObject(
            file,
            convertFolder2Package(path[0], separator),
            path[1],
            fileUri,
            encoding);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:35,代码来源:FileObjects.java

示例11: getURI

import java.nio.file.Path; //导入方法依赖的package包/类
public static URI getURI(Path filePath) {
    if (port == -1)
        return null;
    Path reportPath = Constants.getProjectPath();
    Path relativize = reportPath.relativize(filePath);
    StringBuilder sb = new StringBuilder();
    sb.append("http://localhost:" + port);
    relativize.forEach((p) -> {
        sb.append('/').append(p.toString());
    });
    return URI.create(sb.toString());
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:13,代码来源:ProjectHTTPDServer.java

示例12: getTitle

import java.nio.file.Path; //导入方法依赖的package包/类
public String getTitle() {
    Path corePath = Projects.create().getCorePath();

    return name + " - [" +
            (path.startsWith(corePath) ?
                    "~/" + corePath.getFileName().toString() + "/" + corePath.relativize(path) : path)
            + "] - Coconut-IDE 0.1.1";
}
 
开发者ID:MrChebik,项目名称:Coconut-IDE,代码行数:9,代码来源:Project.java

示例13: toPackageName

import java.nio.file.Path; //导入方法依赖的package包/类
/**
 * Derives a package name from the file path of an entry in an exploded patch
 */
private static String toPackageName(Path top, Path file) {
    Path entry = top.relativize(file);
    Path parent = entry.getParent();
    if (parent == null) {
        return warnIfModuleInfo(top, entry.toString());
    } else {
        return parent.toString().replace(File.separatorChar, '.');
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:ModulePatcher.java

示例14: generateResource

import java.nio.file.Path; //导入方法依赖的package包/类
/**
 * Generates the resource string representation of a product for HFS DataStores.
 *
 * @param racine_path  path of HFS
 * @param product_path path of product
 *
 * @return the resource string representation of product
 */
static String generateResource(String racine_path, String product_path)
{
   Path p_path = Paths.get(product_path);
   Path hfs_path = Paths.get(racine_path);
   Path r_path = hfs_path.relativize(p_path);

   return r_path.toString();
}
 
开发者ID:SentinelDataHub,项目名称:dhus-core,代码行数:17,代码来源:HfsDataStoreUtils.java

示例15: packageOfJavaFile

import java.nio.file.Path; //导入方法依赖的package包/类
private static String packageOfJavaFile(Path sourceRoot, Path javaFile) {
    Path javaFileDir = javaFile.getParent();
    Path packageDir = sourceRoot.relativize(javaFileDir);
    List<String> separateDirs = new ArrayList<>();
    for (Path pathElement : packageDir) {
        separateDirs.add(pathElement.getFileName().toString());
    }
    return String.join(".", separateDirs);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:Source.java


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