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:io.fabric8.kubernetes.pipeline.BuildImageStepExecution.java

private static boolean recursiveMatch(DockerIgnorePathMatcher match, Path file) {
    if (match.matches(file)) {
        return true;
    } else if (file.getParent() != null) {
        return recursiveMatch(match, file.getParent());
    } else {//  w  ww  .  j  ava2  s  .  com
        return false;
    }
}

From source file:org.apache.tika.eval.tools.TopCommonTokenCounter.java

private static void writeTopN(Path path, AbstractTokenTFDFPriorityQueue queue) throws IOException {
    if (Files.isRegularFile(path)) {
        System.err.println("File " + path.getFileName() + " already exists. Skipping.");
        return;/*from  w  w  w . j  av a2 s  . co m*/
    }
    Files.createDirectories(path.getParent());
    BufferedWriter writer = Files.newBufferedWriter(path, StandardCharsets.UTF_8);
    StringBuilder sb = new StringBuilder();
    //add these tokens no matter what
    for (String t : WHITE_LIST) {
        writer.write(t);
        writer.newLine();
    }
    for (TokenDFTF tp : queue.getArray()) {
        writer.write(getRow(sb, tp) + "\n");

    }
    writer.flush();
    writer.close();
}

From source file:controllers.TemplateController.java

@Util
public static TemplateAssignment templateForPath(Project project, Path path) {
    Path cpath = path;
    while (true) {

        TemplateAssignment assignment = TemplateAssignment.forPath(project, cpath);
        if (assignment != null)
            return assignment;

        if (PathService.getRelativeString(cpath).equals("/")) {
            return null;
        }// w  w w .j  av a 2s  . c  o m

        cpath = cpath.getParent();
    }
}

From source file:org.codice.ddf.admin.configurator.impl.ConfigValidator.java

private static void protectHomeDir(Path target) {
    String ddfHomeProp = System.getProperty("ddf.home");
    validateString(ddfHomeProp, "No value set for system property ddf.home");

    Path ddfHomePath = Paths.get(ddfHomeProp);
    if (!target.startsWith(ddfHomePath)) {
        throw new IllegalArgumentException(String.format("File [%s] is not beneath ddf home directory [%s]",
                target.toString(), ddfHomePath.toString()));
    }/*w w  w  .  j  a  va  2s  . co m*/

    if (target.getParent().equals(ddfHomePath)) {
        throw new IllegalArgumentException("Invalid attempt to edit file in ddf.home directory");
    }
}

From source file:edu.umd.umiacs.clip.tools.io.AllFiles.java

public static Path write(Path path, Iterable<? extends CharSequence> lines, OpenOption... options) {
    if (options.length == 0) {
        options = new OpenOption[] { CREATE_NEW };
    }/*from   w  ww .  jav a2  s .  co m*/
    try {
        File parent = path.getParent().toFile();
        if (!parent.exists()) {
            parent.mkdirs();
        }
        return path.toString().endsWith(".gz") ? GZIPFiles.write(path, lines, UTF_8, options)
                : path.toString().endsWith(".bz2") ? BZIP2Files.write(path, lines, UTF_8, options)
                        : Files.write(path, lines, UTF_8, options);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}

From source file:org.roda.core.plugins.plugins.characterization.DigitalSignatureDIPPluginUtils.java

public static void addDetachedSignature(Path input) throws IOException, GeneralSecurityException, CMSException {
    SignatureUtility signatureUtility = new SignatureUtility();
    if (KEYSTORE_PATH != null) {
        try (InputStream is = new FileInputStream(KEYSTORE_PATH)) {
            signatureUtility.loadKeyStore(is, KEYSTORE_PASSWORD.toCharArray());
        }/*from  ww  w  .j a va2  s. c o m*/
    }
    signatureUtility.initSign(KEYSTORE_ALIAS);

    File inputFile = input.toFile();
    signatureUtility.sign(inputFile, input.getParent().resolve(inputFile.getName() + ".p7s").toFile());
}

From source file:ee.ria.xroad.common.conf.globalconf.ConfigurationDirectory.java

/**
 * Saves the file to disk along with corresponding expiration date file.
 * @param fileName the name of the file to save
 * @param content the content of the file
 * @param expirationDate the file expiration date
 * @throws Exception if an error occurs//  w w w  . ja va 2  s.  c  o m
 */
public static final void save(Path fileName, byte[] content, ConfigurationPartMetadata expirationDate)
        throws Exception {
    if (fileName == null) {
        return;
    }

    Path parent = fileName.getParent();
    if (parent != null) {
        Files.createDirectories(parent);
    }

    log.info("Saving content to file {}", fileName);

    // save the content to disk
    AtomicSave.execute(fileName.toString(), "conf", content, StandardCopyOption.ATOMIC_MOVE);

    // save the content metadata date to disk
    saveMetadata(fileName, expirationDate);
}

From source file:com.vaushell.superpipes.tools.scribe.OAuthClient.java

private static void saveToken(final Token accessToken, final Path path) throws IOException {
    if (path == null) {
        throw new IllegalArgumentException();
    }//from  ww w  .j  a v  a 2  s . co  m

    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("[" + OAuthClient.class.getSimpleName() + "] saveToken() : accessToken=" + accessToken
                + " / path=" + path);
    }

    if (accessToken == null) {
        return;
    }

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

    try (final BufferedWriter bfr = Files.newBufferedWriter(path, Charset.forName("utf-8"))) {
        bfr.write(accessToken.getToken());
        bfr.newLine();

        bfr.write(accessToken.getSecret());
        bfr.newLine();

        if (accessToken.getRawResponse() != null) {
            bfr.write(accessToken.getRawResponse());
            bfr.newLine();
        }
    }
}

From source file:org.apache.solr.core.SolrXmlConfig.java

public static NodeConfig fromFile(SolrResourceLoader loader, Path configFile) {

    log.info("Loading container configuration from {}", configFile);

    if (!Files.exists(configFile)) {
        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
                "solr.xml does not exist in " + configFile.getParent() + " cannot start Solr");
    }//from   w w w .  j a v  a  2s . c  o  m

    try (InputStream inputStream = Files.newInputStream(configFile)) {
        return fromInputStream(loader, inputStream);
    } catch (SolrException exc) {
        throw exc;
    } catch (Exception exc) {
        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Could not load SOLR configuration", exc);
    }
}

From source file:illarion.compile.Compiler.java

private static void processPath(@Nonnull final Path path) throws IOException {
    if (Files.isDirectory(path)) {
        return;/* w  ww . j a v a2 s .co  m*/
    }

    int compileResult = 1;
    for (CompilerType type : CompilerType.values()) {
        if (type.isValidFile(path)) {
            Compile compile = type.getImplementation();
            if (path.isAbsolute()) {
                if (storagePaths.containsKey(type)) {
                    compile.setTargetDir(storagePaths.get(type));
                } else {
                    compile.setTargetDir(path.getParent());
                }
            } else {
                if (storagePaths.containsKey(type)) {
                    Path parent = path.getParent();
                    if (parent == null) {
                        compile.setTargetDir(storagePaths.get(type));
                    } else {
                        compile.setTargetDir(storagePaths.get(type).resolve(parent));
                    }
                } else {
                    Path parent = path.getParent();
                    if (parent == null) {
                        compile.setTargetDir(path.toAbsolutePath().getParent());
                    } else {
                        compile.setTargetDir(parent);
                    }
                }
            }
            compileResult = compile.compileFile(path.toAbsolutePath());
            if (compileResult == 0) {
                break;
            }
        }
    }

    switch (compileResult) {
    case 1:
        LOGGER.info("Skipped file: {}", path.getFileName());
        break;
    case 0:
        return;
    default:
        System.exit(compileResult);
    }
}