Interface PathFileObject

All Superinterfaces:
FileObject, JavaFileObject

public interface PathFileObject extends JavaFileObject
Interface for a path-based 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
  • Field Details

  • Method Details

    • delete

      boolean delete()
      Attempt to delete the file.
      Specified by:
      delete in interface FileObject
      Returns:
      true if the file was deleted, or false if it was not deleted.
    • equals

      boolean equals(@Nullable Object other)
      Determine if this object equals another.
      Overrides:
      equals in class Object
      Parameters:
      other - the other object to compare with.
      Returns:
      true if the other object is also a FileObject and has the same URI as this object, or false otherwise.
    • getAbsolutePath

      Get the absolute path of this file object.
      Returns:
      the full path.
    • 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 interface JavaFileObject
      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

      String getCharContent(boolean ignoreEncodingErrors) throws IOException
      Read the character content of the file into memory and decode it using the default character set.
      Specified by:
      getCharContent in interface FileObject
      Parameters:
      ignoreEncodingErrors - ignore encoding errors if true, 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 interface JavaFileObject
      Returns:
      the inferred file kind.
    • getLastModified

      Determine when the file was last modified.
      Specified by:
      getLastModified in interface FileObject
      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 interface FileObject
      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 interface JavaFileObject
      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

      int hashCode()
      Determine the hash code for this object.
      Overrides:
      hashCode in class Object
      Returns:
      the hash code for the object.
    • isNameCompatible

      boolean isNameCompatible(String simpleName, JavaFileObject.Kind kind)
      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 interface JavaFileObject
      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, or false 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 interface FileObject
      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 interface FileObject
      Returns:
      an output stream.
      Throws:
      IOException - if an IO error occurs.
    • openReader

      Reader openReader(boolean ignoreEncodingErrors) throws IOException
      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 interface FileObject
      Parameters:
      ignoreEncodingErrors - true to suppress encoding errors, or false 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 interface FileObject
      Returns:
      a writer.
      Throws:
      IOException - if an IO error occurs.
    • toString

      Get a string representation of this object.
      Overrides:
      toString in class Object
      Returns:
      a string representation of this object.
    • toUri

      Determine the URI for this file.
      Specified by:
      toUri in interface FileObject
      Returns:
      the URI for this file object.