When constructing new JavaFileObjects, the file manager must determine where to create them. For example, if a file manager manages regular files on a file system, it would most likely have a current/working directory to use as default location when creating or finding files. A number of hints can be provided to a file manager as to where to create files. Any file manager might choose to ignore these hints.
Some methods in this interface use class names. Such class names must be given in the Java Virtual Machine internal form of fully qualified class and interface names. For convenience, '.' and '/' are interchangeable. The internal form is defined in chapter four of The Java Virtual Machine Specification.
Discussion: this means that the names "java/lang.package-info", "java/lang/package-info", "java.lang.package-info", are valid and equivalent. Compare to binary name as defined in The Java Language Specification, section 13.1 "The Form of a Binary".
The case of names is significant. All names should be treated
as case-sensitive. For example, some file systems have
case-insensitive, case-aware file names. File objects representing
such files should take care to preserve case by using java. or similar means. If the system is
not case-aware, file objects must use other means to preserve case.
Relative names: some methods in this interface use relative names. A relative name is a non-null, non-empty sequence of path segments separated by '/'. '.' or '..' are invalid path segments. A valid relative name must match the "path-rootless" rule of RFC 3986, section 3.3. Informally, this should be true:
An object of this interface is not required to support multi-threaded access, that is, be synchronized. However, it must support concurrent access to different file objects created by this object.
Implementation Note
a consequence of this requirement is that a trivial implementation of output to a java.util.jar.JarOutputStream is not a sufficient implementation. That is, rather than creating a JavaFileObject that returns the JarOutputStream directly, the contents must be cached until closed and then written to the JarOutputStream.
Unless explicitly allowed, all methods in this interface might
throw a NullPointerException if given a null argument.
JavaFileObject, FileObject
| Modifier and Type | Class and Description |
|---|---|
| public static interface | JavaFileManager.
Interface for locations of file objects. |
| Modifier and Type | Method and Description |
|---|---|
| public void | close()
Redeclares java. Releases any resources opened by this file manager directly or indirectly. |
| public default boolean | Returns: whether or not the file is contained in the locationthe location location,the file object fo)Determines whether or not a given file object is "contained in" a specified location. |
| public void | flush()
Redeclares java. Flushes any resources opened for output by this file manager directly or indirectly. |
| public ClassLoader | Returns: a class loader for the given location; ornull
if loading plug-ins from the given location is disabled or if
the location is not knowna location locationReturns a class loader for loading plug-ins from the given package-oriented location. |
| public FileObject | Returns: a file object, might returnnull if the file
does not exista package-oriented location location,a package name packageName, String a relative name relativeName)Returns a file object for input representing the specified relative name in the specified package in the given package-oriented location. |
| public FileObject | Returns: a file objectan output location location,a package name packageName, String a relative name relativeName, FileObject a file object to be used as hint for placement;
might be sibling)nullReturns a file object for output representing the specified relative name in the specified package in the given location. |
| public default FileObject | Returns: a file objectan output location location,a package name packageName, String a relative name relativeName, FileObject... the files which are contributing to this newly created file;
originatingFiles)null is equivalent to empty originatingFiles,
meaning no known originating filesReturns a file object for output representing the specified relative name in the specified package in the given location. |
| public JavaFileObject | Returns: a file object, might returnnull if the
file does not exista location location,the name of a class className, JavaFileObject.Returns a file object for input representing the specified class of the specified kind in the given package-oriented location. |
| public JavaFileObject | Returns: a file object for outputa package-oriented location location,the name of a class className, JavaFileObject.a file object to be used as hint for placement;
might be sibling)nullReturns a file object for output representing the specified class of the specified kind in the given package-oriented location. |
| public default JavaFileObject | Returns: a file object for outputa package-oriented location location,the name of a class className, JavaFileObject.the files which are contributing to this newly created file;
originatingFiles)null is equivalent to empty originatingFiles,
meaning no known originating filesReturns a file object for output representing the specified class of the specified kind in the given package-oriented location. |
| public default JavaFileManager. | Returns: the location for the named modulethe module-oriented location location,the name of the module to be found moduleName)Gets a location for a named module within a location, which may be either a module-oriented location or an output location. |
| public default JavaFileManager. | Returns: the module containing the filethe module-oriented location location,the file fo)Gets a location for the module containing a specific file to be found within a location, which may be either a module-oriented location or an output location. |
| public default < the service class S> ServiceLoader | Returns: a service loader for the given service classthe module-oriented location location,the service)Class object of the service classGet a service loader for a specific service class from a given location. |
| public boolean | Returns: true if this option was handled by this file manager, false otherwisecurrent option current, Iterator<String> remaining options remaining)Handles one option. |
| public boolean | Returns: true if the location is knowna location locationDetermines if a location is known to this file manager. |
| public String | Returns: a binary name ornull the file object is not
found in the given locationa location location,a file object file)Infers a binary name of a file object based on a package-oriented location. |
| public default String | Returns: the name of the modulea package-oriented location representing a module locationInfer the name of the module from its location, as returned by
|
| public boolean | Returns: true if the given file objects represent the same underlying objecta file object a, FileObject a file object b)Compares two file objects and returns true if they represent the same underlying object. |
| public Iterable | Returns: an Iterable of file objects matching the given criteriaa location location,a package name packageName, Set<JavaFileObject.return objects only of these kinds kinds,if true include "subpackages" recurse)Lists all file objects matching the given criteria in the given package-oriented location. |
| public default Iterable | Returns: a series of sets of locations containing modulesthe module-oriented location for which to list the modules locationLists the locations for all the modules in a module-oriented location or an output location. |
| private static FileObject |
| close | back to summary |
|---|---|
| public void close() throws IOException Redeclares java. Releases any resources opened by this file manager directly or indirectly. This might render this file manager useless and the effect of subsequent calls to methods on this object or any objects obtained through this object is undefined unless explicitly allowed. However, closing a file manager which has already been closed has no effect.
| |
| contains | back to summary |
|---|---|
| public default boolean contains(JavaFileManager. Determines whether or not a given file object is "contained in" a specified location. For a package-oriented location, a file object is contained in the location if there exist
values for packageName and relativeName such that either of the following
calls would return the getFileForInput(location, packageName, relativeName) getFileForOutput(location, packageName, relativeName, null) For a module-oriented location, a file object is contained in the location if there exists a module that may be obtained by the call: getLocationForModule(location, moduleName) Implementation Specification This implementation throws
| |
| flush | back to summary |
|---|---|
| public void flush() throws IOException Redeclares java. Flushes any resources opened for output by this file manager directly or indirectly. Flushing a closed file manager has no effect.
| |
| getClassLoader | back to summary |
|---|---|
| public ClassLoader getClassLoader(JavaFileManager. Returns a class loader for loading plug-ins from the given
package-oriented location.
For example, to load annotation processors,
a compiler will request a class loader for the
| |
| getFileForInput | back to summary |
|---|---|
| public FileObject getFileForInput(JavaFileManager. Returns a file object for input representing the specified relative name in the specified package in the given package-oriented location. If the returned object represents a source or class file, it must be an instance
of Informally, the file object returned by this method is located in the concatenation of the location, package name, and relative name. For example, to locate the properties file "resources/compiler.properties" in the package "com.sun.tools.javac" in the SOURCE_PATH location, this method might be called like so: getFileForInput(SOURCE_PATH, "com.sun.tools.javac", "resources/compiler.properties"); If the call was executed on Windows, with SOURCE_PATH set to
| |
| getFileForOutput | back to summary |
|---|---|
| public FileObject getFileForOutput(JavaFileManager. Returns a file object for output representing the specified relative name in the specified package in the given location. Optionally, this file manager might consider the sibling as a hint for where to place the output. The exact semantics of this hint is unspecified. The JDK compiler, javac, for example, will place class files in the same directories as originating source files unless a class file output directory is provided. To facilitate this behavior, javac might provide the originating source file as sibling when calling this method. If the returned object represents a source or class file, it must be an instance
of Informally, the file object returned by this method is
located in the concatenation of the location, package name, and
relative name or next to the sibling argument. See
| |
| getFileForOutputForOriginatingFiles | back to summary |
|---|---|
| public default FileObject getFileForOutputForOriginatingFiles(JavaFileManager. Returns a file object for output representing the specified relative name in the specified package in the given location. The provided If the returned object represents a source or class file, it must be an instance
of Informally, the file object returned by this method is
located in the concatenation of the location, package name, and
relative name or in a location inferred from the Implementation Specification The default implementation calls
| |
| getJavaFileForInput | back to summary |
|---|---|
| public JavaFileObject getJavaFileForInput(JavaFileManager. Returns a file object for input representing the specified class of the specified kind in the given package-oriented location.
| |
| getJavaFileForOutput | back to summary |
|---|---|
| public JavaFileObject getJavaFileForOutput(JavaFileManager. Returns a file object for output representing the specified class of the specified kind in the given package-oriented location. Optionally, this file manager might consider the sibling as a hint for where to place the output. The exact semantics of this hint is unspecified. The JDK compiler, javac, for example, will place class files in the same directories as originating source files unless a class file output directory is provided. To facilitate this behavior, javac might provide the originating source file as sibling when calling this method.
| |
| getJavaFileForOutputForOriginatingFiles | back to summary |
|---|---|
| public default JavaFileObject getJavaFileForOutputForOriginatingFiles(JavaFileManager. Returns a file object for output representing the specified class of the specified kind in the given package-oriented location. The provided Implementation Specification The default implementation calls
| |
| getLocationForModule | back to summary |
|---|---|
| public default JavaFileManager. Gets a location for a named module within a location, which may be either a module-oriented location or an output location. The result will be an output location if the given location is an output location, or it will be a package-oriented location. Implementation Specification This implementation throws
| |
| getLocationForModule | back to summary |
|---|---|
| public default JavaFileManager. Gets a location for the module containing a specific file to be found within a location, which may be either a module-oriented location or an output location. The result will be an output location if the given location is an output location, or it will be a package-oriented location. Implementation Specification This implementation throws
| |
| getServiceLoader | back to summary |
|---|---|
| public default <S> ServiceLoader Get a service loader for a specific service class from a given location.
If the location is a module-oriented location, the service loader will use the
service declarations in the modules found in that location. Otherwise, a service loader
is created using the package-oriented location, in which case, the services are
determined using the provider-configuration files in Implementation Specification This implementation throws
| |
| handleOption | back to summary |
|---|---|
| public boolean handleOption(String current, Iterator<String> remaining) Handles one option. If
| |
| hasLocation | back to summary |
|---|---|
| public boolean hasLocation(JavaFileManager. Determines if a location is known to this file manager.
| |
| inferBinaryName | back to summary |
|---|---|
| public String inferBinaryName(JavaFileManager. Infers a binary name of a file object based on a package-oriented location. The binary name returned might not be a valid binary name according to The Java Language Specification.
| |
| inferModuleName | back to summary |
|---|---|
| public default String inferModuleName(JavaFileManager. Infer the name of the module from its location, as returned by
Implementation Specification This implementation throws
| |
| isSameFile | back to summary |
|---|---|
| public boolean isSameFile(FileObject a, FileObject b) Compares two file objects and returns true if they represent the same underlying object.
| |
| list | back to summary |
|---|---|
| public Iterable Lists all file objects matching the given criteria in the given package-oriented location. List file objects in "subpackages" if recurse is true. Note even if the given location is unknown to this file
manager, it may not return
| |
| listLocationsForModules | back to summary |
|---|---|
| public default Iterable Lists the locations for all the modules in a module-oriented location or an output location. The locations that are returned will be output locations if the given location is an output, or it will be a package-oriented locations. Implementation Specification This implementation throws
| |
| siblingFrom | back to summary |
|---|---|
| private static FileObject siblingFrom(FileObject[] originatingFiles) | |
Informally, a Location corresponds to a "search path", such as a class
path or module path, as used by command-line tools that use the default file system.
Some locations are typically used to identify a place in which a tool can find files to be read; others are typically used to identify a place where a tool can write files. If a location is used to identify a place for reading files, those files may be organized in a simple package/class hierarchy: such locations are described as package-oriented. Alternatively, the files may be organized in a module/package/class hierarchy: such locations are described as module-oriented. If a location is typically used to identify a place where a tool can write files, it is up to the tool that writes the files to specify how those files will be organized.
You can access the classes in a package-oriented location using methods like
JavaFileManager#getJavaFileForInput or JavaFileManager#list.
It is not possible to directly list the classes in a module-oriented
location. Instead, you can get a package-oriented location for any specific module
using methods like JavaFileManager#getLocationForModule or
JavaFileManager#listLocationsForModules.
| Modifier and Type | Method and Description |
|---|---|
| public String | |
| public default boolean | Returns: true if this location is expected to contain modulesIndicates if this location is module-oriented location, and therefore expected to contain classes in a module/package/class hierarchy, as compared to a package-oriented location, which is expected to contain classes in a package/class hierarchy. |
| public boolean | Returns: true if this is an output location, false otherwiseDetermines if this is an output location. |
| getName | back to summary |
|---|---|
| public String getName() Returns the name of this location.
| |
| isModuleOrientedLocation | back to summary |
|---|---|
| public default boolean isModuleOrientedLocation() Indicates if this location is module-oriented location, and therefore expected to contain classes in a module/package/class hierarchy, as compared to a package-oriented location, which is expected to contain classes in a package/class hierarchy. The result of this method is undefined if this is an output location. Implementation Specification This implementation returns true if the name includes the word "MODULE".
| |
| isOutputLocation | back to summary |
|---|---|
| public boolean isOutputLocation() Determines if this is an output location. An output location is a location that is conventionally used for output. API Note An output location may be used to write files in either a package-oriented organization or in a module-oriented organization.
| |