Example usage for java.nio.file Path toAbsolutePath

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

Introduction

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

Prototype

Path toAbsolutePath();

Source Link

Document

Returns a Path object representing the absolute path of this path.

Usage

From source file:com.kumarvv.setl.Setl.java

/**
 * init csv paths//  w w w.j  av  a2  s.  c o  m
 *
 * @param def
 * @param defPath
 */
protected void initCsvPaths(final Def def, Path defPath) {
    if (def.getExtract().getCsv() != null && StringUtils.isNotEmpty(def.getExtract().getCsv().getFile())) {
        Path csvPath = defPath.getParent().resolve(def.getExtract().getCsv().getFile()).normalize();
        def.getExtract().getCsv().setFilePath(csvPath.toAbsolutePath().toString());
    }

    for (Load load : def.getLoads()) {
        if (load.getPre() != null && load.getPre().getCsv() != null
                && StringUtils.isNotEmpty(load.getPre().getCsv().getFile())) {
            Path csvPath = defPath.getParent().resolve(load.getPre().getCsv().getFile()).normalize();
            load.getPre().getCsv().setFilePath(csvPath.toAbsolutePath().toString());
        }
        if (load.getPost() != null && load.getPost().getCsv() != null
                && StringUtils.isNotEmpty(load.getPost().getCsv().getFile())) {
            Path csvPath = defPath.getParent().resolve(load.getPost().getCsv().getFile()).normalize();
            load.getPost().getCsv().setFilePath(csvPath.toAbsolutePath().toString());
        }
    }
}

From source file:com.spotify.helios.servicescommon.PersistentAtomicReference.java

private PersistentAtomicReference(final Path filename, final JavaType javaType,
        final Supplier<? extends T> initialValue) throws IOException, InterruptedException {
    try {/*from  w ww .j a  v  a  2s . c o m*/
        this.filename = filename.toAbsolutePath();
        this.tempfilename = filename.getFileSystem().getPath(this.filename.toString() + ".tmp");
        if (Files.exists(filename)) {
            final byte[] bytes = Files.readAllBytes(filename);
            if (bytes.length > 0) {
                value = Json.read(bytes, javaType);
            } else {
                value = initialValue.get();
            }
        } else {
            value = initialValue.get();
        }
    } catch (InterruptedIOException | ClosedByInterruptException e) {
        throw new InterruptedException(e.getMessage());
    }
}

From source file:com.zestedesavoir.zestwriter.model.Content.java

@Override
public void renameTitle(String newTitle) {
    String oldPath = getFilePath();
    Path workspace = Paths.get(getFilePath()).getParent();
    String newPath = FunctionTreeFactory
            .getUniqueDirPath(workspace.toAbsolutePath() + File.separator + ZdsHttp.toSlug(newTitle));
    String newSlug = (new File(newPath)).getName();
    setTitle(newTitle);/*from w w  w.  j  a  v a2  s  . c  o m*/
    setSlug(newSlug);
    File oldDir = new File(oldPath);
    File newDir = new File(newPath);
    if (oldDir.renameTo(newDir)) {
        setBasePath(newPath);
    } else {
        MainApp.getLogger().error("Problme de renommage du titre du conteneur " + newTitle);
    }
}

From source file:edu.stanford.slac.archiverappliance.PB.data.LargePBLineTest.java

@Test
public void testLargeLines() throws Exception {
    // We create vector doubles with a large number of elements; write it out and then test the read.
    String pvName = ConfigServiceForTests.ARCH_UNIT_TEST_PVNAME_PREFIX + "LargeLineTest"
            + largeLineTest.getPartitionGranularity();
    ArchDBRTypes type = ArchDBRTypes.DBR_WAVEFORM_DOUBLE;
    short year = TimeUtils.getCurrentYear();
    for (int i = 1; i < 7200; i++) {
        try (BasicContext context = new BasicContext()) {
            ArrayListEventStream strm = new ArrayListEventStream(1024,
                    new RemotableEventStreamDesc(type, pvName, year));
            DBR_TIME_Double retvd = new DBR_TIME_Double(ArrayUtils
                    .toPrimitive(Collections.nCopies(i, Math.sin(i * Math.PI / 3600)).toArray(new Double[0])));
            retvd.setTimeStamp(new gov.aps.jca.dbr.TimeStamp(TimeUtils.getStartOfCurrentYearInSeconds() + i));
            retvd.setSeverity(1);//  w ww  .  ja  v  a  2 s .c  o  m
            retvd.setStatus(0);
            strm.add(new PBVectorDouble(retvd));
            largeLineTest.appendData(context, pvName, strm);
        } catch (Exception ex) {
            logger.error("Exception appending data " + i, ex);
            fail(ex.getMessage());
        }
    }

    Path[] allPaths = PlainPBPathNameUtility.getAllPathsForPV(new ArchPaths(), largeLineTest.getRootFolder(),
            pvName, ".pb", largeLineTest.getPartitionGranularity(), CompressionMode.NONE,
            configService.getPVNameToKeyConverter());
    assertTrue("testLargeLines returns null for getAllFilesForPV for " + pvName, allPaths != null);
    assertTrue("testLargeLines returns empty array for getAllFilesForPV for " + pvName, allPaths.length > 0);

    for (Path destPath : allPaths) {
        try {
            PBFileInfo info = new PBFileInfo(destPath);
            info.getLastEventEpochSeconds();
            assertTrue("File validation failed for " + destPath.toAbsolutePath().toString(),
                    ValidatePBFile.validatePBFile(destPath, false));
        } catch (Exception ex) {
            logger.error("Exception parsing file" + destPath.toAbsolutePath().toString(), ex);
            fail(ex.getMessage());
        }
    }

}

From source file:org.tinymediamanager.core.movie.tasks.MovieUpdateDatasourceTask2.java

public static HashSet<Path> getAllFilesRecursive(Path folder, int deep) {
    folder = folder.toAbsolutePath();
    AllFilesRecursive visitor = new AllFilesRecursive();
    try {//from   w  w w. j  a  v  a 2s  .  co  m
        Files.walkFileTree(folder, EnumSet.of(FileVisitOption.FOLLOW_LINKS), deep, visitor);
    } catch (IOException e) {
        // can not happen, since we overrided visitFileFailed, which throws no
        // exception ;)
    }
    return visitor.fFound;
}

From source file:org.dragoneronca.util.Configuration.java

/**
 * Init logger and configuration properties.
 * <p/>//from   w ww.j  a v  a2  s.  co m
 * The configuration directory should contain at least: <ul> <li>file
 * &quot;environment.properties&quot;</li> <li>file &quot;log4j.properties&quot;</li> <li>file
 * &quot;log4j-debug.properties&quot;</li> </ul>
 *
 * @param confDir path to the configuration directory
 */
public Configuration(Path confDir) {

    String productLogConfig = confDir.toAbsolutePath().toString() + File.separator + PRODUCT_LOG_CONFIG;
    String developLogConfig = confDir.toAbsolutePath().toString() + File.separator + DEVELOP_LOG_CONFIG;

    // default configuration for log4j
    LogManager.resetConfiguration();
    if (Files.exists(Paths.get(productLogConfig))) {
        PropertyConfigurator.configure(productLogConfig);
    } else {
        BasicConfigurator.configure();
        Logger.getRootLogger().setLevel(Level.INFO);
        LOG.warn("Impossible to load configuration for log4j: " + productLogConfig);
        LOG.warn("Using basic configuration for log4j");
    }

    try {
        Files.walkFileTree(confDir, new SimpleFileVisitor<Path>() {

            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                Matcher confMatcher = CONF_PATTERN.matcher(file.getFileName().toString());
                if (confMatcher.matches()) {

                    LOG.info("Loading configuration file: " + file.toAbsolutePath().toString());

                    try {
                        configurationMap.put(confMatcher.group("name"),
                                new PropertiesConfiguration(file.toAbsolutePath().toString()));
                    } catch (ConfigurationException e) {
                        LOG.warn("Exception while loading: " + file.getFileName().toString());
                    }
                }
                return FileVisitResult.CONTINUE;
            }

        });
    } catch (IOException e) {
        LOG.error("Impossible to load configuration files", e);
        System.exit(-1);
    }

    PropertiesConfiguration envConf = configurationMap.get(ENV_CONF);
    if (envConf != null) {
        String envVar = envConf.getString(ENV_VAR);
        if (envVar != null) {
            Environment tmpEnv = Environment.getByName(envVar);
            if (tmpEnv != null) {
                environment = tmpEnv;
            } else {
                environment = Environment.PRODUCTION;
                LOG.warn("Invalid value for the environment variable in configuration file: "
                        + "config/environment.properties "
                        + "- Only \"development\" and \"production\" are allowed");
            }
        } else {
            environment = Environment.PRODUCTION;
            LOG.warn("Missing environment variable in configuration file: " + "config/environment.properties");
        }
    } else {
        environment = Environment.PRODUCTION;
        LOG.warn("Missing environment configuration file, create: " + "config/environment.properties");
    }

    // advanced logger configuration
    if (environment.equals(Environment.DEVELOPMENT)) {
        LogManager.resetConfiguration();
        if (Files.exists(Paths.get(developLogConfig))) {
            PropertyConfigurator.configure(developLogConfig);
        } else {
            LOG.warn("Impossible to load development configuration for log4j: " + developLogConfig);
            LOG.warn("Using the previous configuration for log4j");
        }
    }
}

From source file:its.tools.SonarlintProject.java

/**
 * Copies project to a temporary location and returns its root path.
 *///from  w w  w . j a v  a  2 s.c  o m
public Path deployProject(String location) throws IOException {
    Path originalLoc = Paths.get("projects").resolve(location);
    String projectName = originalLoc.getFileName().toString();

    if (!Files.isDirectory(originalLoc)) {
        throw new IllegalArgumentException(
                "Couldn't find project directory: " + originalLoc.toAbsolutePath().toString());
    }

    cleanProject();
    project = Files.createTempDirectory(projectName);
    FileUtils.copyDirectory(originalLoc.toFile(), project.toFile());
    return project;
}

From source file:PatternFinder.java

private List<String> getFileNames(String search, List<String> fileNames, Path dir) {
    try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) {
        for (Path path : stream) {
            if (path.toFile().isDirectory()) {
                getFileNames(search, fileNames, path);
            } else {

                String fileName = path.toAbsolutePath().getFileName().toString();
                String[] data = search.split("-");
                if (data[0] != null && (data[0].equals("atoms") || data[0].equals("molecules")
                        || data[0].equals("organisms")))
                    data = (String[]) ArrayUtils.remove(data, 0);

                String differentSearchTerm = String.join("-", data).toLowerCase();

                //Search for patternlab identifier in filesystem
                if (fileName.contains(differentSearchTerm) || fileName.contains(search)) {
                    fileNames.add(path.toAbsolutePath().toString());

                }/*from   w w  w.  j  a v  a  2  s  . c  o m*/

            }
        }
    } catch (IOException e) {
        //e.printStackTrace();
    }
    return fileNames;
}

From source file:jp.gr.java_conf.schkit.utils.ApplicationInfo.java

private void setDirectories() throws Exception {
    // get execute directory
    if (classLotation != null)
        executeDir = Paths.get(classLotation.toURI());

    // get/set working directory
    String tmpdir = System.getProperty("java.io.tmpdir");
    if (tmpdir == null)
        return;/*from   w  w  w. j  a  va2s.co  m*/

    Path dir = Paths.get(tmpdir);
    if (!Files.exists(dir))
        return;

    String tmpname = createWorkingDirectoryName();
    workingDir = Paths.get(dir.toAbsolutePath().toString(), tmpname);
    if (!Files.exists(workingDir)) {
        Files.createDirectories(workingDir);
    }

}

From source file:com.netflix.spinnaker.clouddriver.artifacts.http.HttpArtifactCredentialsTest.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());

    HttpArtifactAccount account = new HttpArtifactAccount();
    account.setName("my-http-account");
    account.setUsernamePasswordFile(authFile.toAbsolutePath().toString());

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