List of usage examples for java.nio.file Path isAbsolute
boolean isAbsolute();
From source file:org.apache.archiva.repository.AbstractRepository.java
@Override public Path getLocalPath() { Path localPath; if (StringUtils.isEmpty(getLocation().getScheme()) || "file".equals(getLocation().getScheme())) { localPath = PathUtil.getPathFromUri(getLocation()); if (localPath.isAbsolute()) { return localPath; } else {//from w w w .jav a 2s . c o m return repositoryBase.resolve(localPath); } } else { return repositoryBase.resolve(getId()); } }
From source file:eumetsat.pn.common.ISO2JSON.java
public ISO2JSON(Path configFile) { log.debug("Initializing from {}", configFile); if (configFile.isAbsolute()) { try (InputStream fis = new FileInputStream(configFile.toFile())) { YamlNode n = new Yaml().load(fis); this.config = n.get(getConfigBasename()).get("feeder"); } catch (IOException e) { log.error("Could not load config from absolute file {}", configFile, e); }/*w w w.j a v a2 s . co m*/ } else { try (InputStream fis = ISO2JSON.class.getResourceAsStream("/" + configFile.toString())) { YamlNode n = new Yaml().load(fis); this.config = n.get(getConfigBasename()).get("feeder"); } catch (IOException e) { log.error("Could not load config from resource file {}", configFile, e); } } log.info("NEW {} based on {}", this.toString(), configFile); }
From source file:com.facebook.buck.util.unarchive.Untar.java
/** * Cleans up the destination for the symlink, and symlink file -> symlink target is recorded in * {@code windowsSymlinkMap}/*from w ww . j ava2 s .c o m*/ */ private void recordSymbolicLinkForWindows(DirectoryCreator creator, Path destPath, TarArchiveEntry entry, Map<Path, Path> windowsSymlinkMap) throws IOException { prepareForFile(creator, destPath); Path linkPath = Paths.get(entry.getLinkName()); if (destPath.isAbsolute()) { windowsSymlinkMap.put(destPath, linkPath); } else { // Symlink might be '../foo/Bar', so make sure we resolve relative to the src file // We make them relative to the file again when we write them out Path destinationRelativeTargetPath = destPath.getParent().resolve(linkPath).normalize(); windowsSymlinkMap.put(destPath, destinationRelativeTargetPath); } }
From source file:net.es.nsi.topology.translator.Options.java
/** * Processes the "configdir" command line and system property option. * @param cmd Commands entered by the user. * @param basedir The base directory for the application (install directory). * @return The configured configdir./*w w w. j ava 2s . co m*/ * @throws IOException */ private String getConfigdir(CommandLine cmd) throws IOException { String dir = System.getProperty(Properties.SYSTEM_PROPERTY_CONFIGDIR); dir = cmd.getOptionValue(ARGNAME_CONFIGDIR, dir); Path configPath; if (dir == null || dir.isEmpty()) { configPath = Paths.get(basedir, DEFAULT_CONFIGDIR); } else { configPath = Paths.get(dir); if (!configPath.isAbsolute()) { configPath = Paths.get(basedir, configPath.toString()); } } try { dir = configPath.toRealPath().toString(); } catch (IOException ex) { System.err.println("Error: Configuration directory not found " + dir + "\n"); throw ex; } return dir; }
From source file:com.netflix.nicobar.core.archive.JarScriptArchive.java
protected JarScriptArchive(ScriptModuleSpec moduleSpec, Path jarPath, String moduleSpecEntry, long createTime) throws IOException { this.createTime = createTime; this.moduleSpec = Objects.requireNonNull(moduleSpec, "moduleSpec"); Objects.requireNonNull(jarPath, "jarFile"); if (!jarPath.isAbsolute()) throw new IllegalArgumentException("jarPath must be absolute."); // initialize the index JarFile jarFile = new JarFile(jarPath.toFile()); Set<String> indexBuilder; try {/* w ww. ja v a 2s. c om*/ Enumeration<JarEntry> jarEntries = jarFile.entries(); indexBuilder = new HashSet<String>(); while (jarEntries.hasMoreElements()) { JarEntry jarEntry = jarEntries.nextElement(); // Skip adding moduleSpec to archive entries if (jarEntry.getName().equals(moduleSpecEntry)) { continue; } if (!jarEntry.isDirectory()) { indexBuilder.add(jarEntry.getName()); } } } finally { jarFile.close(); } entryNames = Collections.unmodifiableSet(indexBuilder); rootUrl = jarPath.toUri().toURL(); }
From source file:software.coolstuff.springframework.owncloud.service.impl.local.OwncloudLocalResourceServiceTest.java
private Path resolveRelativePath(Path relativePath) { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); ResourceServiceProperties resourceProperties = properties.getResourceService(); Path basePath = resourceProperties.getLocation().resolve(authentication.getName()); if (relativePath.isAbsolute()) { String relativizedPath = StringUtils.substring(relativePath.toString(), File.pathSeparator.length()); return basePath.resolve(relativizedPath); }// w ww.j ava2 s. c om return basePath.resolve(relativePath); }
From source file:org.codice.ddf.security.certificate.keystore.editor.KeystoreEditor.java
@Override public void deletePrivateKey(String alias) { LOGGER.info("Removing {} from System keystore.", alias); Path keyStoreFile = Paths.get(SecurityConstants.getKeystorePath()); if (!keyStoreFile.isAbsolute()) { Path ddfHomePath = Paths.get(System.getProperty("ddf.home")); keyStoreFile = Paths.get(ddfHomePath.toString(), keyStoreFile.toString()); }/*w ww . j a va2s . c om*/ String keyStorePassword = SecurityConstants.getKeystorePassword(); deleteFromStore(alias, keyStoreFile.toString(), keyStorePassword, keyStore); }
From source file:org.easyrec.utils.io.TreeCopy.java
/** * Resolve a path against another path with a potentially different * {@link FileSystem} or {@link FileSystemProvider} * * <p>{@link Path#resolve(Path)} will refuse to operate if its argument is * issued from a different provider (with a {@link * ProviderMismatchException}); moreover, if the argument is issued from the * same provider but is on a different filesystem, the result of the * resolution may be on the argument's filesystem, not the caller's.</p> * * <p>This method will attempt to resolve the second path against the first * so that the result is <em>always</em> associated to the filesystem (and * therefore provider) of the first argument. For the resolution to operate, * the following conditions must be met for {@code path2}:</p> * * <ul>// www . jav a 2 s . c o m * <li>if it is not absolute, it must not have a root;</li> * <li>if it is absolute, it must have a root, and the string * representation of this root must match a string representation of one * possible root of the first path's filesystem.</li> * </ul> * * <p>If the conditions above are not satisfied, this method throws an * {@link UnresolvablePathException} (unchecked).</p> * * <p>If both paths are issued from the same filesystem, this method will * delegate to {@code path1}'s {@code .resolve()}; if they are from * different filesystems but share the same provider, this method returns: * </p> * * <pre> * path1.resolve(path1.getFileSystem().getPath(path2.toString())) * </pre> * * <p>This means that for instance it is possible to resolve a Unix path * against a Windows path, or the reverse, as long as the second path is * not absolute (the root paths of both filesystems are incompatible):</p> * * <ul> * <li>resolving {@code foo/bar/baz} against {@code c:} will return * {@code c:\foo\bar\baz};</li> * <li>resolving {@code baz\quux} against {@code /foo/bar} will return * {@code /foo/bar/baz/quux}.</li> * </ul> * * @param path1 the first path * @param path2 the second path * @return the resolved path * @throws UnresolvablePathException see description * @throws InvalidPathException {@code path2} is from a different provider, * and one of its name elements is invalid according to {@code path1}'s * filesystem * * @see FileSystem#getPath(String, String...) * @see FileSystem#getRootDirectories() */ @SuppressWarnings("ObjectEquality") private Path resolve(final Path path1, final Path path2) throws IOException { final FileSystem fs1 = Objects.requireNonNull(path1).getFileSystem(); final FileSystem fs2 = Objects.requireNonNull(path2).getFileSystem(); if (fs1 == fs2) return path1.resolve(path2); if (fs1.provider() == fs2.provider()) return path1.resolve(fs1.getPath(path2.toString())); final boolean isAbsolute = path2.isAbsolute(); final Path root2 = path2.getRoot(); final String errmsg = isAbsolute ? "path to resolve is absolute but has no root" : "path to resolve is not absolute but has a root"; // Always tricky to read an xor... if (isAbsolute ^ root2 != null) throw new IOException(errmsg); Path ret; if (isAbsolute) { /* * Check if the root of path2 is compatible with path1 */ final String path2Root = root2.toString(); boolean foundRoot = false; for (final Path root1 : fs1.getRootDirectories()) if (root1.toString().equals(path2Root)) foundRoot = true; if (!foundRoot) throw new IOException("root of path to resolve " + "is incompatible with source path"); ret = fs1.getPath(path2Root); } else { /* * Since the empty path is defined as having one empty name * component, which is rather awkward, we don't want to take the * risk of triggering bugs in FileSystem#getPath(); instead, check * that the string representation of path2 is empty, and if it is, * just return path1. */ if (path2.toString().isEmpty()) return path1; ret = path1; } for (final Path element : path2) ret = ret.resolve(element.toString()); return ret; }
From source file:org.codice.ddf.security.certificate.keystore.editor.KeystoreEditor.java
@Override public void addPrivateKey(String alias, String keyPassword, String storePassword, String data, String type, String fileName) throws KeystoreEditorException { LOGGER.info("Adding alias {} to private key", alias); LOGGER.trace("Received data {}", data); Path keyStoreFile = Paths.get(SecurityConstants.getKeystorePath()); if (!keyStoreFile.isAbsolute()) { Path ddfHomePath = Paths.get(System.getProperty("ddf.home")); keyStoreFile = Paths.get(ddfHomePath.toString(), keyStoreFile.toString()); }/*from w w w . j a v a 2 s . co m*/ String keyStorePassword = SecurityConstants.getKeystorePassword(); addToStore(alias, keyPassword, storePassword, data, type, fileName, keyStoreFile.toString(), keyStorePassword, keyStore); }
From source file:org.codice.ddf.security.certificate.keystore.editor.KeystoreEditor.java
@Override public void deleteTrustedCertificate(String alias) { LOGGER.info("Removing {} from System truststore.", alias); Path trustStoreFile = Paths.get(SecurityConstants.getTruststorePath()); if (!trustStoreFile.isAbsolute()) { Path ddfHomePath = Paths.get(System.getProperty("ddf.home")); trustStoreFile = Paths.get(ddfHomePath.toString(), trustStoreFile.toString()); }//ww w. j a va 2 s . co m String trustStorePassword = SecurityConstants.getTruststorePassword(); deleteFromStore(alias, trustStoreFile.toString(), trustStorePassword, trustStore); }