APIdia Launch Partner
Top Description Inners Methods
javax.tools

public Interface StandardJavaFileManager

extends JavaFileManager
Imports
java.io.File, .IOException, java.nio.file.Path, java.util.ArrayList, .Arrays, .Collection, .Iterator, .List

File manager based on java.io.File and java.nio.file.Path. A common way to obtain an instance of this class is using getStandardFileManager, for example:
  JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
  DiagnosticCollector<JavaFileObject> diagnostics =
      new DiagnosticCollector<JavaFileObject>();
  StandardJavaFileManager fm = compiler.getStandardFileManager(diagnostics, null, null);
This file manager creates file objects representing regular files, zip file entries, or entries in similar file system based containers. Any file object returned from a file manager implementing this interface must observe the following behavior: According to these rules, the following URIs, for example, are allowed: Whereas these are not (reason in parentheses):

All implementations of this interface must support Path objects representing files in the default file system. It is recommended that implementations should support Path objects from any filesystem.

API Note

Some methods on this interface take a Collection<? extends Path> instead of Iterable<? extends Path>. This is to prevent the possibility of accidentally calling the method with a single Path as such an argument, because although Path implements Iterable<Path>, it would almost never be correct to call these methods with a single Path and have it be treated as an Iterable of its components.

Since
1.6

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
StandardJavaFileManager.PathFactory

Factory to create Path objects from strings.

Method Summary

Modifier and TypeMethod and Description
private static <T> Collection<T>
asCollection(Iterable<T> iterable)

private static Iterable<File>
asFiles(final Iterable<? extends Path> paths)

public default Path

Returns:

a path representing the same underlying file system artifact
asPath
(FileObject
a file object
file
)

Returns the path, if any, underlying this file object (optional operation).

private static Iterable<Path>
asPaths(final Iterable<? extends File> files)

public Iterable<? extends JavaFileObject>

Returns:

a list of file objects
getJavaFileObjects
(File...
an array of files
files
)

Returns file objects representing the given files.

public default Iterable<? extends JavaFileObject>

Returns:

a list of file objects
getJavaFileObjects
(Path...
an array of paths
paths
)

Returns file objects representing the given paths.

public Iterable<? extends JavaFileObject>

Returns:

a list of file objects
getJavaFileObjects
(String...
a list of file names
names
)

Returns file objects representing the given file names.

public Iterable<? extends JavaFileObject>

Returns:

a list of file objects
getJavaFileObjectsFromFiles
(Iterable<? extends File>
a list of files
files
)

Returns file objects representing the given files.

public default Iterable<? extends JavaFileObject>

Returns:

a list of file objects
getJavaFileObjectsFromPaths
(Collection<? extends Path>
a list of paths
paths
)

Returns file objects representing the given paths.

public default Iterable<? extends JavaFileObject>

Returns:

a list of file objects
getJavaFileObjectsFromPaths
(Iterable<? extends Path>
a list of paths
paths
)
Deprecated since 13. use getJavaFileObjectsFromPaths(Collection) instead, to prevent the possibility of accidentally calling the method with a single Path as such an argument.

Returns file objects representing the given paths.

public Iterable<? extends JavaFileObject>

Returns:

a list of file objects
getJavaFileObjectsFromStrings
(Iterable<String>
a list of file names
names
)

Returns file objects representing the given file names.

public Iterable<? extends File>

Returns:

a list of files or null if this location has no associated search path
getLocation
(JavaFileManager.Location
a location
location
)

Returns the search path associated with the given location.

public default Iterable<? extends Path>

Returns:

a list of paths or null if this location has no associated search path
getLocationAsPaths
(JavaFileManager.Location
a location
location
)

Returns the search path associated with the given location.

public boolean

Returns:

true if the given file objects represent the same canonical file, zip file entry or path; false otherwise
isSameFile
(FileObject
a file object
a
,
FileObject
a file object
b
)

Redeclares javax.tools.JavaFileManager.isSameFile.

Compares two file objects and return true if they represent the same canonical file, zip file entry, or entry in any file system based container.

public void
setLocation(JavaFileManager.Location
a location
location
,
Iterable<? extends File>
a list of files, if null use the default search path for this location
files
)

Associates the given search path with the given location.

public default void
setLocationForModule(JavaFileManager.Location
the location
location
,
String
the name of the module
moduleName
,
Collection<? extends Path>
the search path to associate with the location and module.
paths
)

Associates the given search path with the given module and location, which must be a module-oriented or output location.

public default void
setLocationFromPaths(JavaFileManager.Location
a location
location
,
Collection<? extends Path>
a list of paths, if null use the default search path for this location
paths
)

Associates the given search path with the given location.

public default void
setPathFactory(StandardJavaFileManager.PathFactory
the factory
f
)

Specify a factory that can be used to generate a path from a string, or series of strings.

Inherited from javax.tools.JavaFileManager:
closecontainsflushgetClassLoadergetFileForInputgetFileForOutputgetFileForOutputForOriginatingFilesgetJavaFileForInputgetJavaFileForOutputgetJavaFileForOutputForOriginatingFilesgetLocationForModulegetLocationForModulegetServiceLoaderhandleOptionhasLocationinferBinaryNameinferModuleNamelistlistLocationsForModules

Method Detail

asCollectionback to summary
private static <T> Collection<T> asCollection(Iterable<T> iterable)
asFilesback to summary
private static Iterable<File> asFiles(final Iterable<? extends Path> paths)
asPathback to summary
public default Path asPath(FileObject file)

Returns the path, if any, underlying this file object (optional operation). File objects derived from a FileSystem, including the default file system, typically have a corresponding underlying Path object. In such cases, this method may be used to access that object.

Implementation Specification

The default implementation throws UnsupportedOperationException for all files.

Parameters
file:FileObject

a file object

Returns:Path

a path representing the same underlying file system artifact

Exceptions
IllegalArgumentException:
if the file object does not have an underlying path
UnsupportedOperationException:
if the operation is not supported by this file manager
Since
9
asPathsback to summary
private static Iterable<Path> asPaths(final Iterable<? extends File> files)
getJavaFileObjectsback to summary
public Iterable<? extends JavaFileObject> getJavaFileObjects(File... files)

Returns file objects representing the given files. Convenience method equivalent to:

getJavaFileObjectsFromFiles(Arrays.asList(files))
getJavaFileObjectsFromFiles(Arrays.asList(files))
Parameters
files:File[]

an array of files

Returns:Iterable<? extends JavaFileObject>

a list of file objects

Exceptions
IllegalArgumentException:
if the array of files includes a directory or if this file manager does not support any of the given paths
NullPointerException:
if the given array contains null elements
getJavaFileObjectsback to summary
public default Iterable<? extends JavaFileObject> getJavaFileObjects(Path... paths)

Returns file objects representing the given paths. Convenience method equivalent to:

getJavaFileObjectsFromPaths(Arrays.asList(paths))
getJavaFileObjectsFromPaths(Arrays.asList(paths))

Implementation Specification

The default implementation will only throw NullPointerException if getJavaFileObjectsFromPaths(Collection) throws it.

Parameters
paths:Path[]

an array of paths

Returns:Iterable<? extends JavaFileObject>

a list of file objects

Exceptions
IllegalArgumentException:
if the array of files includes a directory or if this file manager does not support any of the given paths
NullPointerException:
if the given array contains null elements
Since
9
getJavaFileObjectsback to summary
public Iterable<? extends JavaFileObject> getJavaFileObjects(String... names)

Returns file objects representing the given file names. Convenience method equivalent to:

getJavaFileObjectsFromStrings(Arrays.asList(names))
getJavaFileObjectsFromStrings(Arrays.asList(names))
Parameters
names:String[]

a list of file names

Returns:Iterable<? extends JavaFileObject>

a list of file objects

Exceptions
IllegalArgumentException:
if the array of file names includes a directory
NullPointerException:
if the given array contains null elements
getJavaFileObjectsFromFilesback to summary
public Iterable<? extends JavaFileObject> getJavaFileObjectsFromFiles(Iterable<? extends File> files)

Returns file objects representing the given files.

Parameters
files:Iterable<? extends File>

a list of files

Returns:Iterable<? extends JavaFileObject>

a list of file objects

Exceptions
IllegalArgumentException:
if the list of files includes a directory
getJavaFileObjectsFromPathsback to summary
public default Iterable<? extends JavaFileObject> getJavaFileObjectsFromPaths(Collection<? extends Path> paths)

Returns file objects representing the given paths.

Implementation Specification

The default implementation lazily converts each path to a file and calls getJavaFileObjectsFromFiles. IllegalArgumentException will be thrown if any of the paths cannot be converted to a file at the point the conversion happens.

Parameters
paths:Collection<? extends Path>

a list of paths

Returns:Iterable<? extends JavaFileObject>

a list of file objects

Exceptions
IllegalArgumentException:
if the list of paths includes a directory or if this file manager does not support any of the given paths
Since
13
getJavaFileObjectsFromPathsback to summary
public default Iterable<? extends JavaFileObject> getJavaFileObjectsFromPaths(Iterable<? extends Path> paths)

Deprecated

since 13.

use getJavaFileObjectsFromPaths(Collection) instead, to prevent the possibility of accidentally calling the method with a single Path as such an argument. Although Path implements Iterable<Path>, it would almost never be correct to pass a single Path and have it be treated as an Iterable of its components.

Returns file objects representing the given paths.

Implementation Specification

The default implementation lazily converts each path to a file and calls getJavaFileObjectsFromPaths. IllegalArgumentException will be thrown if any of the paths cannot be converted to a file at the point the conversion happens.

Parameters
paths:Iterable<? extends Path>

a list of paths

Returns:Iterable<? extends JavaFileObject>

a list of file objects

Annotations
@Deprecated
since:13
Exceptions
IllegalArgumentException:
if the list of paths includes a directory or if this file manager does not support any of the given paths.
Since
9
getJavaFileObjectsFromStringsback to summary
public Iterable<? extends JavaFileObject> getJavaFileObjectsFromStrings(Iterable<String> names)

Returns file objects representing the given file names.

Parameters
names:Iterable<String>

a list of file names

Returns:Iterable<? extends JavaFileObject>

a list of file objects

Exceptions
IllegalArgumentException:
if the list of file names includes a directory
getLocationback to summary
public Iterable<? extends File> getLocation(JavaFileManager.Location location)

Returns the search path associated with the given location.

Parameters
location:JavaFileManager.Location

a location

Returns:Iterable<? extends File>

a list of files or null if this location has no associated search path

Exceptions
IllegalStateException:
if any element of the search path cannot be converted to a File, or if the search path cannot be represented as a simple series of files.
See Also
setLocation, Path#toFile
getLocationAsPathsback to summary
public default Iterable<? extends Path> getLocationAsPaths(JavaFileManager.Location location)

Returns the search path associated with the given location.

Implementation Specification

The default implementation calls getLocation and then returns an Iterable formed by calling toPath() on each File returned from getLocation.

Parameters
location:JavaFileManager.Location

a location

Returns:Iterable<? extends Path>

a list of paths or null if this location has no associated search path

Exceptions
IllegalStateException:
if the search path cannot be represented as a simple series of paths.
Since
9
See Also
setLocationFromPaths
isSameFileback to summary
public boolean isSameFile(FileObject a, FileObject b)

Redeclares javax.tools.JavaFileManager.isSameFile.

Compares two file objects and return true if they represent the same canonical file, zip file entry, or entry in any file system based container.

Parameters
a:FileObject

a file object

b:FileObject

a file object

Returns:boolean

true if the given file objects represent the same canonical file, zip file entry or path; false otherwise

Annotations
@Override
Exceptions
IllegalArgumentException:
if either of the arguments were created with another file manager implementation
setLocationback to summary
public void setLocation(JavaFileManager.Location location, Iterable<? extends File> files) throws IOException

Associates the given search path with the given location. Any previous value will be discarded. If the location is a module-oriented or output location, any module-specific associations set up by setLocationForModule will be cancelled.

Parameters
location:JavaFileManager.Location

a location

files:Iterable<? extends File>

a list of files, if null use the default search path for this location

Exceptions
IOException:
if location is an output location and does not represent an existing directory
IllegalArgumentException:
if location is an output location and files does not contain exactly one element
See Also
getLocation
setLocationForModuleback to summary
public default void setLocationForModule(JavaFileManager.Location location, String moduleName, Collection<? extends Path> paths) throws IOException

Associates the given search path with the given module and location, which must be a module-oriented or output location. Any previous value will be discarded. This overrides any default association derived from the search path associated with the location itself. All such module-specific associations will be cancelled if a new search path is associated with the location by calling setLocation or setLocationFromPaths.

Implementation Specification

The default implementation throws UnsupportedOperationException.

Parameters
location:JavaFileManager.Location

the location

moduleName:String

the name of the module

paths:Collection<? extends Path>

the search path to associate with the location and module.

Exceptions
IOException:
if location is an output location and paths does not represent an existing directory
IllegalStateException:
if the location is not a module-oriented or output location.
UnsupportedOperationException:
if this operation is not supported by this file manager.
Since
9
See Also
setLocation, setLocationFromPaths
setLocationFromPathsback to summary
public default void setLocationFromPaths(JavaFileManager.Location location, Collection<? extends Path> paths) throws IOException

Associates the given search path with the given location. Any previous value will be discarded. If the location is a module-oriented or output location, any module-specific associations set up by setLocationForModule will be cancelled.

Implementation Specification

The default implementation lazily converts each path to a file and calls setLocation. IllegalArgumentException will be thrown if any of the paths cannot be converted to a file at the point the conversion happens.

Parameters
location:JavaFileManager.Location

a location

paths:Collection<? extends Path>

a list of paths, if null use the default search path for this location

Exceptions
IOException:
if location is an output location and paths does not represent an existing directory
IllegalArgumentException:
if location is an output location and paths does not contain exactly one element or if this file manager does not support any of the given paths
Since
9
See Also
getLocation
setPathFactoryback to summary
public default void setPathFactory(StandardJavaFileManager.PathFactory f)

Specify a factory that can be used to generate a path from a string, or series of strings. If this method is not called, a factory whose getPath method is equivalent to calling java.nio.file.Paths.get(first, more) will be used.

Implementation Specification

The default implementation of this method ignores the factory that is provided.

Parameters
f:StandardJavaFileManager.PathFactory

the factory

Since
9
javax.tools back to summary

public Interface StandardJavaFileManager.PathFactory


Factory to create Path objects from strings.
Since
9

Method Summary

Modifier and TypeMethod and Description
public Path

Returns:

the resulting Path
getPath
(String
the path string or initial part of the path string
first
,
String...
additional strings to be joined to form the path string
more
)

Converts a path string, or a sequence of strings that when joined form a path string, to a Path.

Method Detail

getPathback to summary
public Path getPath(String first, String... more)

Converts a path string, or a sequence of strings that when joined form a path string, to a Path.

Parameters
first:String

the path string or initial part of the path string

more:String[]

additional strings to be joined to form the path string

Returns:Path

the resulting Path