- All Implemented Interfaces:
FileObject,JavaFileObject
JavaFileObject that points to a path on some FileSystem 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:
- 0.0.1
- Author:
- Ashley Scopes
-
Nested Class Summary
Nested classes/interfaces inherited from interface javax.tools.JavaFileObject
JavaFileObject.Kind -
Constructor Summary
ConstructorsConstructorDescriptionPathFileObject(JavaFileManager.Location location, Path rootPath, Path relativePath) Initialize this file object. -
Method Summary
Modifier and TypeMethodDescriptionbooleandelete()Attempt to delete the file.booleanDetermine if this object equals another.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.Get the full path of this file object.getKind()Get the kind of the file.longDetermine when the file was last modified.Get the location of this path file object.getName()Get the file name as a string.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.inthashCode()Determine the hash code for this object.booleanisNameCompatible(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.
-
Constructor Details
-
PathFileObject
Initialize this file object.- Parameters:
location- the location that the file object is located within.rootPath- the root directory that the path is a package within.relativePath- the path to point to, relative to the root.
-
-
Method Details
-
delete
Attempt to delete the file.- Specified by:
deletein interfaceFileObject- Returns:
trueif the file was deleted, orfalseif it was not deleted.
-
equals
Determine if this object equals another.- Overrides:
equalsin classObject- Parameters:
other- the other object to compare with.- Returns:
trueif the other object is also aFileObjectand has the sameURIas this object, orfalseotherwise.
-
getAccessLevel
Get the class access level, where appropriate.In this implementation, 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:
getAccessLevelin interfaceJavaFileObject- Returns:
null, always. This implementation does not provide this functionality.
-
getBinaryName
Get the inferred binary name of the file object.- Returns:
- the inferred binary name.
- Since:
- 0.2.1
-
getCharContent
Read the character content of the file into memory and decode it using the default character set.- Specified by:
getCharContentin 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.
-
getFullPath
Get the full path of this file object.- Returns:
- the full path.
-
getKind
Get the kind of the file.- Specified by:
getKindin interfaceJavaFileObject- Returns:
- the inferred file kind.
-
getLastModified
Determine when the file was last modified.- Specified by:
getLastModifiedin interfaceFileObject- Returns:
- the timestamp in milliseconds since UNIX epoch that the file was last modified at, or
0Lif unmodified.
-
getLocation
Get the location of this path file object.- Returns:
- the location.
-
getName
Get the file name as a string.- Specified by:
getNamein interfaceFileObject- Returns:
- the name of the file.
-
getNestingKind
Determine the class nesting kind, where appropriate.In this implementation, 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:
getNestingKindin interfaceJavaFileObject- Returns:
nullin all cases, this operation is not implemented.
-
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
Determine the hash code for this object. -
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:
isNameCompatiblein interfaceJavaFileObject- Returns:
trueif the simple name and kind are compatible with the current file object name, orfalseif 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.
- Specified by:
openInputStreamin interfaceFileObject- Returns:
- a buffered 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.
- Specified by:
openOutputStreamin interfaceFileObject- Returns:
- a buffered 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.
- Specified by:
openReaderin interfaceFileObject- Parameters:
ignoreEncodingErrors-trueto suppress encoding errors, orfalseto throw them to the caller.- Returns:
- a buffered 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.
- Specified by:
openWriterin interfaceFileObject- Returns:
- a buffered writer.
- Throws:
IOException- if an IO error occurs.
-
toUri
Determine the URI for this file.- Specified by:
toUriin interfaceFileObject- Returns:
- the URI for this file object.
-
toString
Get a string representation of this object.
-