T
- for self returning keeping the actual type.public class JkAbstractPathTree<T extends JkAbstractPathTree>
extends java.lang.Object
JkPathTree
may have some include/exclude filters to include only
or exclude specified files.JkAbstractPathTree
, we mean all
files contained in its root directory or subdirectories, matching positively
the filter defined on it.Modifier and Type | Class and Description |
---|---|
static class |
JkAbstractPathTree.FileChange |
class |
JkAbstractPathTree.JkPathTreeStream
A decorator class for Stream
|
Modifier and Type | Field and Description |
---|---|
protected java.util.function.Supplier<java.nio.file.Path> |
rootSupplier |
Modifier | Constructor and Description |
---|---|
protected |
JkAbstractPathTree(java.util.function.Supplier<java.nio.file.Path> rootSupplier,
JkPathMatcher matcher) |
Modifier and Type | Method and Description |
---|---|
T |
andMatcher(java.nio.file.PathMatcher pathMatcher)
Creates a copy of this
JkAbstractPathTree augmented with the specified JkPathMatcher |
T |
andMatching(boolean positive,
java.lang.Iterable<java.lang.String> globPatterns)
Creates a copy of this
JkAbstractPathTree augmented with the specified pattern matcher. |
T |
andMatching(boolean positive,
java.lang.String... globPatterns)
Creates a copy of this
JkAbstractPathTree augmented with the specified pattern matcher. |
T |
andMatching(java.lang.String... globPatterns)
Shorthand to
andMatching(true, globPatterns...) . |
java.lang.String |
checksum(java.lang.String algorithm)
Computes the checksum of this tree content.
|
boolean |
containFiles() |
void |
copyFile(java.lang.String sourcePath,
java.nio.file.Path destinationDir,
java.nio.file.CopyOption... copyOptions)
Copies a single file contained in this
JkAbstractPathTree to the specified directory. |
int |
copyTo(java.nio.file.Path destinationDir,
java.nio.file.CopyOption... copyOptions)
Copies files contained in this
JkAbstractPathTree to the specified directory. |
int |
count(int max,
boolean includeDirectories)
Returns the file count contained in this
JkAbstractPathTree to concurrence to specified max count. |
T |
createIfNotExist()
Creates root directory if not exists.
|
T |
deleteContent()
Deletes each and every file in this tree except the root and files not matching this tree filter.
|
T |
deleteRoot()
Deletes the root directory of the path tree.
|
T |
deleteRootIfExist()
Deletes the root directory of the path tree.
|
boolean |
exists()
Returns
true if the root directory exists. |
java.nio.file.Path |
get(java.lang.String relativePath)
Returns path relative to this root of the specified relative path.
|
java.util.List<java.nio.file.Path> |
getFiles()
Returns list of paths returned by
stream(FileVisitOption...) but excluding directories from the result. |
JkPathMatcher |
getMatcher()
Returns the filter defined on this
JkAbstractPathTree , never null . |
java.util.List<java.nio.file.Path> |
getRelativeFiles()
Deprecated.
Use
stream(FileVisitOption...) in combination with
JkAbstractPathTree.JkPathTreeStream.relativizeFromRoot() instead |
java.nio.file.Path |
getRoot()
Returns the root directory.
|
T |
goTo(java.lang.String relativePath)
Creates a
JkAbstractPathTree having the specified relative path to this root as getRoot directory. |
boolean |
hasFilter() |
T |
importDir(java.nio.file.Path dirToCopy,
java.nio.file.CopyOption... copyOptions)
Copies the specified directory and its content at the root of this tree.
|
T |
importFile(java.nio.file.Path src,
java.lang.String targetName,
java.nio.file.StandardCopyOption... copyOptions)
Copies the specified file at the specified path within this tree.
|
T |
importFiles(java.lang.Iterable<java.nio.file.Path> files,
java.nio.file.StandardCopyOption... copyOptions)
Copies the specified files at the root of this tree.
|
T |
importTree(JkAbstractPathTree tree,
java.nio.file.CopyOption... copyOptions)
Copies the content of the specified tree at the root of this one.
|
protected T |
newInstance(java.util.function.Supplier<java.nio.file.Path> pathSupplier,
JkPathMatcher pathMatcher) |
static JkAbstractPathTree |
of(java.nio.file.Path rootDir)
Creates a
JkAbstractPathTree having the specified root directory. |
static JkAbstractPathTree |
of(java.lang.String rootDir) |
T |
resolvedTo(java.nio.file.Path newRoot)
Assuming the root folder is relative, this creates an identical
JkAbstractPathTree
but having the root as : [specified new root]/[former root] |
JkAbstractPathTree.JkPathTreeStream |
stream(java.nio.file.FileVisitOption... options)
Returns a stream of paths in the directory tree rooted at the specified directory,
filtered by the specified options.
|
JkAbstractPathTree.JkPathTreeStream |
streamBreathFirst()
Same as
stream(FileVisitOption...) but using a breath-first
traversal algorithm. |
java.lang.String |
toString() |
void |
watch(long millis,
java.util.concurrent.atomic.AtomicBoolean run,
java.util.function.Consumer<java.util.List<JkAbstractPathTree.FileChange>> fileChangeConsumer)
Watches file and directory changes involved in this path tree.
|
void |
watch(long millis,
java.util.concurrent.atomic.AtomicBoolean run,
java.lang.Runnable runnable)
Same as
watch(long, AtomicBoolean, Consumer) but just triggering a consumer on file changes. |
void |
watch(long millis,
java.lang.Runnable runnable)
Same as
watch(long, AtomicBoolean, Runnable) but running indefinitely. |
T |
withMatcher(JkPathMatcher pathMatcher)
Creates a
JkAbstractPathTree which is a copy of this JkAbstractPathTree
but the matcher is replaced with the specified one. |
protected T |
withRoot(java.nio.file.Path newRoot) |
T |
zipTo(java.nio.file.Path destination)
Zips the content of this tree to the specified destination file.
|
protected final java.util.function.Supplier<java.nio.file.Path> rootSupplier
protected JkAbstractPathTree(java.util.function.Supplier<java.nio.file.Path> rootSupplier, JkPathMatcher matcher)
public static JkAbstractPathTree of(java.nio.file.Path rootDir)
JkAbstractPathTree
having the specified root directory.public static JkAbstractPathTree of(java.lang.String rootDir)
of(Path)
protected T newInstance(java.util.function.Supplier<java.nio.file.Path> pathSupplier, JkPathMatcher pathMatcher)
protected T withRoot(java.nio.file.Path newRoot)
public java.nio.file.Path getRoot()
public JkPathMatcher getMatcher()
JkAbstractPathTree
, never null
.public boolean hasFilter()
public boolean exists()
true
if the root directory exists.public T createIfNotExist()
public JkAbstractPathTree.JkPathTreeStream stream(java.nio.file.FileVisitOption... options)
The tree is traversed using a deep first algorithm.
The returned paths are
The returned stream provides means o filer file only, and transform to paths relative to root dir.
public JkAbstractPathTree.JkPathTreeStream streamBreathFirst()
stream(FileVisitOption...)
but using a breath-first
traversal algorithm.@Deprecated public java.util.List<java.nio.file.Path> getRelativeFiles()
stream(FileVisitOption...)
in combination with
JkAbstractPathTree.JkPathTreeStream.relativizeFromRoot()
insteadgetFiles()
but returning paths relative to this tree root.public java.util.List<java.nio.file.Path> getFiles()
stream(FileVisitOption...)
but excluding directories from the result.public T goTo(java.lang.String relativePath)
JkAbstractPathTree
having the specified relative path to this root as getRoot directory.
Note that the returned tree has no filter even if this tree has one.public T resolvedTo(java.nio.file.Path newRoot)
JkAbstractPathTree
but having the root as : [specified new root]/[former root]public java.nio.file.Path get(java.lang.String relativePath)
public T importDir(java.nio.file.Path dirToCopy, java.nio.file.CopyOption... copyOptions)
public T importTree(JkAbstractPathTree tree, java.nio.file.CopyOption... copyOptions)
public T importFiles(java.lang.Iterable<java.nio.file.Path> files, java.nio.file.StandardCopyOption... copyOptions)
public T importFile(java.nio.file.Path src, java.lang.String targetName, java.nio.file.StandardCopyOption... copyOptions)
public T deleteContent()
public T deleteRoot()
public T deleteRootIfExist()
public T zipTo(java.nio.file.Path destination)
public int copyTo(java.nio.file.Path destinationDir, java.nio.file.CopyOption... copyOptions)
JkAbstractPathTree
to the specified directory.public void copyFile(java.lang.String sourcePath, java.nio.file.Path destinationDir, java.nio.file.CopyOption... copyOptions)
JkAbstractPathTree
to the specified directory. File name remains the same.sourcePath
- The relative path of the source file from this tree root.public T andMatcher(java.nio.file.PathMatcher pathMatcher)
JkAbstractPathTree
augmented with the specified JkPathMatcher
public T withMatcher(JkPathMatcher pathMatcher)
JkAbstractPathTree
which is a copy of this JkAbstractPathTree
but the matcher is replaced with the specified one.public T andMatching(boolean positive, java.lang.String... globPatterns)
JkAbstractPathTree
augmented with the specified pattern matcher.public T andMatching(java.lang.String... globPatterns)
andMatching(true, globPatterns...)
.public T andMatching(boolean positive, java.lang.Iterable<java.lang.String> globPatterns)
JkAbstractPathTree
augmented with the specified pattern matcher.public int count(int max, boolean includeDirectories)
JkAbstractPathTree
to concurrence to specified max count.
If the effective count is greater than max count, this method returns max count + 1
.
This method is designed to stop file traversal as soon as count is greater than max.public boolean containFiles()
public java.lang.String toString()
toString
in class java.lang.Object
public void watch(long millis, java.util.concurrent.atomic.AtomicBoolean run, java.util.function.Consumer<java.util.List<JkAbstractPathTree.FileChange>> fileChangeConsumer)
millis
- Time to wait for capturing file changesrun
- Semaphore, this methods loop until this values falsefileChangeConsumer
- The consumer to be invoked on file changespublic void watch(long millis, java.util.concurrent.atomic.AtomicBoolean run, java.lang.Runnable runnable)
watch(long, AtomicBoolean, Consumer)
but just triggering a consumer on file changes.public void watch(long millis, java.lang.Runnable runnable)
watch(long, AtomicBoolean, Runnable)
but running indefinitely.public java.lang.String checksum(java.lang.String algorithm)
algorithm
- algorithm used to produce checksum, such as md5 or sha256.