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:eu.itesla_project.iidm.ddb.eurostag_imp_exp.tools.DdbUpdateEurostagDataTool.java

@Override
public void run(CommandLine line) throws Exception {
    String dataDir = line.getOptionValue(DATA_DIR);
    String ddFile = line.getOptionValue(DD_FILE);
    String jbossHost = line.getOptionValue(HOST);
    String jbossPort = line.getOptionValue(PORT);
    String jbossUser = line.getOptionValue(USER);
    String jbossPassword = line.getOptionValue(PASSWORD);
    String eurostagVersion = line.getOptionValue(EUROSTAG_VERSION);

    Path ddFilePath = Paths.get(ddFile);
    Path ddData = Paths.get(dataDir);
    Path ddPath = ddData.resolve("gene");
    Path genPath = ddData.resolve("reguls");
    Path dicoPath = ddData.resolve("dico.txt");

    if ((ddFilePath.toFile().isFile()) == false) {
        throw new RuntimeException(DD_FILE + ": " + ddFile + " is not a file!");
    }/*from www .  j  a  v a 2 s.  c  om*/

    DdbDtaImpExp ddbImpExp = new DdbDtaImpExp(new DdbConfig(jbossHost, jbossPort, jbossUser, jbossPassword));
    ddbImpExp.setUpdateFlag(true);
    ddbImpExp.loadEurostagData(ddFilePath, dicoPath, eurostagVersion, genPath);

}

From source file:com.cloudbees.clickstack.vertx.VertxConfigurationBuilder.java

public void fillVertxModuleConfiguration(Path vertxHome, Metadata metadata) throws IOException {
    Path jsonConfPath = vertxHome.resolve("conf/configuration.json");
    Preconditions.checkState(Files.exists(jsonConfPath), "Expected conf file file %s does not exist",
            jsonConfPath);/* w w  w  .jav a 2  s. c  o m*/
    ObjectMapper mapper = new ObjectMapper();
    JsonNodeFactory nodeFactory = mapper.getNodeFactory();
    ObjectNode conf = (ObjectNode) mapper.readValue(jsonConfPath.toFile(), JsonNode.class);

    new VertxConfigurationBuilder().fillVertxModuleConfiguration(metadata, nodeFactory, conf);

    mapper.writerWithDefaultPrettyPrinter().writeValue(jsonConfPath.toFile(), conf);
}

From source file:cz.muni.fi.lessappcache.parser.modules.ImportModule.java

@Override
public ModuleOutput parse(String line, ParsingContext pc) throws ModuleException {
    ModuleOutput output = new ModuleOutput();
    if (line.startsWith("@import")) {
        output.setControl(ModuleControl.STOP);
        String url = line.replaceAll("(?i)^@import\\s+(.*)$", "$1");
        //TODO: regex should be more aggresive
        url = StringUtils.strip(url, "\'\"");
        Path base = PathUtils.isAbsoluteOrRemote(url) ? Paths.get("") : pc.getContext();
        Path file = base.resolve(Paths.get(url));
        if (Importer.isImported(file)) {
            logger.warn("File " + file + " already imported. Skipping...");
            return output;
        }//from   www .j a  v a 2 s  . c om
        ManifestParser mp = new ManifestParser(file);
        try {
            mp.getLoadedResources().putAll(pc.getLoadedResources());
            mp.setMode(pc.getMode());
            output.getOutput().addAll(mp.processFile());
            output.setLoadedResources(mp.getLoadedResources());
            output.setMode(mp.getMode());
        } catch (IOException ex) {
            logger.error("File " + file + " not found.");
            throw new ModuleException(ex);
        }
    }
    return output;
}

From source file:com.boundlessgeo.geoserver.bundle.BundleExporterTest.java

void assertPathExists(Path root, String path) {
    assertTrue(root.resolve(path).toFile().exists());
}

From source file:org.bonitasoft.web.designer.repository.AbstractLoader.java

@Override
public T load(Path directory, String filename) {
    try {//from   w  w  w  . jav  a 2  s  .  c  o  m
        return objectMapper.fromJson(readAllBytes(directory.resolve(filename)), type);
    } catch (JsonProcessingException e) {
        throw new JsonReadException(format("Could not read json file [%s]", filename), e);
    } catch (NoSuchFileException e) {
        throw new NotFoundException(
                format("Could not load component, unexpected structure in the file [%s]", filename));
    } catch (IOException e) {
        throw new RepositoryException(format("Error while getting component (on file [%s])", filename), e);
    }
}

From source file:com.ejisto.core.classloading.scan.ScanAction.java

private void scanGroups(Map<String, List<MockedField>> groups) {
    try {/*from  w  w  w .jav a 2  s .c o m*/
        ClassPool classPool = new ClassPool();
        Path webInf = baseDirectory.resolve("WEB-INF");
        classPool.appendClassPath(webInf.resolve("classes").toAbsolutePath().toString());
        classPool.appendClassPath(webInf.resolve("lib").toAbsolutePath().toString() + "/*");
        classPool.appendSystemPath();
        ClassTransformerImpl transformer = new ClassTransformerImpl(contextPath, mockedFieldsRepository);
        groups.forEach((k, v) -> scanClass(v, classPool, transformer,
                normalize(webInf + File.separator + "classes/", true)));
    } catch (Exception e) {
        log.error("got exception: " + e.toString());
        throw new ApplicationException(e);
    }
}

From source file:org.wte4j.examples.showcase.server.hsql.ShowCaseDbInitializerTest.java

@Test
public void createDatabaseFilesWithoutOveride() throws IOException, SQLException {
    ApplicationContext context = new StaticApplicationContext();
    Path directory = Files.createTempDirectory("database");
    Path dummyFile = directory.resolve("wte4j-showcase.script");
    Files.createFile(dummyFile);//from   ww w  .j  a va  2 s  . co m
    try {
        ShowCaseDbInitializer showCaseDbInitializer = new ShowCaseDbInitializer(context);
        showCaseDbInitializer.createDateBaseFiles(directory, false);

        Set<String> fileNamesInDirectory = listFiles(directory);
        Set<String> expectedFileNames = new HashSet<String>();
        expectedFileNames.add("wte4j-showcase.script");
        assertEquals(expectedFileNames, fileNamesInDirectory);
        assertEquals(0, Files.size(dummyFile));
    } finally {
        deleteDirectory(directory);
    }
}

From source file:ee.ria.xroad.confproxy.commandline.ConfProxyUtilCreateInstance.java

@Override
final void execute(final CommandLine commandLine) throws Exception {
    if (commandLine.hasOption(PROXY_INSTANCE.getOpt())) {
        String instance = commandLine.getOptionValue(PROXY_INSTANCE.getOpt());
        System.out.println("Generating configuration directory for " + "instance '" + instance + "' ...");
        String basePath = SystemProperties.getConfigurationProxyConfPath();
        Path instancePath = Paths.get(basePath, instance);
        Files.createDirectories(instancePath);
        Path confPath = instancePath.resolve(CONF_INI);
        try {/*from  w w  w.ja va 2 s .com*/
            Files.createFile(confPath);
        } catch (FileAlreadyExistsException ex) {
            fail("Configuration for instance '" + instance + "' already exists, aborting. ", ex);
        }
        ConfProxyProperties conf = new ConfProxyProperties(instance);
        System.out.println("Populating '" + CONF_INI + "' with default values ...");
        conf.setValidityIntervalSeconds(DEFAULT_VALIDITY_INTERVAL_SECONDS);
        System.out.println("Done.");
    } else {
        printHelp();
    }
}

From source file:com.cloudbees.clickstack.util.Files2.java

/**
 * Copy given {@code srcFile} to given {@code destDir}.
 *
 * @param srcFile/*from   w  ww.java 2 s  . co m*/
 * @param destDir destination directory, must exist
 * @return
 * @throws RuntimeIOException
 */
@Nonnull
public static Path copyToDirectory(@Nonnull Path srcFile, @Nonnull Path destDir) throws RuntimeIOException {
    Preconditions.checkArgument(Files.exists(srcFile), "Src %s not found");
    Preconditions.checkArgument(!Files.isDirectory(srcFile), "Src %s is a directory");
    Preconditions.checkArgument(Files.exists(destDir), "Dest %s not found");
    Preconditions.checkArgument(Files.isDirectory(destDir), "Dest %s is not a directory");
    try {
        return Files.copy(srcFile, destDir.resolve(srcFile.getFileName()));
    } catch (IOException e) {
        throw new RuntimeIOException("Exception copying " + srcFile.getFileName() + " to " + srcFile, e);
    }
}

From source file:com.cloudera.oryx.ml.SimpleMLUpdateIT.java

@Test
public void testMLUpdate() throws Exception {
    Path tempDir = getTempDir();
    Path dataDir = tempDir.resolve("data");
    Path modelDir = tempDir.resolve("model");
    Map<String, String> overlayConfig = new HashMap<>();
    overlayConfig.put("oryx.batch.update-class", MockMLUpdate.class.getName());
    ConfigUtils.set(overlayConfig, "oryx.batch.storage.data-dir", dataDir);
    ConfigUtils.set(overlayConfig, "oryx.batch.storage.model-dir", modelDir);
    overlayConfig.put("oryx.batch.generation-interval-sec", Integer.toString(GEN_INTERVAL_SEC));
    overlayConfig.put("oryx.batch.block-interval-sec", Integer.toString(BLOCK_INTERVAL_SEC));
    overlayConfig.put("oryx.ml.eval.test-fraction", Double.toString(TEST_FRACTION));
    Config config = ConfigUtils.overlayOn(overlayConfig, getConfig());

    startMessaging();/* www  .  java2 s  . co m*/

    List<Integer> trainCounts = new ArrayList<>();
    List<Integer> testCounts = new ArrayList<>();

    MockMLUpdate.setCountHolders(trainCounts, testCounts);

    startServerProduceConsumeTopics(config, DATA_TO_WRITE, WRITE_INTERVAL_MSEC);

    // If lists are unequal at this point, there must have been an empty test set
    // which yielded no call to evaluate(). Fill in the blank
    while (trainCounts.size() > testCounts.size()) {
        testCounts.add(0);
    }

    log.info("trainCounts = {}", trainCounts);
    log.info("testCounts = {}", testCounts);

    checkOutputData(dataDir, DATA_TO_WRITE);
    checkIntervals(trainCounts.size(), DATA_TO_WRITE, WRITE_INTERVAL_MSEC, GEN_INTERVAL_SEC);

    assertEquals(testCounts.size(), trainCounts.size());

    RandomGenerator random = RandomManager.getRandom();
    int lastTotalTrainCount = 0;
    int lastTestCount = 0;
    for (int i = 0; i < testCounts.size(); i++) {
        int totalTrainCount = trainCounts.get(i);
        int testCount = testCounts.get(i);
        int newTrainInGen = totalTrainCount - (lastTotalTrainCount + lastTestCount);
        if (newTrainInGen == 0) {
            continue;
        }
        lastTotalTrainCount = totalTrainCount;
        lastTestCount = testCount;
        int totalNew = testCount + newTrainInGen;

        IntegerDistribution dist = new BinomialDistribution(random, totalNew, TEST_FRACTION);
        double probability;
        if (testCount < dist.getNumericalMean()) {
            probability = dist.cumulativeProbability(testCount);
        } else {
            probability = 1.0 - dist.cumulativeProbability(testCount);
        }
        log.info("Probability of observing {} as {} sample of {}: {}", testCount, TEST_FRACTION, totalNew,
                probability);
        assertTrue(probability >= 0.001);
    }

}