public final class JkUtilsPath
extends java.lang.Object
Path
.
Mainly for wrapping checked exceptions and handle safely null parameters.Modifier and Type | Class and Description |
---|---|
static class |
JkUtilsPath.JkZipRoot
A container object representing both a zip file and its content.
|
Modifier and Type | Method and Description |
---|---|
static int |
childrenCount(java.nio.file.Path dir,
int max,
boolean includeDirectories,
java.nio.file.PathMatcher pathMatcher)
Returns the file count contained in the specified directory (recursively) to concurrence to specified max count.
|
static void |
copy(java.nio.file.Path source,
java.nio.file.Path target,
java.nio.file.CopyOption... copyOptions)
Delegates to
Files.copy(Path, Path, CopyOption...) wrapping checked exception. |
static int |
copyDirContent(java.nio.file.Path sourceDir,
java.nio.file.Path targetDir,
java.nio.file.PathMatcher pathMatcher,
java.nio.file.CopyOption... copyOptions)
Copies the content of the source directory into the target directory.
|
static void |
createDirectories(java.nio.file.Path path,
java.nio.file.attribute.FileAttribute<?>... attrs)
Delegates to
Files.createDirectories(Path, FileAttribute[]) wrapping checked exception. |
static void |
createFile(java.nio.file.Path path,
java.nio.file.attribute.FileAttribute<?>... attrs)
Delegates to
Files.createFile(Path, FileAttribute[]) s |
static void |
createFileSafely(java.nio.file.Path path,
java.nio.file.attribute.FileAttribute<?>... attrs)
Delegates to
Files.createFile(Path, FileAttribute[]) but checking first
if the specified file does not already exist. |
static java.nio.file.Path |
createTempDirectory(java.lang.String prefix,
java.nio.file.attribute.FileAttribute... fileAttributes)
Delegates to Files
createTempDirectory(String, FileAttribute[]) |
static java.nio.file.Path |
createTempFile(java.lang.String prefix,
java.lang.String extension,
java.nio.file.attribute.FileAttribute... fileAttributes)
Delegates to
Files.createTempFile(String, String, FileAttribute[]) |
static void |
deleteFile(java.nio.file.Path path)
Delegates to Files
deleteFile(Path) |
static void |
deleteIfExists(java.nio.file.Path path)
Delegates to Files
deleteIfExists(Path) |
static void |
deleteIfExistsSafely(java.nio.file.Path path)
Delegates to Files
deleteIfExists(Path) |
static void |
deleteQuietly(java.nio.file.Path path,
boolean ignoreDeleteError) |
static java.util.List<java.nio.file.Path> |
disambiguate(java.lang.Iterable<java.nio.file.Path> paths)
As
Path implements Iterable it is not obvious if an Iterable of Path was
intended to be a list of Path or a single Path . |
static java.nio.file.Path |
firstExisting(java.nio.file.Path... paths)
Returns the first specified path that exist.
|
static java.lang.String |
friendlyName(java.nio.file.Path path) |
static java.nio.file.Path |
get(java.net.URL url) |
static java.util.Optional<java.lang.Long> |
getLastModifiedTime(java.nio.file.Path path,
java.nio.file.LinkOption... options) |
static boolean |
isSameFile(java.nio.file.Path path1,
java.nio.file.Path path2)
Delegates to Files
isSameFile(Path, Path) |
static java.util.stream.Stream<java.lang.String> |
lines(java.nio.file.Path file,
java.nio.charset.Charset charset) |
static java.util.List<java.nio.file.Path> |
listDirectChildren(java.nio.file.Path path) |
static void |
move(java.nio.file.Path from,
java.nio.file.Path to,
java.nio.file.StandardCopyOption... options) |
static void |
moveDir(java.nio.file.Path source,
java.nio.file.Path target)
Move directory along all its children and subdirectories recursively
|
static java.nio.file.DirectoryStream<java.nio.file.Path> |
newDirectoryStream(java.nio.file.Path root,
java.nio.file.DirectoryStream.Filter<java.nio.file.Path> filter) |
static java.io.InputStream |
newInputStream(java.nio.file.Path path,
java.nio.file.OpenOption... openOptions) |
static byte[] |
readAllBytes(java.nio.file.Path path)
Delegates to
Files.readAllBytes(Path) (Path) |
static java.util.List<java.lang.String> |
readAllLines(java.nio.file.Path path)
Delegates to
Files.readAllLines(Path) |
static java.util.Properties |
readPropertyFile(java.nio.file.Path propertyFile)
Returns the content of the specified property file as a
Properties object. |
static java.nio.file.WatchKey |
register(java.nio.file.Path dir,
java.nio.file.WatchService watchService,
java.nio.file.WatchEvent.Kind<?>... watchEventKinds) |
static java.nio.file.Path |
relativizeFromDirIfAbsolute(java.nio.file.Path referent,
java.nio.file.Path pathToRelativize)
Returns the relative path to working dir of the specified path.
|
static java.nio.file.Path |
relativizeFromWorkingDir(java.nio.file.Path path)
Returns the relative path to working dir of the specified path.
|
static long |
size(java.nio.file.Path path) |
static java.util.List<java.io.File> |
toFiles(java.util.Collection<java.nio.file.Path> paths) |
static java.io.File[] |
toFiles(java.nio.file.Path... paths) |
static java.nio.file.Path[] |
toPaths(java.io.File... files) |
static java.util.List<java.nio.file.Path> |
toPaths(java.lang.Iterable<java.io.File> files) |
static java.net.URL |
toUrl(java.io.File file)
Get the url to the specified file.
|
static java.net.URL |
toUrl(java.nio.file.Path path)
Get the url to the specified path.
|
static java.util.stream.Stream<java.nio.file.Path> |
walk(java.nio.file.Path path,
java.nio.file.FileVisitOption... options) |
static java.util.stream.Stream<java.nio.file.Path> |
walk(java.nio.file.Path path,
int deep,
java.nio.file.FileVisitOption... options) |
static void |
walkFileTree(java.nio.file.Path path,
java.nio.file.FileVisitor<java.nio.file.Path> visitor) |
static void |
write(java.nio.file.Path path,
byte[] bytes,
java.nio.file.OpenOption... options)
Delegates to Files
write(Path, byte[], OpenOption...) |
static JkUtilsPath.JkZipRoot |
zipRoot(java.nio.file.Path zipFile) |
public static java.lang.String friendlyName(java.nio.file.Path path)
public static java.util.List<java.nio.file.Path> disambiguate(java.lang.Iterable<java.nio.file.Path> paths)
Path
implements Iterable
it is not obvious if an Iterable
of Path
was
intended to be a list of Path
or a single Path
.
This method helps by returning a list of Path containing either a single element if the argument was an instance
of Path
nor a list of elements contained in the iterable argument.paths
- public static java.nio.file.Path firstExisting(java.nio.file.Path... paths)
public static java.nio.file.Path get(java.net.URL url)
public static JkUtilsPath.JkZipRoot zipRoot(java.nio.file.Path zipFile)
public static void move(java.nio.file.Path from, java.nio.file.Path to, java.nio.file.StandardCopyOption... options)
Files.move(Path, Path, CopyOption...)
public static java.util.Properties readPropertyFile(java.nio.file.Path propertyFile)
Properties
object.public static java.net.URL toUrl(java.io.File file)
public static java.io.InputStream newInputStream(java.nio.file.Path path, java.nio.file.OpenOption... openOptions)
public static java.util.List<java.io.File> toFiles(java.util.Collection<java.nio.file.Path> paths)
public static java.io.File[] toFiles(java.nio.file.Path... paths)
public static java.nio.file.Path[] toPaths(java.io.File... files)
public static java.util.List<java.nio.file.Path> toPaths(java.lang.Iterable<java.io.File> files)
public static boolean isSameFile(java.nio.file.Path path1, java.nio.file.Path path2)
isSameFile(Path, Path)
public static java.nio.file.Path createTempFile(java.lang.String prefix, java.lang.String extension, java.nio.file.attribute.FileAttribute... fileAttributes)
Files.createTempFile(String, String, FileAttribute[])
public static java.util.List<java.lang.String> readAllLines(java.nio.file.Path path)
Files.readAllLines(Path)
public static java.util.stream.Stream<java.lang.String> lines(java.nio.file.Path file, java.nio.charset.Charset charset)
public static byte[] readAllBytes(java.nio.file.Path path)
Files.readAllBytes(Path)
(Path)public static void deleteQuietly(java.nio.file.Path path, boolean ignoreDeleteError)
public static void deleteFile(java.nio.file.Path path)
deleteFile(Path)
public static void deleteIfExists(java.nio.file.Path path)
deleteIfExists(Path)
public static void deleteIfExistsSafely(java.nio.file.Path path)
deleteIfExists(Path)
public static void createFile(java.nio.file.Path path, java.nio.file.attribute.FileAttribute<?>... attrs)
Files.createFile(Path, FileAttribute[])
spublic static void createFileSafely(java.nio.file.Path path, java.nio.file.attribute.FileAttribute<?>... attrs)
Files.createFile(Path, FileAttribute[])
but checking first
if the specified file does not already exist. If so, do nothing, else creates
parent directories if needed prior creating the file.public static void write(java.nio.file.Path path, byte[] bytes, java.nio.file.OpenOption... options)
write(Path, byte[], OpenOption...)
public static java.nio.file.Path createTempDirectory(java.lang.String prefix, java.nio.file.attribute.FileAttribute... fileAttributes)
createTempDirectory(String, FileAttribute[])
public static java.nio.file.DirectoryStream<java.nio.file.Path> newDirectoryStream(java.nio.file.Path root, java.nio.file.DirectoryStream.Filter<java.nio.file.Path> filter)
public static java.util.List<java.nio.file.Path> listDirectChildren(java.nio.file.Path path)
public static void createDirectories(java.nio.file.Path path, java.nio.file.attribute.FileAttribute<?>... attrs)
Files.createDirectories(Path, FileAttribute[])
wrapping checked exception.public static void copy(java.nio.file.Path source, java.nio.file.Path target, java.nio.file.CopyOption... copyOptions)
Files.copy(Path, Path, CopyOption...)
wrapping checked exception.public static java.net.URL toUrl(java.nio.file.Path path)
public static java.util.stream.Stream<java.nio.file.Path> walk(java.nio.file.Path path, java.nio.file.FileVisitOption... options)
public static java.util.stream.Stream<java.nio.file.Path> walk(java.nio.file.Path path, int deep, java.nio.file.FileVisitOption... options)
public static void walkFileTree(java.nio.file.Path path, java.nio.file.FileVisitor<java.nio.file.Path> visitor)
public static int copyDirContent(java.nio.file.Path sourceDir, java.nio.file.Path targetDir, java.nio.file.PathMatcher pathMatcher, java.nio.file.CopyOption... copyOptions)
public static int childrenCount(java.nio.file.Path dir, int max, boolean includeDirectories, java.nio.file.PathMatcher pathMatcher)
max + 1
.
This method is designed to stop file traversal as soon as count is greater than max.public static java.nio.file.Path relativizeFromWorkingDir(java.nio.file.Path path)
public static java.nio.file.Path relativizeFromDirIfAbsolute(java.nio.file.Path referent, java.nio.file.Path pathToRelativize)
public static java.util.Optional<java.lang.Long> getLastModifiedTime(java.nio.file.Path path, java.nio.file.LinkOption... options)
public static long size(java.nio.file.Path path)
public static java.nio.file.WatchKey register(java.nio.file.Path dir, java.nio.file.WatchService watchService, java.nio.file.WatchEvent.Kind<?>... watchEventKinds)
public static void moveDir(java.nio.file.Path source, java.nio.file.Path target)