本文整理了Java中java.nio.file.Path.normalize()
方法的一些代码示例,展示了Path.normalize()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Path.normalize()
方法的具体详情如下:
包路径:java.nio.file.Path
类名称:Path
方法名:normalize
暂无
代码示例来源:origin: spring-projects/spring-framework
/**
* 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();
}
代码示例来源:origin: google/guava
Path normalizedAbsolutePath = path.toAbsolutePath().normalize();
Path parent = normalizedAbsolutePath.getParent();
if (parent == null) {
代码示例来源:origin: syncany/syncany
private Path toAbsoluteNormalizedPath(String potentiallyRelativePathStr) {
Path filePath = Paths.get(potentiallyRelativePathStr);
if (!filePath.isAbsolute()) {
return Paths.get(root.toString(), filePath.toString()).normalize();
}
else {
return filePath.normalize();
}
}
代码示例来源:origin: ehcache/ehcache3
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;
}
}
}
代码示例来源:origin: neo4j/neo4j
final Path urlPath = Paths.get( url.toURI() );
final Path rootPath = root.toPath().normalize().toAbsolutePath();
rootPath.resolve( urlPath.getRoot().relativize( urlPath ) ).normalize().toAbsolutePath();
代码示例来源:origin: apache/nifi
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();
}
}
代码示例来源:origin: SonarSource/sonarqube
/**
* 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;
}
}
代码示例来源:origin: apache/incubator-gobblin
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);
代码示例来源:origin: spring-projects/spring-framework
/**
* 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();
}
代码示例来源:origin: checkstyle/checkstyle
/**
* 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;
}
代码示例来源:origin: jshiell/checkstyle-idea
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 '?';
}
代码示例来源:origin: jenkinsci/jenkins
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);
代码示例来源:origin: SonarSource/sonarqube
/**
* 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();
}
}
代码示例来源:origin: jooby-project/jooby
/**
* 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);
}
代码示例来源:origin: jshiell/checkstyle-idea
@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;
}
代码示例来源:origin: org.springframework/spring-core
/**
* 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();
}
代码示例来源:origin: AdoptOpenJDK/jitwatch
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();
}
代码示例来源:origin: jshiell/checkstyle-idea
private File projectRelativeFileOf(final String filename) {
return Paths.get(new File(project.getBasePath(), filename).getAbsolutePath())
.normalize()
.toAbsolutePath()
.toFile();
}
代码示例来源:origin: wildfly/wildfly
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;
}
代码示例来源:origin: apache/flink
if (!fileUpload.getFileName().toString().endsWith(".jar")) {
throw new CompletionException(new RestHandlerException(
"Only Jar files are allowed.",
.normalize()
.toString());
内容来源于网络,如有侵权,请联系作者删除!