Class RelativeFile

java.lang.Object
com.android.builder.files.RelativeFile

public class RelativeFile extends Object
Representation of a file with respect to a base directory. A RelativeFile contains information on the file, the base directory and the relative path from the base directory to the file. The relative path is kept in OS independent form with sub directories separated by slashes.

Neither the file nor the base need to exist. They are treated as abstract paths.

  • Field Details

  • Constructor Details

    • RelativeFile

      public RelativeFile(@NonNull File base, @NonNull File file)
      Creates a new relative file.
      Parameters:
      base - the base directory.
      file - the file, must not be the same as the base directory and must be located inside base
    • RelativeFile

      public RelativeFile(@NonNull File base, @NonNull String relativePath)
      Creates a new relative file.
      Parameters:
      base - the base jar.
      relativePath - the relative path to the file.
  • Method Details

    • fileInDirectory

      public static RelativeFile fileInDirectory(@NonNull String relativePath, @NonNull File file)
    • getBase

      @NonNull public File getBase()
      Obtains the base directory or jar.

      Only applicable when getType() == RelativeFile.Type.JAR

      Returns:
      the base directory or jar as provided when created the object
    • getRelativePath

      @NonNull public String getRelativePath()
      Obtains the OS independent path. The general contract of the normalized relative path is that by replacing the slashes by file separators in the relative path and appending it to the base directory's path, the resulting path is the file's path
      Returns:
      the normalized path, separated by slashes; directories have a terminating slash
    • getType

      @NonNull public RelativeFile.Type getType()
    • getFile

      @NonNull public File getFile()
      Returns the actual file from the directory.

      Only applicable when getType() == RelativeFile.Type.DIRECTORY

      Returns:
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object