Example usage for java.nio.file Path resolve

List of usage examples for java.nio.file Path resolve

Introduction

In this page you can find the example usage for java.nio.file Path resolve.

Prototype

default Path resolve(String other) 

Source Link

Document

Converts a given path string to a Path and resolves it against this Path in exactly the manner specified by the #resolve(Path) resolve method.

Usage

From source file:org.bonitasoft.web.designer.controller.importer.ImporterResolver.java

public ArtifactImporter getImporter(Path extractDir) {
    Path resources = resolveImportPath(extractDir);
    for (Map.Entry<String, ArtifactImporter> entry : artifactImporters.entrySet()) {
        if (Files.exists(resources.resolve(entry.getKey() + ".json"))) {
            return entry.getValue();
        }/*from   w  w  w  . j  a  v  a  2s  .c om*/
    }
    throw anImportException();
}

From source file:com.netflix.spinnaker.clouddriver.artifacts.gitlab.GitlabArtifactCredentialsTest.java

@Test
void downloadWithTokenFromFile(@TempDirectory.TempDir Path tempDir,
        @WiremockResolver.Wiremock WireMockServer server) throws IOException {
    Path authFile = tempDir.resolve("auth-file");
    Files.write(authFile, "zzz".getBytes());

    GitlabArtifactAccount account = new GitlabArtifactAccount();
    account.setName("my-gitlab-account");
    account.setTokenFile(authFile.toAbsolutePath().toString());

    runTestCase(server, account, m -> m.withHeader("Private-Token", equalTo("zzz")));
}

From source file:com.netflix.spinnaker.clouddriver.artifacts.bitbucket.BitbucketArtifactCredentialsTest.java

@Test
void downloadWithBasicAuthFromFile(@TempDirectory.TempDir Path tempDir,
        @WiremockResolver.Wiremock WireMockServer server) throws IOException {
    Path authFile = tempDir.resolve("auth-file");
    Files.write(authFile, "someuser:somepassw0rd!".getBytes());

    BitbucketArtifactAccount account = new BitbucketArtifactAccount();
    account.setName("my-bitbucket-account");
    account.setUsernamePasswordFile(authFile.toAbsolutePath().toString());

    runTestCase(server, account, m -> m.withBasicAuth("someuser", "somepassw0rd!"));
}

From source file:org.opentestsystem.ap.ivs.service.ValidationUtility.java

public List<ErrorReport> parseErrorReport(final Path reportFolder) {
    final Path errorFilePath = reportFolder.resolve(this.ivsProperties.getErrorReportFileName());
    try {//w ww  .  ja  va  2s  .co  m
        final MappingIterator<ErrorReport> results = new CsvMapper().readerWithTypedSchemaFor(ErrorReport.class)
                .readValues(errorFilePath.toFile());
        return results.readAll();
    } catch (IOException e) {
        throw new SystemException("Error converting item history list to CSV", e);
    }
}

From source file:it.sonarlint.cli.tools.SonarlintInstaller.java

private boolean isInstalled(Path installPath, String version) {
    String directoryName = "sonarlint-cli-" + version;

    Path sonarlint = installPath.resolve(directoryName);

    if (Files.isDirectory(sonarlint)) {
        LOG.debug("SonarLint CLI {} already exists in {}", version, installPath);
        return true;
    }/*from   www  . j a  va 2  s. co  m*/
    return false;
}

From source file:org.opentestsystem.ap.ivs.service.ValidationUtility.java

public Path initializeValidationStructure(final Path destinationRootPath) {
    final Path validationRootChild = destinationRootPath.resolve(validationRootChildName);
    try {//w ww.j  a  v a  2 s .co m
        FileUtils.write(validationRootChild.resolve(manifestFile).toFile(), "<manifest/>", "UTF-8");
    } catch (IOException e) {
        throw new SystemException(e);
    }
    return validationRootChild;
}

From source file:codes.thischwa.c5c.impl.JarFilemanagerMessageResolver.java

@Override
public void setServletContext(ServletContext servletContext) {
    ObjectMapper mapper = new ObjectMapper();
    try {/*  w  w w.  ja  v  a 2s  . c  o  m*/
        if (JarPathResolver.insideJar(getMessagesFolderPath())) {
            CodeSource src = JarFilemanagerMessageResolver.class.getProtectionDomain().getCodeSource();
            URI uri = src.getLocation().toURI();
            logger.info("Message folder is inside jar: {}", uri);

            try (FileSystem jarFS = FileSystems.newFileSystem(uri, new HashMap<String, String>())) {
                if (jarFS.getRootDirectories().iterator().hasNext()) {
                    Path rootDirectory = jarFS.getRootDirectories().iterator().next();

                    Path langFolder = rootDirectory.resolve(getMessagesFolderPath());
                    if (langFolder != null) {
                        try (DirectoryStream<Path> langFolderStream = Files.newDirectoryStream(langFolder,
                                JS_FILE_MASK)) {
                            for (Path langFile : langFolderStream) {
                                String lang = langFile.getFileName().toString();
                                InputStream is = Files.newInputStream(langFile);
                                Map<String, String> langData = mapper.readValue(is,
                                        new TypeReference<HashMap<String, String>>() {
                                        });
                                collectLangData(lang, langData);
                            }
                        }
                    } else {
                        throw new RuntimeException("Folder in jar " + langFolder + " does not exists.");
                    }
                }
            }
        } else {
            File messageFolder = JarPathResolver.getFolder(getMessagesFolderPath());
            logger.info("Message folder resolved to: {}", messageFolder);

            if (messageFolder == null || !messageFolder.exists()) {
                throw new RuntimeException("Folder " + getMessagesFolderPath() + " does not exist");
            }

            for (File file : messageFolder.listFiles(jsFilter)) {
                String lang = FilenameUtils.getBaseName(file.getName());
                Map<String, String> langData = mapper.readValue(file,
                        new TypeReference<HashMap<String, String>>() {
                        });
                collectLangData(lang, langData);
            }
        }
    } catch (URISyntaxException | IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:its.tools.SonarlintInstaller.java

private boolean isInstalled(Path installPath, String version) {
    String directoryName = "sonarlint-daemon-" + version;

    Path sonarlint = installPath.resolve(directoryName);

    if (Files.isDirectory(sonarlint)) {
        LOG.debug("SonarLint Daemon {} already exists in {}", version, installPath);
        return true;
    }/*from w w w. ja v  a  2 s . co m*/
    return false;
}

From source file:es.ucm.fdi.storage.business.entity.StorageObject.java

public void save(InputStream input) throws IOException {
    Path file = root.resolve(UUID.randomUUID().toString());
    try (FileOutputStream out = new FileOutputStream(file.toFile())) {
        MessageDigest sha2sum = MessageDigest.getInstance("SHA-256");

        byte[] dataBytes = new byte[4 * 1024];

        int nread = 0;
        long length = 0;
        while ((nread = input.read(dataBytes)) != -1) {
            sha2sum.update(dataBytes, 0, nread);
            out.write(dataBytes, 0, nread);
            length += nread;/*from   ww  w . j a va  2s.  c  o m*/
        }

        this.internalName = toHexString(sha2sum.digest());
        this.length = length;

        out.close();
        String folder = internalName.substring(0, 2);
        Path parent = Files.createDirectories(root.resolve(folder));
        Files.move(file, parent.resolve(internalName), StandardCopyOption.REPLACE_EXISTING);
    } catch (NoSuchAlgorithmException nsae) {
        throw new IOException("Cant save file", nsae);
    }

}

From source file:cc.kave.commons.externalserializationtests.ExternalTestCaseProviderTest.java

@Before
public void buildTestCaseStructure() throws IOException {
    baseDirectory = Files.createTempDirectory(null);

    Path testSuiteDir = Files.createDirectory(baseDirectory.resolve("TestSuite"));
    Path testCasesDir = Files.createDirectory(testSuiteDir.resolve("TestCases"));

    settingsFile = testCasesDir.resolve("settings.ini");
    expectedFormattedFile = testCasesDir.resolve("expected-formatted.json");

    Files.write(testCasesDir.resolve("FirstTest.json"), expectedFirstInput.getBytes());
    Files.write(testCasesDir.resolve("SecondTest.json"), "Some input".getBytes());
    Files.write(testCasesDir.resolve("expected-compact.json"), expectedCompact.getBytes());
    Files.write(expectedFormattedFile, expectedFormatted.getBytes());

    try (PrintWriter settingsFileWriter = new PrintWriter(settingsFile.toFile())) {
        settingsFileWriter.println("[CSharp]");
        settingsFileWriter.println("SerializedType=SomeCSharpType");
        settingsFileWriter.println("[Java]");
        settingsFileWriter.println("SerializedType=" + expectedSerializedType.getName());
    }/*w  w  w .  j a v  a  2s.  c o m*/
}