- All Superinterfaces:
AutoCloseable,Closeable
Container that wraps a file path source of some description.
Closing this resource will close any internally held resources that were opened internally. Already-opened resources passed to the implementation will not be closed.
- Since:
- 0.0.1
- Author:
- Ashley Scopes
-
Method Summary
Modifier and TypeMethodDescriptionbooleancontains(PathFileObject fileObject) Determine if this container contains the path file object.Find the physical path to a given string file path.getFileForInput(String packageName, String relativeName) Get aFileObjectfor reading, if it exists.getFileForOutput(String packageName, String relativeName) Get aFileObjectfor writing.getJavaFileForInput(String className, JavaFileObject.Kind kind) Get aJavaFileObjectfor reading, if it exists.getJavaFileForOutput(String className, JavaFileObject.Kind kind) Get aJavaFileObjectfor writing.Get the location of this container.Get a module finder for this container.getName()Get the name of this container for human consumption.Get the path root of the container.inferBinaryName(PathFileObject javaFileObject) Infer the binary name of a given Java file object.List all files within this container.voidlistFileObjects(String packageName, Set<? extends JavaFileObject.Kind> kinds, boolean recurse, Collection<JavaFileObject> collection) List all the file objects that match the given criteria in this group.
-
Method Details
-
contains
Determine if this container contains the path file object.- Parameters:
fileObject- the file object to look up.- Returns:
trueif the object exists in this container, orfalseotherwise.
-
getFile
Find the physical path to a given string file path.Examples:
// Using platform-specific separators ('/' for in-memory file systems). container.getFile("foo/bar/baz.txt"); // Letting JCT infer the correct path separators to use. container.getFile("foo", "bar", "baz.txt");- Parameters:
fragment- the first part of the file name.fragments- any additional parts of the file name to find.- Returns:
- the path if the file exists, or null if it does not exist.
-
getFileForInput
Get aFileObjectfor reading, if it exists.If the file does not exist,
nullis returned.- Parameters:
packageName- the package name of the file.relativeName- the relative name of the file in the package.- Returns:
- the file object, or null if it does not exist.
-
getFileForOutput
Get aFileObjectfor writing.If the container is read-only,
nullis returned.- Parameters:
packageName- the package name of the file.relativeName- the relative name of the file in the package.- Returns:
- the file object, or null if this container is read-only.
-
getJavaFileForInput
Get aJavaFileObjectfor reading, if it exists.If the file does not exist,
nullis returned.- Parameters:
className- the binary name of the class to open.kind- the kind of file to open.- Returns:
- the file object, or null if it does not exist.
-
getJavaFileForOutput
Get aJavaFileObjectfor writing.If the container is read-only,
nullis returned.- Parameters:
className- the binary name of the class to open.kind- the kind of file to open.- Returns:
- the file object, or null if this container is read-only.
-
getLocation
Get the location of this container.- Returns:
- the location.
-
getModuleFinder
Get a module finder for this container.Note that this will not detect modules that are not yet compiled.
- Returns:
- the module finder for this container, or
nullif not relevant to the implementation.
-
getName
Get the name of this container for human consumption.- Returns:
- the container name.
-
getPathRoot
Get the path root of the container.- Returns:
- the path root.
-
inferBinaryName
Infer the binary name of a given Java file object.- Parameters:
javaFileObject- the Java file object to infer the binary name of.- Returns:
- the name, or null if the file does not exist in this container.
-
listAllFiles
List all files within this container.- Returns:
- all files within the container, relative to the container base path.
- Throws:
IOException- if the file system failed to be read.
-
listFileObjects
void listFileObjects(String packageName, Set<? extends JavaFileObject.Kind> kinds, boolean recurse, Collection<JavaFileObject> collection) throws IOException List all the file objects that match the given criteria in this group.The results are filled into a given collection, since this call may be made many times per compliation, and this reduces the memory overhead needed in such cases.
- Parameters:
packageName- the package name to look in.kinds- the kinds of file to look for. Set toSet.of(Kind.OTHER)to find all types of file.recurse-trueto recurse subpackages,falseto only consider the given package.collection- the collection to fill.- Throws:
IOException- if the file system failed to be read.
-