Example usage for java.nio.file Path getParent

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

Introduction

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

Prototype

Path getParent();

Source Link

Document

Returns the parent path, or null if this path does not have a parent.

Usage

From source file:org.pdfsam.configuration.EnhancedClassloaderProvider.java

private static Path getModulesPath() throws URISyntaxException {
    URL jarLocation = EnhancedClassloaderProvider.class.getProtectionDomain().getCodeSource().getLocation();
    if (jarLocation != null) {
        Path jarPath = Paths.get(jarLocation.toURI());
        return Paths.get(jarPath.getParent().toString(), MODULES_DIRECTORY);
    }//w  w w  .  ja v a 2 s.c  o  m
    LOG.warn(DefaultI18nContext.getInstance().i18n("Unable to find modules location."));
    return null;
}

From source file:azkaban.webapp.AzkabanWebServerTest.java

private static String getSqlScriptsDir() throws IOException {
    // Dummy because any resource file works.
    final String dummyResourcePath = getUserManagerXmlFile();
    Path resources = Paths.get(dummyResourcePath).getParent();
    Path azkabanRoot = resources.getParent().getParent().getParent().getParent();

    File sqlScriptDir = Paths.get(azkabanRoot.toString(), AZKABAN_DB_SQL_PATH).toFile();
    return sqlScriptDir.getCanonicalPath();
}

From source file:com.github.horrorho.inflatabledonkey.pcs.xfile.FileAssembler.java

static boolean createDirectories(Path file) {
    Path parent = file.getParent();
    if (parent != null) {
        if (Files.exists(parent)) {
            if (Files.isDirectory(parent)) {
                return true;

            } else {
                logger.warn("-- createDirectories() - path exists but is not a directory: {}", file);
                return false;
            }//from   w ww.  j a  v  a2  s.  c om
        }

        try {
            Files.createDirectories(parent);
            return true;

        } catch (IOException ex) {
            logger.debug("-- createDirectories() - IOException: {}", ex);
            return false;
        }
    }
    return true;
}

From source file:com.teradata.tempto.internal.convention.SqlTestsFileUtils.java

public static Path changeExtension(Path source, String extension) {
    String newFileName = changeExtension(extension, source.getFileName().toString());
    return source.getParent().resolve(newFileName);
}

From source file:io.hightide.TemplateFetcher.java

public static Path extractTemplate(Path tempFile) throws IOException {
    return extractTemplate(tempFile, tempFile.getParent());
}

From source file:org.eclipse.winery.yaml.common.Utils.java

public static Path unzipFile(InputStream in) {
    Path dir = Utils.getTmpDir(Paths.get("zip"));
    FileUtils.forceDelete(dir);//from  w  ww .  ja  v  a  2  s  .  c o m
    try (ZipInputStream inputStream = new ZipInputStream(in)) {
        ZipEntry entry;
        while (Objects.nonNull(entry = inputStream.getNextEntry())) {
            if (!entry.isDirectory()) {
                Path targetPath = dir.resolve(entry.getName());
                Files.createDirectories(targetPath.getParent());
                Files.copy(inputStream, targetPath);
                logger.debug("Write tmp file: {}", targetPath.toString());
            }
        }
    } catch (Exception e) {
        logger.error("Create zip tmp file error: ", e);
    }
    return dir;
}

From source file:oz.hadoop.yarn.api.utils.MiniClusterUtils.java

public static void startMiniCluster() {
    try {//from  w w w.j a  va 2 s. c o  m
        semaphore.acquire();
    } catch (InterruptedException e) {
        throw new IllegalStateException("Acquisition of semaphore is interrupted. Exiting");
    }
    if (clusterLauncher != null) {
        throw new IllegalStateException("MiniClustrer is currently running");
    }
    File file = new File("");
    Path path = Paths.get(file.getAbsolutePath());

    Path parentPath = path.getParent();

    File clusterConfiguration = new File(parentPath + "/yarn-test-cluster/src/main/resources");
    Assert.isTrue(clusterConfiguration.exists());
    ConfigUtils.addToClasspath(clusterConfiguration);

    File miniClusterExe = new File(
            parentPath.toString() + "/yarn-test-cluster/build/install/yarn-test-cluster/bin/yarn-test-cluster");
    System.out.println(miniClusterExe.getAbsolutePath());
    if (!miniClusterExe.exists()) {
        logger.info("BUILDING MINI_CLUSTER");
        CommandProcessLauncher buildLauncher = new CommandProcessLauncher(
                path.toString() + "/build-mini-cluster");
        buildLauncher.launch();
    }
    Assert.isTrue(miniClusterExe.exists(), "Failed to find mini-cluster executable");
    clusterLauncher = new CommandProcessLauncher(miniClusterExe.getAbsolutePath());
    executor = Executors.newSingleThreadExecutor();
    executor.execute(new Runnable() {
        @Override
        public void run() {
            logger.info("STARTING MINI_CLUSTER");
            clusterLauncher.launch();
            System.out.println("EXITING>>>>>>>>>");
        }
    });
    try {
        Thread.sleep(2000);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
}

From source file:com.spectralogic.ds3client.helpers.FileObjectPutter_Test.java

private static String getParentDir(final Path path) {
    final String parentPath = path.getParent().toString();
    final int lastIndex = parentPath.lastIndexOf(File.separator);
    return parentPath.substring(lastIndex + 1);
}

From source file:org.gradle.caching.internal.tasks.FileWalkingBenchmark.java

private static void mkdirs(Path path) throws IOException {
    if (path == null || Files.isDirectory(path)) {
        return;//  w  ww .j  a v a 2  s .co m
    }
    mkdirs(path.getParent());
    Files.createDirectory(path);
}

From source file:net.minecrell.serverlistplus.canary.SnakeYAML.java

@SneakyThrows
public static void load(Plugin plugin) {
    try { // Check if it is already loaded
        Class.forName("org.yaml.snakeyaml.Yaml");
        return;/*from   w w w  . j  a va2  s .c o  m*/
    } catch (ClassNotFoundException ignored) {
    }

    Path path = Paths.get("lib", SNAKE_YAML_JAR);

    if (Files.notExists(path)) {
        Files.createDirectories(path.getParent());

        plugin.getLogman().info("Downloading SnakeYAML...");

        URL url = new URL(SNAKE_YAML);
        MessageDigest sha1 = MessageDigest.getInstance("SHA-1");

        try (ReadableByteChannel source = Channels.newChannel(new DigestInputStream(url.openStream(), sha1));
                FileChannel out = FileChannel.open(path, StandardOpenOption.CREATE_NEW,
                        StandardOpenOption.WRITE)) {
            out.transferFrom(source, 0, Long.MAX_VALUE);
        }

        if (!new String(Hex.encodeHex(sha1.digest())).equals(EXPECTED_HASH)) {
            Files.delete(path);
            throw new IllegalStateException(
                    "Downloaded SnakeYAML, but checksum check failed. Please try again later.");
        }

        plugin.getLogman().info("Successfully downloaded!");
    }

    loadJAR(path);
}