Example usage for java.nio.file Path isAbsolute

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

Introduction

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

Prototype

boolean isAbsolute();

Source Link

Document

Tells whether or not this path is absolute.

Usage

From source file:org.codice.ddf.configuration.migration.PathUtilsTest.java

@Test
public void testResolveAgainstDDFHomeWithStringWhenPathIsAbsolute() throws Exception {
    // resolving against DDF_HOME ensures that on Windows the absolute path gets the same drive as
    // DDF_HOME//from  w w  w .j  a v  a  2 s.  co m
    final Path absolutePath = ddfHome.resolve(Paths.get("/test", "script.sh"));

    final Path path = pathUtils.resolveAgainstDDFHome(absolutePath.toString());

    Assert.assertThat(path.isAbsolute(), Matchers.equalTo(true));
    Assert.assertThat(path, Matchers.equalTo(absolutePath));
}

From source file:org.darkware.wpman.security.ChecksumDatabase.java

/**
 * Normalize the given {@code Path} so that internal {@code Path} operations don't have to think about
 * absolute/relative comparisons or paths that don't represent concrete files.
 *
 * @param file The {@code Path} to normalize.
 * @return An absolute {@code Path} to a concrete file which is a descendant of the database root.
 * @throws IllegalArgumentException If the path does not exist, was not a path to a regular file, or pointed
 * to a file that was outside the database root.
 *///from w ww  . ja  v a2s . c om
protected Path normalize(final Path file) {
    Path normalized = file;

    if (normalized.isAbsolute()) {
        if (!file.startsWith(this.root))
            throw new IllegalArgumentException("The given file is outside the database root path.");
    } else {
        normalized = this.root.resolve(normalized);
    }

    if (Files.notExists(normalized))
        throw new IllegalArgumentException("The given file does not exist.");
    if (!Files.isRegularFile(normalized))
        throw new IllegalArgumentException("The given path is not a file.");

    return normalized;
}

From source file:org.openmrs.module.radiology.legacyui.RadiologyProperties.java

/**
 * Gets folder to store {@code MRRT} templates.
 * /*from   w  w w . j  av  a 2  s.  c  o  m*/
 * @return templates folder
 * @throws IllegalStateException if global property cannot be found
 * @should create a directory under the openmrs application data directory if GP value is relative
 * @should creates a directory at GP value if it is an absolute path
 * @should throw illegal state exception if global property cannot be found
 */
public File getReportTemplateHome() {

    Path templatesPath = Paths.get(getGlobalProperty(RadiologyConstants.GP_MRRT_REPORT_TEMPLATE_DIR, true));

    if (!templatesPath.isAbsolute()) {
        templatesPath = Paths.get(OpenmrsUtil.getApplicationDataDirectory(), templatesPath.toString());
    }
    if (!templatesPath.toFile().exists()) {
        templatesPath.toFile().mkdirs();
    }

    return templatesPath.toFile();
}

From source file:com.thinkbiganalytics.metadata.modeshape.support.JcrPath.java

@Override
public Path resolveSibling(Path other) {
    if (other.isAbsolute()) {
        return other;
    } else if (other.getNameCount() == 0) {
        return this;
    } else {/*from w w  w. j  a  va2  s .  c  om*/
        return getParent().resolve(other);
    }
}

From source file:com.thinkbiganalytics.metadata.modeshape.support.JcrPath.java

@Override
public Path resolve(Path other) {
    if (other.isAbsolute()) {
        return other;
    } else if (other.getNameCount() == 0) {
        return this;
    } else {/*from  w ww  .  j a  v  a2s.  c  o m*/
        List<String> elements = new ArrayList<>(this.elements);
        for (int idx = 0; idx < other.getNameCount(); idx++) {
            elements.add(other.getName(idx).toString());
        }
        return new JcrPath(this.absolute, elements);
    }
}

From source file:com.thinkbiganalytics.metadata.modeshape.support.JcrPath.java

@Override
public Path relativize(Path other) {
    if (other.isAbsolute() != isAbsolute() || other.getNameCount() < getNameCount()) {
        return other;
    } else if (other.getNameCount() == 0) {
        return this;
    } else {//  w  w  w  .  j  av  a 2  s. c  om
        int idx = 0;
        for (; idx < getNameCount(); idx++) {
            if (!other.getName(idx).equals(getName(idx))) {
                return other;
            }
        }
        return other.subpath(idx - 1, other.getNameCount());
    }
}

From source file:com.thinkbiganalytics.metadata.modeshape.support.JcrPath.java

@Override
public boolean startsWith(Path other) {
    if (other.isAbsolute() != isAbsolute()) {
        return false;
    } else if (other.getNameCount() > getNameCount()) {
        return false;
    } else {/* w w w  .j  ava 2  s  . c  o  m*/
        for (int idx = 0; idx < other.getNameCount(); idx++) {
            Path otherElem = other.getName(idx);

            if (otherElem.getFileName().equals(this.elements.get(idx))) {
                return false;
            }
        }

        return true;
    }
}

From source file:com.thinkbiganalytics.metadata.modeshape.support.JcrPath.java

@Override
public boolean equals(Object obj) {
    if (obj instanceof Path) {
        Path other = (Path) obj;
        if (isAbsolute() == other.isAbsolute()) {
            return compareTo(other) == 0;
        } else {//from  ww w . j av a  2 s.  c om
            return false;
        }
    } else {
        return false;
    }
}

From source file:org.codice.ddf.security.common.Security.java

private KeyStore getSystemKeyStore() {
    KeyStore keyStore;/*from   w  ww  . j  a v a2 s. c o  m*/

    try {
        keyStore = KeyStore.getInstance(System.getProperty("javax.net.ssl.keyStoreType"));

    } catch (KeyStoreException e) {
        LOGGER.error("Unable to create keystore instance of type {}",
                System.getProperty("javax.net.ssl.keyStoreType"), e);
        return null;
    }

    Path keyStoreFile = new File(System.getProperty("javax.net.ssl.keyStore")).toPath();
    Path ddfHomePath = Paths.get(System.getProperty("ddf.home"));

    if (!keyStoreFile.isAbsolute()) {
        keyStoreFile = Paths.get(ddfHomePath.toString(), keyStoreFile.toString());
    }

    String keyStorePassword = System.getProperty("javax.net.ssl.keyStorePassword");

    if (!Files.isReadable(keyStoreFile)) {
        LOGGER.error("Unable to read system key/trust store files: [ {} ] ", keyStoreFile);
        return null;
    }

    try (InputStream kfis = Files.newInputStream(keyStoreFile)) {
        keyStore.load(kfis, keyStorePassword.toCharArray());
    } catch (NoSuchAlgorithmException | CertificateException | IOException e) {
        LOGGER.error("Unable to load system key file.", e);
    }

    return keyStore;
}

From source file:net.es.nsi.topology.translator.Options.java

/**
 * Processes the "configfile" command line and system property option.
 *
 * @param cmd Commands entered by the user.
 * @param configdir The application configuration directory.
 * @return The configuration file path.//from ww  w  . j  a v  a2  s  .  c o  m
 * @throws IOException
 */
private String getConfigFile(CommandLine cmd) throws IOException {
    String file = System.getProperty(Properties.SYSTEM_PROPERTY_CONFIGFILE);
    file = cmd.getOptionValue(ARGNAME_CONFIGFILE, file);

    Path path;
    if (Strings.isNullOrEmpty(file)) {
        path = Paths.get(basedir, DEFAULT_CONFIGFILE);
    } else {
        path = Paths.get(file);
        if (!path.isAbsolute()) {
            path = Paths.get(basedir, path.toString());
        }
    }

    try {
        file = path.toRealPath().toString();
    } catch (IOException ex) {
        System.err.println("Error: Configuration file not found " + path.toString() + "\n");
        throw ex;
    }

    return file;
}