8194746: (fs) Add equivalents of Paths.get to Path interface

Copy Paths.get() methods to Path.get() methods and have former call latter

Reviewed-by: alanb, forax, chegar, psandoz
This commit is contained in:
Brian Burkhalter 2018-03-22 12:30:47 -07:00
parent 37f1b2b1e3
commit 9e3d8fd230
18 changed files with 174 additions and 119 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -103,8 +103,8 @@ public class LinuxFileSystemProvider extends UnixFileSystemProvider {
@Override @Override
FileTypeDetector getFileTypeDetector() { FileTypeDetector getFileTypeDetector() {
String userHome = GetPropertyAction.privilegedGetProperty("user.home"); String userHome = GetPropertyAction.privilegedGetProperty("user.home");
Path userMimeTypes = Paths.get(userHome, ".mime.types"); Path userMimeTypes = Path.of(userHome, ".mime.types");
Path etcMimeTypes = Paths.get("/etc/mime.types"); Path etcMimeTypes = Path.of("/etc/mime.types");
return chain(new MimeTypesFileTypeDetector(userMimeTypes), return chain(new MimeTypesFileTypeDetector(userMimeTypes),
new MimeTypesFileTypeDetector(etcMimeTypes)); new MimeTypesFileTypeDetector(etcMimeTypes));

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -26,7 +26,6 @@
package sun.nio.fs; package sun.nio.fs;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.spi.FileTypeDetector; import java.nio.file.spi.FileTypeDetector;
import sun.security.action.GetPropertyAction; import sun.security.action.GetPropertyAction;
@ -46,7 +45,7 @@ public class MacOSXFileSystemProvider extends BsdFileSystemProvider {
@Override @Override
FileTypeDetector getFileTypeDetector() { FileTypeDetector getFileTypeDetector() {
Path userMimeTypes = Paths.get(GetPropertyAction Path userMimeTypes = Path.of(GetPropertyAction
.privilegedGetProperty("user.home"), ".mime.types"); .privilegedGetProperty("user.home"), ".mime.types");
return chain(new MimeTypesFileTypeDetector(userMimeTypes), return chain(new MimeTypesFileTypeDetector(userMimeTypes),

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -30,7 +30,6 @@ import java.io.FilePermission;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.InvalidPathException; import java.nio.file.InvalidPathException;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.AccessController; import java.security.AccessController;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import java.util.Objects; import java.util.Objects;
@ -63,7 +62,7 @@ final class ProxyClassesDumper {
} }
try { try {
path = path.trim(); path = path.trim();
final Path dir = Paths.get(path.length() == 0 ? "." : path); final Path dir = Path.of(path.length() == 0 ? "." : path);
AccessController.doPrivileged(new PrivilegedAction<>() { AccessController.doPrivileged(new PrivilegedAction<>() {
@Override @Override
public Void run() { public Void run() {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -34,7 +34,6 @@ import java.lang.reflect.Array;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
@ -346,11 +345,11 @@ class ProxyGenerator {
int i = name.lastIndexOf('.'); int i = name.lastIndexOf('.');
Path path; Path path;
if (i > 0) { if (i > 0) {
Path dir = Paths.get(name.substring(0, i).replace('.', File.separatorChar)); Path dir = Path.of(name.substring(0, i).replace('.', File.separatorChar));
Files.createDirectories(dir); Files.createDirectories(dir);
path = dir.resolve(name.substring(i+1, name.length()) + ".class"); path = dir.resolve(name.substring(i+1, name.length()) + ".class");
} else { } else {
path = Paths.get(name + ".class"); path = Path.of(name + ".class");
} }
Files.write(path, classFile); Files.write(path, classFile);
return null; return null;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -28,6 +28,7 @@ package java.nio.file;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.nio.file.spi.FileSystemProvider;
import java.util.Iterator; import java.util.Iterator;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
@ -93,12 +94,124 @@ import java.util.NoSuchElementException;
* multiple concurrent threads. * multiple concurrent threads.
* *
* @since 1.7 * @since 1.7
* @see Paths
*/ */
public interface Path public interface Path
extends Comparable<Path>, Iterable<Path>, Watchable extends Comparable<Path>, Iterable<Path>, Watchable
{ {
/**
* Returns a {@code Path} by converting a path string, or a sequence of
* strings that when joined form a path string. If {@code more} does not
* specify any elements then the value of the {@code first} parameter is
* the path string to convert. If {@code more} specifies one or more
* elements then each non-empty string, including {@code first}, is
* considered to be a sequence of name elements and is joined to form a
* path string. The details as to how the Strings are joined is provider
* specific but typically they will be joined using the
* {@link FileSystem#getSeparator name-separator} as the separator.
* For example, if the name separator is "{@code /}" and
* {@code getPath("/foo","bar","gus")} is invoked, then the path string
* {@code "/foo/bar/gus"} is converted to a {@code Path}. A {@code Path}
* representing an empty path is returned if {@code first} is the empty
* string and {@code more} does not contain any non-empty strings.
*
* <p> The {@code Path} is obtained by invoking the {@link FileSystem#getPath
* getPath} method of the {@link FileSystems#getDefault default} {@link
* FileSystem}.
*
* <p> Note that while this method is very convenient, using it will imply
* an assumed reference to the default {@code FileSystem} and limit the
* utility of the calling code. Hence it should not be used in library code
* intended for flexible reuse. A more flexible alternative is to use an
* existing {@code Path} instance as an anchor, such as:
* <pre>{@code
* Path dir = ...
* Path path = dir.resolve("file");
* }</pre>
*
* @param first
* the path string or initial part of the path string
* @param more
* additional strings to be joined to form the path string
*
* @return the resulting {@code Path}
*
* @throws InvalidPathException
* if the path string cannot be converted to a {@code Path}
*
* @see FileSystem#getPath
*
* @since 11
*/
public static Path of(String first, String... more) {
return FileSystems.getDefault().getPath(first, more);
}
/**
* Returns a {@code Path} by converting a URI.
*
* <p> This method iterates over the {@link FileSystemProvider#installedProviders()
* installed} providers to locate the provider that is identified by the
* URI {@link URI#getScheme scheme} of the given URI. URI schemes are
* compared without regard to case. If the provider is found then its {@link
* FileSystemProvider#getPath getPath} method is invoked to convert the
* URI.
*
* <p> In the case of the default provider, identified by the URI scheme
* "file", the given URI has a non-empty path component, and undefined query
* and fragment components. Whether the authority component may be present
* is platform specific. The returned {@code Path} is associated with the
* {@link FileSystems#getDefault default} file system.
*
* <p> The default provider provides a similar <em>round-trip</em> guarantee
* to the {@link java.io.File} class. For a given {@code Path} <i>p</i> it
* is guaranteed that
* <blockquote>{@code
* Path.of(}<i>p</i>{@code .}{@link Path#toUri() toUri}{@code ()).equals(}
* <i>p</i>{@code .}{@link Path#toAbsolutePath() toAbsolutePath}{@code ())}
* </blockquote>
* so long as the original {@code Path}, the {@code URI}, and the new {@code
* Path} are all created in (possibly different invocations of) the same
* Java virtual machine. Whether other providers make any guarantees is
* provider specific and therefore unspecified.
*
* @param uri
* the URI to convert
*
* @return the resulting {@code Path}
*
* @throws IllegalArgumentException
* if preconditions on the {@code uri} parameter do not hold. The
* format of the URI is provider specific.
* @throws FileSystemNotFoundException
* The file system, identified by the URI, does not exist and
* cannot be created automatically, or the provider identified by
* the URI's scheme component is not installed
* @throws SecurityException
* if a security manager is installed and it denies an unspecified
* permission to access the file system
*
* @since 11
*/
public static Path of(URI uri) {
String scheme = uri.getScheme();
if (scheme == null)
throw new IllegalArgumentException("Missing scheme");
// check for default provider to avoid loading of installed providers
if (scheme.equalsIgnoreCase("file"))
return FileSystems.getDefault().provider().getPath(uri);
// try to find provider
for (FileSystemProvider provider: FileSystemProvider.installedProviders()) {
if (provider.getScheme().equalsIgnoreCase(scheme)) {
return provider.getPath(uri);
}
}
throw new FileSystemNotFoundException("Provider \"" + scheme + "\" not installed");
}
/** /**
* Returns the file system that created this object. * Returns the file system that created this object.
* *
@ -527,7 +640,7 @@ public interface Path
* to the {@link java.io.File} class. For a given {@code Path} <i>p</i> it * to the {@link java.io.File} class. For a given {@code Path} <i>p</i> it
* is guaranteed that * is guaranteed that
* <blockquote> * <blockquote>
* {@link Paths#get(URI) Paths.get}{@code (}<i>p</i>{@code .toUri()).equals(}<i>p</i> * {@link Path#of(URI) Path.of}{@code (}<i>p</i>{@code .toUri()).equals(}<i>p</i>
* {@code .}{@link #toAbsolutePath() toAbsolutePath}{@code ())} * {@code .}{@link #toAbsolutePath() toAbsolutePath}{@code ())}
* </blockquote> * </blockquote>
* so long as the original {@code Path}, the {@code URI}, and the new {@code * so long as the original {@code Path}, the {@code URI}, and the new {@code

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -32,7 +32,13 @@ import java.net.URI;
* This class consists exclusively of static methods that return a {@link Path} * This class consists exclusively of static methods that return a {@link Path}
* by converting a path string or {@link URI}. * by converting a path string or {@link URI}.
* *
* @apiNote
* It is recommended to obtain a {@code Path} via the {@code Path.of} methods
* instead of via the {@code get} methods defined in this class as this class
* may be deprecated in a future release.
*
* @since 1.7 * @since 1.7
* @see Path
*/ */
public final class Paths { public final class Paths {
@ -40,33 +46,11 @@ public final class Paths {
/** /**
* Converts a path string, or a sequence of strings that when joined form * Converts a path string, or a sequence of strings that when joined form
* a path string, to a {@code Path}. If {@code more} does not specify any * a path string, to a {@code Path}.
* elements then the value of the {@code first} parameter is the path string
* to convert. If {@code more} specifies one or more elements then each
* non-empty string, including {@code first}, is considered to be a sequence
* of name elements (see {@link Path}) and is joined to form a path string.
* The details as to how the Strings are joined is provider specific but
* typically they will be joined using the {@link FileSystem#getSeparator
* name-separator} as the separator. For example, if the name separator is
* "{@code /}" and {@code getPath("/foo","bar","gus")} is invoked, then the
* path string {@code "/foo/bar/gus"} is converted to a {@code Path}.
* A {@code Path} representing an empty path is returned if {@code first}
* is the empty string and {@code more} does not contain any non-empty
* strings.
* *
* <p> The {@code Path} is obtained by invoking the {@link FileSystem#getPath * @implSpec
* getPath} method of the {@link FileSystems#getDefault default} {@link * This method simply invokes {@link Path#of(String,String...)
* FileSystem}. * Path.of(String, String...)} with the given parameters.
*
* <p> Note that while this method is very convenient, using it will imply
* an assumed reference to the default {@code FileSystem} and limit the
* utility of the calling code. Hence it should not be used in library code
* intended for flexible reuse. A more flexible alternative is to use an
* existing {@code Path} instance as an anchor, such as:
* <pre>
* Path dir = ...
* Path path = dir.resolve("file");
* </pre>
* *
* @param first * @param first
* the path string or initial part of the path string * the path string or initial part of the path string
@ -79,38 +63,17 @@ public final class Paths {
* if the path string cannot be converted to a {@code Path} * if the path string cannot be converted to a {@code Path}
* *
* @see FileSystem#getPath * @see FileSystem#getPath
* @see Path#of(String,String...)
*/ */
public static Path get(String first, String... more) { public static Path get(String first, String... more) {
return FileSystems.getDefault().getPath(first, more); return Path.of(first, more);
} }
/** /**
* Converts the given URI to a {@link Path} object. * Converts the given URI to a {@link Path} object.
* *
* <p> This method iterates over the {@link FileSystemProvider#installedProviders() * @implSpec
* installed} providers to locate the provider that is identified by the * This method simply invokes {@link Path#of(URI) * Path.of(URI)} with the given parameter.
* URI {@link URI#getScheme scheme} of the given URI. URI schemes are
* compared without regard to case. If the provider is found then its {@link
* FileSystemProvider#getPath getPath} method is invoked to convert the
* URI.
*
* <p> In the case of the default provider, identified by the URI scheme
* "file", the given URI has a non-empty path component, and undefined query
* and fragment components. Whether the authority component may be present
* is platform specific. The returned {@code Path} is associated with the
* {@link FileSystems#getDefault default} file system.
*
* <p> The default provider provides a similar <em>round-trip</em> guarantee
* to the {@link java.io.File} class. For a given {@code Path} <i>p</i> it
* is guaranteed that
* <blockquote>{@code
* Paths.get(}<i>p</i>{@code .}{@link Path#toUri() toUri}{@code ()).equals(}
* <i>p</i>{@code .}{@link Path#toAbsolutePath() toAbsolutePath}{@code ())}
* </blockquote>
* so long as the original {@code Path}, the {@code URI}, and the new {@code
* Path} are all created in (possibly different invocations of) the same
* Java virtual machine. Whether other providers make any guarantees is
* provider specific and therefore unspecified.
* *
* @param uri * @param uri
* the URI to convert * the URI to convert
@ -127,23 +90,10 @@ public final class Paths {
* @throws SecurityException * @throws SecurityException
* if a security manager is installed and it denies an unspecified * if a security manager is installed and it denies an unspecified
* permission to access the file system * permission to access the file system
*
* @see Path#of(URI)
*/ */
public static Path get(URI uri) { public static Path get(URI uri) {
String scheme = uri.getScheme(); return Path.of(uri);
if (scheme == null)
throw new IllegalArgumentException("Missing scheme");
// check for default provider to avoid loading of installed providers
if (scheme.equalsIgnoreCase("file"))
return FileSystems.getDefault().provider().getPath(uri);
// try to find provider
for (FileSystemProvider provider: FileSystemProvider.installedProviders()) {
if (provider.getScheme().equalsIgnoreCase(scheme)) {
return provider.getPath(uri);
}
}
throw new FileSystemNotFoundException("Provider \"" + scheme + "\" not installed");
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -46,7 +46,7 @@ class TempFileHelper {
// temporary directory location // temporary directory location
private static final Path tmpdir = private static final Path tmpdir =
Paths.get(GetPropertyAction.privilegedGetProperty("java.io.tmpdir")); Path.of(GetPropertyAction.privilegedGetProperty("java.io.tmpdir"));
private static final boolean isPosix = private static final boolean isPosix =
FileSystems.getDefault().supportedFileAttributeViews().contains("posix"); FileSystems.getDefault().supportedFileAttributeViews().contains("posix");

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -2897,7 +2897,7 @@ public final class Scanner implements Iterator<String>, Closeable {
* letters: * letters:
* *
* <pre>{@code * <pre>{@code
* try (Scanner sc = new Scanner(Paths.get("input.txt"))) { * try (Scanner sc = new Scanner(Path.of("input.txt"))) {
* Pattern pat = Pattern.compile("[A-Z]{7,}"); * Pattern pat = Pattern.compile("[A-Z]{7,}");
* List<String> capWords = sc.findAll(pat) * List<String> capWords = sc.findAll(pat)
* .map(MatchResult::group) * .map(MatchResult::group)

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -32,7 +32,6 @@ import java.net.URI;
import java.net.URL; import java.net.URL;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.AccessController; import java.security.AccessController;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import java.util.Arrays; import java.util.Arrays;
@ -243,8 +242,8 @@ public class BootLoader {
mn = location.substring(5, location.length()); mn = location.substring(5, location.length());
} else if (location.startsWith("file:/")) { } else if (location.startsWith("file:/")) {
// named module in exploded image // named module in exploded image
Path path = Paths.get(URI.create(location)); Path path = Path.of(URI.create(location));
Path modulesDir = Paths.get(JAVA_HOME, "modules"); Path modulesDir = Path.of(JAVA_HOME, "modules");
if (path.startsWith(modulesDir)) { if (path.startsWith(modulesDir)) {
mn = path.getFileName().toString(); mn = path.getFileName().toString();
} }
@ -267,7 +266,7 @@ public class BootLoader {
private static URL toFileURL(String location) { private static URL toFileURL(String location) {
return AccessController.doPrivileged(new PrivilegedAction<>() { return AccessController.doPrivileged(new PrivilegedAction<>() {
public URL run() { public URL run() {
Path path = Paths.get(location); Path path = Path.of(location);
if (Files.isRegularFile(path)) { if (Files.isRegularFile(path)) {
try { try {
return path.toUri().toURL(); return path.toUri().toURL();
@ -285,7 +284,7 @@ public class BootLoader {
private static Manifest getManifest(String location) { private static Manifest getManifest(String location) {
return AccessController.doPrivileged(new PrivilegedAction<>() { return AccessController.doPrivileged(new PrivilegedAction<>() {
public Manifest run() { public Manifest run() {
Path jar = Paths.get(location); Path jar = Path.of(location);
try (InputStream in = Files.newInputStream(jar); try (InputStream in = Files.newInputStream(jar);
JarInputStream jis = new JarInputStream(in, false)) { JarInputStream jis = new JarInputStream(in, false)) {
return jis.getManifest(); return jis.getManifest();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -28,7 +28,7 @@ package jdk.internal.loader;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.nio.file.InvalidPathException; import java.nio.file.InvalidPathException;
import java.nio.file.Paths; import java.nio.file.Path;
import java.security.CodeSource; import java.security.CodeSource;
import java.security.PermissionCollection; import java.security.PermissionCollection;
import java.util.jar.Manifest; import java.util.jar.Manifest;
@ -223,7 +223,7 @@ public class ClassLoaders {
// Use an intermediate File object to construct a URI/URL without // Use an intermediate File object to construct a URI/URL without
// authority component as URLClassPath can't handle URLs with a UNC // authority component as URLClassPath can't handle URLs with a UNC
// server name in the authority component. // server name in the authority component.
return Paths.get(s).toRealPath().toFile().toURI().toURL(); return Path.of(s).toRealPath().toFile().toURI().toURL();
} catch (InvalidPathException | IOException ignore) { } catch (InvalidPathException | IOException ignore) {
// malformed path string or class path element does not exist // malformed path string or class path element does not exist
return null; return null;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -34,7 +34,6 @@ import java.lang.module.ModuleReference;
import java.lang.module.ResolvedModule; import java.lang.module.ResolvedModule;
import java.net.URI; import java.net.URI;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
@ -539,7 +538,7 @@ public final class ModuleBootstrap {
Path[] paths = new Path[dirs.length]; Path[] paths = new Path[dirs.length];
int i = 0; int i = 0;
for (String dir: dirs) { for (String dir: dirs) {
paths[i++] = Paths.get(dir); paths[i++] = Path.of(dir);
} }
return ModulePath.of(patcher, paths); return ModulePath.of(patcher, paths);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -30,7 +30,6 @@ import java.lang.module.Configuration;
import java.lang.module.ResolvedModule; import java.lang.module.ResolvedModule;
import java.net.URI; import java.net.URI;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayDeque; import java.util.ArrayDeque;
import java.util.Collections; import java.util.Collections;
import java.util.Deque; import java.util.Deque;
@ -129,7 +128,7 @@ public class ModuleHashesBuilder {
() -> new InternalError("Selected module " + name + " not on module path")); () -> new InternalError("Selected module " + name + " not on module path"));
URI uri = rm.reference().location().get(); URI uri = rm.reference().location().get();
Path path = Paths.get(uri); Path path = Path.of(uri);
String fn = path.getFileName().toString(); String fn = path.getFileName().toString();
if (!fn.endsWith(".jar") && !fn.endsWith(".jmod")) { if (!fn.endsWith(".jar") && !fn.endsWith(".jmod")) {
throw new UnsupportedOperationException(path + " is not a modular JAR or jmod file"); throw new UnsupportedOperationException(path + " is not a modular JAR or jmod file");

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -43,7 +43,6 @@ import java.nio.file.DirectoryStream;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.NoSuchFileException; import java.nio.file.NoSuchFileException;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -360,7 +359,7 @@ public class ModulePath implements ModuleFinder {
URI uri = mref.location().orElse(null); URI uri = mref.location().orElse(null);
if (uri != null) { if (uri != null) {
if (uri.getScheme().equalsIgnoreCase("file")) { if (uri.getScheme().equalsIgnoreCase("file")) {
Path file = Paths.get(uri); Path file = Path.of(uri);
return file.getFileName().toString(); return file.getFileName().toString();
} else { } else {
return uri.toString(); return uri.toString();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -38,7 +38,6 @@ import java.net.URLConnection;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.AccessController; import java.security.AccessController;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import java.util.ArrayDeque; import java.util.ArrayDeque;
@ -185,7 +184,7 @@ public final class SystemModuleFinders {
// probe to see if this is an images build // probe to see if this is an images build
String home = System.getProperty("java.home"); String home = System.getProperty("java.home");
Path modules = Paths.get(home, "lib", "modules"); Path modules = Path.of(home, "lib", "modules");
if (Files.isRegularFile(modules)) { if (Files.isRegularFile(modules)) {
if (USE_FAST_PATH) { if (USE_FAST_PATH) {
SystemModules systemModules = allSystemModules(); SystemModules systemModules = allSystemModules();
@ -205,7 +204,7 @@ public final class SystemModuleFinders {
} }
// exploded build (do not cache module finder) // exploded build (do not cache module finder)
Path dir = Paths.get(home, "modules"); Path dir = Path.of(home, "modules");
if (!Files.isDirectory(dir)) if (!Files.isDirectory(dir))
throw new InternalError("Unable to detect the run-time image"); throw new InternalError("Unable to detect the run-time image");
ModuleFinder f = ModulePath.of(ModuleBootstrap.patcher(), dir); ModuleFinder f = ModulePath.of(ModuleBootstrap.patcher(), dir);

View File

@ -30,7 +30,7 @@ import java.lang.reflect.*;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.net.URI; import java.net.URI;
import java.nio.file.Paths; import java.nio.file.Path;
import java.util.*; import java.util.*;
import java.security.*; import java.security.*;
import java.security.cert.Certificate; import java.security.cert.Certificate;
@ -278,7 +278,7 @@ public class PolicyFile extends java.security.Policy {
public URL run() { public URL run() {
String sep = File.separator; String sep = File.separator;
try { try {
return Paths.get(System.getProperty("java.home"), return Path.of(System.getProperty("java.home"),
"lib", "security", "lib", "security",
"default.policy").toUri().toURL(); "default.policy").toUri().toURL();
} catch (MalformedURLException mue) { } catch (MalformedURLException mue) {

View File

@ -27,7 +27,7 @@ package sun.security.tools.keytool;
import java.io.*; import java.io.*;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Path;
import java.security.CodeSigner; import java.security.CodeSigner;
import java.security.CryptoPrimitive; import java.security.CryptoPrimitive;
import java.security.KeyStore; import java.security.KeyStore;
@ -2189,7 +2189,7 @@ public final class Main {
inplaceBackupName = srcksfname + ".old" + (n == 1 ? "" : n); inplaceBackupName = srcksfname + ".old" + (n == 1 ? "" : n);
File bkFile = new File(inplaceBackupName); File bkFile = new File(inplaceBackupName);
if (!bkFile.exists()) { if (!bkFile.exists()) {
Files.copy(Paths.get(srcksfname), bkFile.toPath()); Files.copy(Path.of(srcksfname), bkFile.toPath());
break; break;
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -84,9 +84,9 @@ public class SolarisFileSystemProvider extends UnixFileSystemProvider {
@Override @Override
FileTypeDetector getFileTypeDetector() { FileTypeDetector getFileTypeDetector() {
Path userMimeTypes = Paths.get( Path userMimeTypes = Path.of(
GetPropertyAction.privilegedGetProperty("user.home"), ".mime.types"); GetPropertyAction.privilegedGetProperty("user.home"), ".mime.types");
Path etcMimeTypes = Paths.get("/etc/mime.types"); Path etcMimeTypes = Path.of("/etc/mime.types");
return chain(new MimeTypesFileTypeDetector(userMimeTypes), return chain(new MimeTypesFileTypeDetector(userMimeTypes),
new MimeTypesFileTypeDetector(etcMimeTypes)); new MimeTypesFileTypeDetector(etcMimeTypes));

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -260,7 +260,7 @@ abstract class UnixFileStore
private static Properties loadProperties() { private static Properties loadProperties() {
Properties result = new Properties(); Properties result = new Properties();
String fstypes = System.getProperty("java.home") + "/lib/fstypes.properties"; String fstypes = System.getProperty("java.home") + "/lib/fstypes.properties";
Path file = Paths.get(fstypes); Path file = Path.of(fstypes);
try { try {
try (ReadableByteChannel rbc = Files.newByteChannel(file)) { try (ReadableByteChannel rbc = Files.newByteChannel(file)) {
result.load(Channels.newReader(rbc, "UTF-8")); result.load(Channels.newReader(rbc, "UTF-8"));