Interface PathFileObject
- All Superinterfaces:
FileObject
,JavaFileObject
JavaFileObject
that points to a path on a file system
somewhere.
This object will always use UTF-8 encoding when obtaining readers or writers.
No access level or nesting kind information is provided by this implementation.
- Since:
- 1.0.0
- Author:
- Ashley Scopes
-
Nested Class Summary
Nested classes/interfaces inherited from interface javax.tools.JavaFileObject
JavaFileObject.Kind
-
Field Summary
Modifier and TypeFieldDescriptionstatic final long
Timestamp that is returned if the file object has never been modified. -
Method Summary
Modifier and TypeMethodDescriptionboolean
delete()
Attempt to delete the file.boolean
Determine if this object equals another.Get the absolute path of this file object.Get the class access level, where appropriate.Get the inferred binary name of the file object.getCharContent
(boolean ignoreEncodingErrors) Read the character content of the file into memory and decode it using the default character set.getKind()
Get the kind of the file.long
Determine when the file was last modified.Get the location of this path file object.getName()
Get the file name as a string.default @Nullable NestingKind
Determine the class nesting kind, where appropriate.Get the relative path of this file object.Get the root path that the package containing this file is nested within.int
hashCode()
Determine the hash code for this object.boolean
isNameCompatible
(String simpleName, JavaFileObject.Kind kind) Determine if a given simple name and file kind are compatible with this file object.Open an input stream into this file.Open an output stream to this file.openReader
(boolean ignoreEncodingErrors) Open a reader to this file using the default charset (UTF-8).Open a writer to this file using the default charset (UTF-8).toString()
Get a string representation of this object.toUri()
Determine the URI for this file.
-
Field Details
-
NOT_MODIFIED
Timestamp that is returned if the file object has never been modified.- See Also:
-
-
Method Details
-
delete
boolean delete()Attempt to delete the file.- Specified by:
delete
in interfaceFileObject
- Returns:
true
if the file was deleted, orfalse
if it was not deleted.
-
equals
-
getAbsolutePath
-
getAccessLevel
Get the class access level, where appropriate.In most implementations, this class will always return
null
, since this information is not readily available without preloading the file in question and parsing it first.At the time of writing, the OpenJDK implementations of the JavaFileObject class do not provide an implementation for this method either.
- Specified by:
getAccessLevel
in interfaceJavaFileObject
- Returns:
- the modifier for the access level, or
null
if the information is not available.
-
getBinaryName
Get the inferred binary name of the file object.- Returns:
- the inferred binary name.
-
getCharContent
Read the character content of the file into memory and decode it using the default character set.- Specified by:
getCharContent
in interfaceFileObject
- Parameters:
ignoreEncodingErrors
- ignore encoding errors iftrue
, or throw them otherwise.- Returns:
- the character content, encoded as UTF-8.
- Throws:
IOException
- if an IO error occurs.
-
getKind
Get the kind of the file.- Specified by:
getKind
in interfaceJavaFileObject
- Returns:
- the inferred file kind.
-
getLastModified
long getLastModified()Determine when the file was last modified.- Specified by:
getLastModified
in interfaceFileObject
- Returns:
- the timestamp in milliseconds since UNIX epoch that the file was last modified at, or
NOT_MODIFIED
if unmodified, if the information is not available, or if an error occurred obtaining the information.
-
getLocation
Get the location of this path file object.- Returns:
- the location.
-
getName
Get the file name as a string.- Specified by:
getName
in interfaceFileObject
- Returns:
- the name of the file.
-
getNestingKind
Determine the class nesting kind, where appropriate.In most implementations, this method will always return
null
, since this information is not readily available without preloading the file in question and parsing it first.At the time of writing, the OpenJDK implementations of the JavaFileObject class do not provide an implementation for this method either.
- Specified by:
getNestingKind
in interfaceJavaFileObject
- Returns:
- the nesting kind, or
null
if the information is not available.
-
getRelativePath
Get the relative path of this file object.- Returns:
- the path of this file object.
-
getRootPath
Get the root path that the package containing this file is nested within.- Returns:
- the root path.
-
hashCode
-
isNameCompatible
Determine if a given simple name and file kind are compatible with this file object.This will perform a case-sensitive check, regardless of the platform that it runs on.
- Specified by:
isNameCompatible
in interfaceJavaFileObject
- Parameters:
simpleName
- the simple name of the class to compare to this file.kind
- the kind of the class to compare to this file.- Returns:
true
if the simple name and kind are compatible with the current file object name, orfalse
if not.
-
openInputStream
Open an input stream into this file.This input stream must be closed once finished with, otherwise resources will be leaked.
The returned implementation will always be buffered when appropriate.
- Specified by:
openInputStream
in interfaceFileObject
- Returns:
- an input stream.
- Throws:
NoSuchFileException
- if the file does not exist.IOException
- if an IO error occurs.
-
openOutputStream
Open an output stream to this file.This will create the file first if it does not already exist. If it does exist, then this will overwrite the file and truncate it. The parent directories will also be created if they do not exist.
This output stream must be closed once finished with, otherwise resources will be leaked.
The returned implementation will always be buffered when appropriate.
- Specified by:
openOutputStream
in interfaceFileObject
- Returns:
- an output stream.
- Throws:
IOException
- if an IO error occurs.
-
openReader
Open a reader to this file using the default charset (UTF-8).This reader must be closed once finished with, otherwise resources will be leaked.
The returned implementation will always be buffered when appropriate.
- Specified by:
openReader
in interfaceFileObject
- Parameters:
ignoreEncodingErrors
-true
to suppress encoding errors, orfalse
to throw them to the caller.- Returns:
- a reader.
- Throws:
NoSuchFileException
- if the file does not exist.IOException
- if an IO error occurs.
-
openWriter
Open a writer to this file using the default charset (UTF-8).This will create the file first if it does not already exist. If it does exist, this will first overwrite the file and truncate it. The parent directories will also be created if they do not exist.
This input stream must be closed once finished with, otherwise resources will be leaked.
The returned implementation will always be buffered when appropriate.
- Specified by:
openWriter
in interfaceFileObject
- Returns:
- a writer.
- Throws:
IOException
- if an IO error occurs.
-
toString
-
toUri
Determine the URI for this file.- Specified by:
toUri
in interfaceFileObject
- Returns:
- the URI for this file object.
-