Refine search
/** * Create a new PathResource from a Path handle. * <p>Note: Unlike {@link FileSystemResource}, when building relative resources * via {@link #createRelative}, the relative path will be built <i>underneath</i> * the given root: e.g. Paths.get("C:/dir1/"), relative path "dir2" -> "C:/dir1/dir2"! * @param uri a path URI * @see java.nio.file.Paths#get(URI) */ public PathResource(URI uri) { Assert.notNull(uri, "URI must not be null"); this.path = Paths.get(uri).normalize(); }
Path normalizedAbsolutePath = path.toAbsolutePath().normalize(); Path parent = normalizedAbsolutePath.getParent(); if (parent == null) {
private static String getKitInstallationPath(String diskPrefix) { String basedir = diskPrefix + "build/ehcache-kit"; if(!new File(basedir).exists()) { return null; } try { return Files.list(Paths.get(basedir)) .sorted(Comparator.<Path>naturalOrder().reversed()) // the last one should be the one with the highest version .findFirst() .map(path -> path.toAbsolutePath().normalize().toString()) .orElse(null); } catch (IOException e) { fail("Failed to set kitInstallationPath from " + basedir, e); return null; } } }
final Path urlPath = Paths.get( url.toURI() ); final Path rootPath = root.toPath().normalize().toAbsolutePath(); rootPath.resolve( urlPath.getRoot().relativize( urlPath ) ).normalize().toAbsolutePath();
protected static String calculateDefaultOutputDirectory(Path currentPath) { Path currentAbsolutePath = currentPath.toAbsolutePath(); Path parent = currentAbsolutePath.getParent(); if (currentAbsolutePath.getRoot().equals(parent)) { return parent.toString(); } else { Path currentNormalizedPath = currentAbsolutePath.normalize(); return "../" + currentNormalizedPath.getFileName().toString(); } }
/** * Similar to {@link Path#relativize(Path)} except that: * <ul> * <li>null is returned if file is not a child of dir * <li>the resulting path is converted to use Unix separators * </ul> * @since 6.0 */ @CheckForNull public String relativePath(Path dir, Path file) { Path baseDir = dir.normalize(); Path path = file.normalize(); if (!path.startsWith(baseDir)) { return null; } try { Path relativized = baseDir.relativize(path); return FilenameUtils.separatorsToUnix(relativized.toString()); } catch (IllegalArgumentException e) { return null; } }
String cacertsFilepath = ConfigUtils .getString(config, ElasticsearchWriterConfigurationKeys.ELASTICSEARCH_WRITER_SSL_TRUSTSTORE_LOCATION, ""); String truststoreAbsolutePath = Paths.get(cacertsFilepath).toAbsolutePath().normalize().toString(); log.info("Truststore absolutePath is:" + truststoreAbsolutePath);
/** * Create a new PathResource from a Path handle. * <p>Note: Unlike {@link FileSystemResource}, when building relative resources * via {@link #createRelative}, the relative path will be built <i>underneath</i> * the given root: e.g. Paths.get("C:/dir1/"), relative path "dir2" -> "C:/dir1/dir2"! * @param path a path * @see java.nio.file.Paths#get(String, String...) */ public PathResource(String path) { Assert.notNull(path, "Path must not be null"); this.path = Paths.get(path).normalize(); }
/** * Constructs a normalized relative path between base directory and a given path. * * @param baseDirectory * the base path to which given path is relativized * @param path * the path to relativize against base directory * @return the relative normalized path between base directory and * path or path if base directory is null. */ public static String relativizeAndNormalizePath(final String baseDirectory, final String path) { final String resultPath; if (baseDirectory == null) { resultPath = path; } else { final Path pathAbsolute = Paths.get(path).normalize(); final Path pathBase = Paths.get(baseDirectory).normalize(); resultPath = pathBase.relativize(pathAbsolute).toString(); } return resultPath; }
private char driveLetterOf(final String windowsPath) { if (windowsPath != null && windowsPath.length() > 0) { final Path normalisedPath = Paths.get(windowsPath).normalize().toAbsolutePath(); return normalisedPath.toFile().toString().charAt(0); } return '?'; }
Path directChild = this.getDirectChild(currentFilePath, remainingPath); Path childUsingFullPath = currentFilePath.resolve(remainingPath); String childUsingFullPathAbs = childUsingFullPath.toAbsolutePath().toString(); String directChildAbs = directChild.toAbsolutePath().toString(); Path currentFileAbsolutePath = currentFilePath.toAbsolutePath(); try{ Path child = currentFileAbsolutePath.toRealPath(); Path child = currentFileAbsolutePath.normalize(); Path parent = parentAbsolutePath.normalize(); return child.startsWith(parent);
/** * Similar to {@link Path#relativize(Path)} except that: * <ul> * <li>Empty is returned if file is not a child of dir * <li>the resulting path is converted to use Unix separators * </ul> * @since 6.6 */ public static Optional<String> relativize(Path dir, Path file) { Path baseDir = dir.normalize(); Path path = file.normalize(); if (!path.startsWith(baseDir)) { return Optional.empty(); } try { Path relativized = baseDir.relativize(path); return Optional.of(FilenameUtils.separatorsToUnix(relativized.toString())); } catch (IllegalArgumentException e) { return Optional.empty(); } }
/** * Write content to file. * * @param path Target file. * @param sequence File content. * @throws IOException If something goes wrong. */ private void write(final Path path, final List<CharSequence> sequence) throws IOException { log.debug("writing: {}", path.normalize().toAbsolutePath()); path.toFile().getParentFile().mkdirs(); Files.write(path, sequence); }
@Nullable private InputSource loadFromLocalFile(final URI systemIdUrl) throws IOException { File file = new File(systemIdUrl.getPath()); if (file.exists()) { return sourceFromFile(file.getAbsolutePath()); } String normalisedFilePath = Paths.get(systemIdUrl).normalize().toAbsolutePath().toString(); String cwd = System.getProperties().getProperty("user.dir"); if (normalisedFilePath.startsWith(cwd)) { String relativePath = normalisedFilePath.substring(cwd.length() + 1); final String resolvedFile = configurationLocation.resolveAssociatedFile(relativePath, null, checkstyleClassLoader); if (resolvedFile != null) { return sourceFromFile(resolvedFile); } } return null; }
/** * Create a new PathResource from a Path handle. * <p>Note: Unlike {@link FileSystemResource}, when building relative resources * via {@link #createRelative}, the relative path will be built <i>underneath</i> * the given root: e.g. Paths.get("C:/dir1/"), relative path "dir2" -> "C:/dir1/dir2"! * @param path a path * @see java.nio.file.Paths#get(String, String...) */ public PathResource(String path) { Assert.notNull(path, "Path must not be null"); this.path = Paths.get(path).normalize(); }
public JavapProcess() throws FileNotFoundException { super(); Path javaHome = Paths.get(System.getProperty("java.home")); executablePath = Paths.get(javaHome.toString(), "..", "bin", EXECUTABLE_NAME); if (!executablePath.toFile().exists()) { executablePath = Paths.get(javaHome.toString(), "bin", EXECUTABLE_NAME); if (!executablePath.toFile().exists()) { throw new FileNotFoundException("Could not find " + EXECUTABLE_NAME); } } executablePath = executablePath.normalize(); }
private File projectRelativeFileOf(final String filename) { return Paths.get(new File(project.getBasePath(), filename).getAbsolutePath()) .normalize() .toAbsolutePath() .toFile(); }
private PathResourceManager(Builder builder) { this.allowResourceChangeListeners = builder.allowResourceChangeListeners; if (builder.base == null) { throw UndertowMessages.MESSAGES.argumentCannotBeNull("base"); } this.fileSystem = builder.base.getFileSystem(); String basePath = builder.base.normalize().toAbsolutePath().toString(); if (!basePath.endsWith(fileSystem.getSeparator())) { basePath = basePath + fileSystem.getSeparator(); } this.base = basePath; this.transferMinSize = builder.transferMinSize; this.caseSensitive = builder.caseSensitive; this.followLinks = builder.followLinks; if (this.followLinks) { if (builder.safePaths == null) { throw UndertowMessages.MESSAGES.argumentCannotBeNull("safePaths"); } for (final String safePath : builder.safePaths) { if (safePath == null) { throw UndertowMessages.MESSAGES.argumentCannotBeNull("safePaths"); } } this.safePaths.addAll(Arrays.asList(builder.safePaths)); } this.eTagFunction = builder.eTagFunction; }