Package org.apache.tools.ant.util

# Class ResourceUtils

java.lang.Object
org.apache.tools.ant.util.ResourceUtils

    public class ResourceUtils
    extends java.lang.Object

This class provides utility methods to process Resources.

Since:
  Ant 1.5.2

- ## Nested Class Summary

  Nested Classes
  Modifier and Type | Class | Description
  --- | --- | ---
  `static class` | `ResourceUtils.ReadOnlyTargetFileException` |
  `static interface` | `ResourceUtils.ResourceSelectorProvider` |

- ## Field Summary

  Fields
  Modifier and Type | Field | Description
  --- | --- | ---
  `static java.lang.String` | `ISO_8859_1` | Deprecated. use StandardCharsets.ISO_8859_1

- ## Constructor Summary

  Constructors
  Constructor | Description
  --- | ---
  `ResourceUtils()` |

- ## Method Summary

  Modifier and Type | Method | Description
  --- | --- | ---
  `static FileResource` | `asFileResource​(FileProvider fileProvider)` | Convenience method to turn any fileProvider into a basic FileResource with the file's immediate parent as the basedir, for tasks that need one.
  `static int` | `compareContent​(Resource r1, Resource r2, boolean text)` | Compare the content of two Resources.
  `static boolean` | `contentEquals​(Resource r1, Resource r2, boolean text)` | Compares the contents of two Resources.
  `static void` | `copyResource​(Resource source, Resource dest)` | Convenience method to copy content from one Resource to another.
  `static void` | `copyResource​(Resource source, Resource dest, Project project)` | Convenience method to copy content from one Resource to another.
  `static void` | `copyResource​(Resource source, Resource dest, FilterSetCollection filters, java.util.Vector<FilterChain> filterChains, boolean overwrite, boolean preserveLastModified, boolean append, java.lang.String inputEncoding, java.lang.String outputEncoding, Project project)` | Convenience method to copy content from one Resource to another specifying whether token filtering must be used, whether filter chains must be used, whether newer destination files may be overwritten and whether the last modified time of `dest` file should be made equal to the last modified time of `source`.
  `static void` | `copyResource​(Resource source, Resource dest, FilterSetCollection filters, java.util.Vector<FilterChain> filterChains, boolean overwrite, boolean preserveLastModified, boolean append, java.lang.String inputEncoding, java.lang.String outputEncoding, Project project, boolean force)` | Convenience method to copy content from one Resource to another specifying whether token filtering must be used, whether filter chains must be used, whether newer destination files may be overwritten and whether the last modified time of `dest` file should be made equal to the last modified time of `source`.
  `static void` | `copyResource​(Resource source, Resource dest, FilterSetCollection filters, java.util.Vector<FilterChain> filterChains, boolean overwrite, boolean preserveLastModified, java.lang.String inputEncoding, java.lang.String outputEncoding, Project project)` | Convenience method to copy content from one Resource to another specifying whether token filtering must be used, whether filter chains must be used, whether newer destination files may be overwritten and whether the last modified time of `dest` file should be made equal to the last modified time of `source`.
  `static Resource[]` | `selectOutOfDateSources​(ProjectComponent logTo, Resource[] source, FileNameMapper mapper, ResourceFactory targets)` | Tells which source files should be reprocessed based on the last modification date of target files.
  `static Resource[]` | `selectOutOfDateSources​(ProjectComponent logTo, Resource[] source, FileNameMapper mapper, ResourceFactory targets, long granularity)` | Tells which source files should be reprocessed based on the last modification date of target files.
  `static ResourceCollection` | `selectOutOfDateSources​(ProjectComponent logTo, ResourceCollection source, FileNameMapper mapper, ResourceFactory targets, long granularity)` | Tells which sources should be reprocessed based on the last modification date of targets.
  `static ResourceCollection` | `selectSources​(ProjectComponent logTo, ResourceCollection source, FileNameMapper mapper, ResourceFactory targets, ResourceUtils.ResourceSelectorProvider selector)` | Tells which sources should be reprocessed because the given selector selects at least one target.
  `static void` | `setLastModified​(Touchable t, long time)` | Set the last modified time of an object implementing org.apache.tools.ant.types.resources.Touchable .

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### ISO_8859_1

    @Deprecated public static final java.lang.String ISO_8859_1
    Deprecated.
    use StandardCharsets.ISO_8859_1
    Name of charset "ISO Latin Alphabet No. 1, a.k.a. ISO-LATIN-1".
    Since:
      Ant 1.8.1
    See Also:
      Constant Field Values

- ## Constructor Details

  - ### ResourceUtils

    public ResourceUtils()

- ## Method Details

  - ### selectOutOfDateSources

    public static Resource[] selectOutOfDateSources​(ProjectComponent logTo, Resource[] source, FileNameMapper mapper, ResourceFactory targets)
    Tells which source files should be reprocessed based on the last modification date of target files.
    Parameters:
      `logTo` - where to send (more or less) interesting output.
      `source` - array of resources bearing relative path and last modification date.
      `mapper` - filename mapper indicating how to find the target files.
      `targets` - object able to map as a resource a relative path at destination.
    Returns:
      array containing the source files which need to be copied or processed, because the targets are out of date or do not exist.

  - ### selectOutOfDateSources

    public static Resource[] selectOutOfDateSources​(ProjectComponent logTo, Resource[] source, FileNameMapper mapper, ResourceFactory targets, long granularity)
    Tells which source files should be reprocessed based on the last modification date of target files.
    Parameters:
      `logTo` - where to send (more or less) interesting output.
      `source` - array of resources bearing relative path and last modification date.
      `mapper` - filename mapper indicating how to find the target files.
      `targets` - object able to map as a resource a relative path at destination.
      `granularity` - The number of milliseconds leeway to give before deciding a target is out of date.
    Returns:
      array containing the source files which need to be copied or processed, because the targets are out of date or do not exist.
    Since:
      Ant 1.6.2

  - ### selectOutOfDateSources

    public static ResourceCollection selectOutOfDateSources​(ProjectComponent logTo, ResourceCollection source, FileNameMapper mapper, ResourceFactory targets, long granularity)
    Tells which sources should be reprocessed based on the last modification date of targets.
    Parameters:
      `logTo` - where to send (more or less) interesting output.
      `source` - ResourceCollection.
      `mapper` - filename mapper indicating how to find the target Resources.
      `targets` - object able to map a relative path as a Resource.
      `granularity` - The number of milliseconds leeway to give before deciding a target is out of date.
    Returns:
      ResourceCollection.
    Since:
      Ant 1.7

  - ### selectSources

    public static ResourceCollection selectSources​(ProjectComponent logTo, ResourceCollection source, FileNameMapper mapper, ResourceFactory targets, ResourceUtils.ResourceSelectorProvider selector)
    Tells which sources should be reprocessed because the given selector selects at least one target.
    Parameters:
      `logTo` - where to send (more or less) interesting output.
      `source` - ResourceCollection.
      `mapper` - filename mapper indicating how to find the target Resources.
      `targets` - object able to map a relative path as a Resource.
      `selector` - returns a selector that is applied to target files. If it selects at least one target the source will be added to the returned collection.
    Returns:
      ResourceCollection.
    Since:
      Ant 1.8.0

  - ### copyResource

    public static void copyResource​(Resource source, Resource dest) throws java.io.IOException
    Convenience method to copy content from one Resource to another. No filtering is performed.
    Parameters:
      `source` - the Resource to copy from. Must not be `null`.
      `dest` - the Resource to copy to. Must not be `null`.
    Throws:
      `java.io.IOException` - if the copying fails.
    Since:
      Ant 1.7

  - ### copyResource

    public static void copyResource​(Resource source, Resource dest, Project project) throws java.io.IOException
    Convenience method to copy content from one Resource to another. No filtering is performed.
    Parameters:
      `source` - the Resource to copy from. Must not be `null`.
      `dest` - the Resource to copy to. Must not be `null`.
      `project` - the project instance.
    Throws:
      `java.io.IOException` - if the copying fails.
    Since:
      Ant 1.7

  - ### copyResource

    public static void copyResource​(Resource source, Resource dest, FilterSetCollection filters, java.util.Vector<FilterChain> filterChains, boolean overwrite, boolean preserveLastModified, java.lang.String inputEncoding, java.lang.String outputEncoding, Project project) throws java.io.IOException
    Convenience method to copy content from one Resource to another specifying whether token filtering must be used, whether filter chains must be used, whether newer destination files may be overwritten and whether the last modified time of `dest` file should be made equal to the last modified time of `source`.
    Parameters:
      `source` - the Resource to copy from. Must not be `null`.
      `dest` - the Resource to copy to. Must not be `null`.
      `filters` - the collection of filters to apply to this copy.
      `filterChains` - filterChains to apply during the copy.
      `overwrite` - Whether or not the destination Resource should be overwritten if it already exists.
      `preserveLastModified` - Whether or not the last modified time of the destination Resource should be set to that of the source.
      `inputEncoding` - the encoding used to read the files.
      `outputEncoding` - the encoding used to write the files.
      `project` - the project instance.
    Throws:
      `java.io.IOException` - if the copying fails.
    Since:
      Ant 1.7

  - ### copyResource

    public static void copyResource​(Resource source, Resource dest, FilterSetCollection filters, java.util.Vector<FilterChain> filterChains, boolean overwrite, boolean preserveLastModified, boolean append, java.lang.String inputEncoding, java.lang.String outputEncoding, Project project) throws java.io.IOException
    Convenience method to copy content from one Resource to another specifying whether token filtering must be used, whether filter chains must be used, whether newer destination files may be overwritten and whether the last modified time of `dest` file should be made equal to the last modified time of `source`.
    Parameters:
      `source` - the Resource to copy from. Must not be `null`.
      `dest` - the Resource to copy to. Must not be `null`.
      `filters` - the collection of filters to apply to this copy.
      `filterChains` - filterChains to apply during the copy.
      `overwrite` - Whether or not the destination Resource should be overwritten if it already exists.
      `preserveLastModified` - Whether or not the last modified time of the destination Resource should be set to that of the source.
      `append` - Whether to append to an Appendable Resource.
      `inputEncoding` - the encoding used to read the files.
      `outputEncoding` - the encoding used to write the files.
      `project` - the project instance.
    Throws:
      `java.io.IOException` - if the copying fails.
    Since:
      Ant 1.8

  - ### copyResource

    public static void copyResource​(Resource source, Resource dest, FilterSetCollection filters, java.util.Vector<FilterChain> filterChains, boolean overwrite, boolean preserveLastModified, boolean append, java.lang.String inputEncoding, java.lang.String outputEncoding, Project project, boolean force) throws java.io.IOException
    Convenience method to copy content from one Resource to another specifying whether token filtering must be used, whether filter chains must be used, whether newer destination files may be overwritten and whether the last modified time of `dest` file should be made equal to the last modified time of `source`.
    Parameters:
      `source` - the Resource to copy from. Must not be `null`.
      `dest` - the Resource to copy to. Must not be `null`.
      `filters` - the collection of filters to apply to this copy.
      `filterChains` - filterChains to apply during the copy.
      `overwrite` - Whether or not the destination Resource should be overwritten if it already exists.
      `preserveLastModified` - Whether or not the last modified time of the destination Resource should be set to that of the source.
      `append` - Whether to append to an Appendable Resource.
      `inputEncoding` - the encoding used to read the files.
      `outputEncoding` - the encoding used to write the files.
      `project` - the project instance.
      `force` - whether read-only target files will be overwritten
    Throws:
      `java.io.IOException` - if the copying fails.
    Since:
      Ant 1.8.2

  - ### setLastModified

    public static void setLastModified​(Touchable t, long time)
    Set the last modified time of an object implementing org.apache.tools.ant.types.resources.Touchable .
    Parameters:
      `t` - the Touchable whose modified time is to be set.
      `time` - the time to which the last modified time is to be set. if this is -1, the current time is used.
    Since:
      Ant 1.7

  - ### contentEquals

    public static boolean contentEquals​(Resource r1, Resource r2, boolean text) throws java.io.IOException
    Compares the contents of two Resources.
    Parameters:
      `r1` - the Resource whose content is to be compared.
      `r2` - the other Resource whose content is to be compared.
      `text` - true if the content is to be treated as text and differences in kind of line break are to be ignored.
    Returns:
      true if the content of the Resources is the same.
    Throws:
      `java.io.IOException` - if the Resources cannot be read.
    Since:
      Ant 1.7

  - ### compareContent

    public static int compareContent​(Resource r1, Resource r2, boolean text) throws java.io.IOException
    Compare the content of two Resources. A nonexistent Resource's content is "less than" that of an existing Resource; a directory-type Resource's content is "less than" that of a file-type Resource.
    Parameters:
      `r1` - the Resource whose content is to be compared.
      `r2` - the other Resource whose content is to be compared.
      `text` - true if the content is to be treated as text and differences in kind of line break are to be ignored.
    Returns:
      a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
    Throws:
      `java.io.IOException` - if the Resources cannot be read.
    Since:
      Ant 1.7

  - ### asFileResource

    public static FileResource asFileResource​(FileProvider fileProvider)
    Convenience method to turn any fileProvider into a basic FileResource with the file's immediate parent as the basedir, for tasks that need one.
    Parameters:
      `fileProvider` - input
    Returns:
      fileProvider if it is a FileResource instance, or a new FileResource with fileProvider's file.
    Since:
      Ant 1.8