Package com.swoval.files
Class FileTreeViews
- java.lang.Object
-
- com.swoval.files.FileTreeViews
-
public class FileTreeViews extends java.lang.ObjectProvides static methods returning instances of the various view interfaces defined throughout this package.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceFileTreeViews.Observable<T>Provides an api for subscribing and unsubscribing to events.static interfaceFileTreeViews.Observer<T>Generic Observer for anFileTreeViews.Observable.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static DirectoryViewcached(java.nio.file.Path path, int depth, boolean followLinks)Make a newDirectoryViewthat caches the file tree but has no data value associated with each value.static FileTreeViewgetDefault(boolean followLinks)Returns the defaultFileTreeViewfor the runtime platform.static FileTreeViewgetNative(boolean followLinks)Returns an instance ofFileTreeViewthat uses native jni functions to improve performance compared to theFileTreeViewreturned bygetNio(boolean).static FileTreeViewgetNio(boolean followLinks)Returns an instance ofFileTreeViewthat uses only apis available in java.nio.file.static java.util.List<TypedPath>list(java.nio.file.Path path, int maxDepth, Filter<? super TypedPath> filter)List the contents of a path.
-
-
-
Method Detail
-
cached
public static DirectoryView cached(java.nio.file.Path path, int depth, boolean followLinks) throws java.io.IOException
Make a newDirectoryViewthat caches the file tree but has no data value associated with each value.- Parameters:
path- the path to monitordepth- sets how the limit for how deep to traverse the children of this directoryfollowLinks- sets whether or not to treat symbolic links whose targets as directories or files- Returns:
- a directory whose entries just contain the path itself.
- Throws:
java.io.IOException- when an error is encountered traversing the directory.
-
getNio
public static FileTreeView getNio(boolean followLinks)
Returns an instance ofFileTreeViewthat uses only apis available in java.nio.file. This may be used on platforms for which there is no native implementation ofFileTreeView.- Parameters:
followLinks- toggles whether or not to follow the targets of symbolic links to directories.- Returns:
- an instance of
FileTreeView.
-
getNative
public static FileTreeView getNative(boolean followLinks)
Returns an instance ofFileTreeViewthat uses native jni functions to improve performance compared to theFileTreeViewreturned bygetNio(boolean).- Parameters:
followLinks- toggles whether or not to follow the targets of symbolic links to directories.- Returns:
- an instance of
FileTreeView.
-
getDefault
public static FileTreeView getDefault(boolean followLinks)
Returns the defaultFileTreeViewfor the runtime platform. If a native implementation is present, it will be used. Otherwise, it will fall back to the java.nio.file based implementation.- Parameters:
followLinks- toggles whether or not to follow the targets of symbolic links to directories.- Returns:
- an instance of
FileTreeView.
-
list
public static java.util.List<TypedPath> list(java.nio.file.Path path, int maxDepth, Filter<? super TypedPath> filter) throws java.io.IOException
List the contents of a path.- Parameters:
path- the path to list. If the path is a directory, return the children of this directory up to the maxDepth. If the path is a regular file and the maxDepth is-1, the path itself is returned. Otherwise an empty list is returned.maxDepth- the maximum depth of children to include in the resultsfilter- only include paths accepted by this filter- Returns:
- a
ListofTypedPath - Throws:
java.io.IOException- if the Path doesn't exist
-
-