null.
* @param dest the Resource to copy to.
* Must not be null.
*
* @throws IOException if the copying fails.
*
* @since Ant 1.7
*/
public static void copyResource(final Resource source, final Resource dest) throws IOException {
copyResource(source, dest, null);
}
/**
* Convenience method to copy content from one Resource to another.
* No filtering is performed.
*
* @param source the Resource to copy from.
* Must not be null.
* @param dest the Resource to copy to.
* Must not be null.
* @param project the project instance.
*
* @throws IOException if the copying fails.
*
* @since Ant 1.7
*/
public static void copyResource(final Resource source, final Resource dest, final Project project)
throws IOException {
copyResource(source, dest, null, null, false,
false, null, null, project);
}
// CheckStyle:ParameterNumberCheck OFF - bc
/**
* 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.
*
* @param source the Resource to copy from.
* Must not be null.
* @param dest the Resource to copy to.
* Must not be null.
* @param filters the collection of filters to apply to this copy.
* @param filterChains filterChains to apply during the copy.
* @param overwrite Whether or not the destination Resource should be
* overwritten if it already exists.
* @param preserveLastModified Whether or not the last modified time of
* the destination Resource should be set to that
* of the source.
* @param inputEncoding the encoding used to read the files.
* @param outputEncoding the encoding used to write the files.
* @param project the project instance.
*
* @throws IOException if the copying fails.
*
* @since Ant 1.7
*/
public static void copyResource(final Resource source, final Resource dest,
final FilterSetCollection filters, final Vectordest file should be made
* equal to the last modified time of source.
*
* @param source the Resource to copy from.
* Must not be null.
* @param dest the Resource to copy to.
* Must not be null.
* @param filters the collection of filters to apply to this copy.
* @param filterChains filterChains to apply during the copy.
* @param overwrite Whether or not the destination Resource should be
* overwritten if it already exists.
* @param preserveLastModified Whether or not the last modified time of
* the destination Resource should be set to that
* of the source.
* @param append Whether to append to an Appendable Resource.
* @param inputEncoding the encoding used to read the files.
* @param outputEncoding the encoding used to write the files.
* @param project the project instance.
*
* @throws IOException if the copying fails.
*
* @since Ant 1.8
*/
public static void copyResource(final Resource source, final Resource dest,
final FilterSetCollection filters, final Vectordest file should be made
* equal to the last modified time of source.
*
* @param source the Resource to copy from.
* Must not be null.
* @param dest the Resource to copy to.
* Must not be null.
* @param filters the collection of filters to apply to this copy.
* @param filterChains filterChains to apply during the copy.
* @param overwrite Whether or not the destination Resource should be
* overwritten if it already exists.
* @param preserveLastModified Whether or not the last modified time of
* the destination Resource should be set to that
* of the source.
* @param append Whether to append to an Appendable Resource.
* @param inputEncoding the encoding used to read the files.
* @param outputEncoding the encoding used to write the files.
* @param project the project instance.
* @param force whether read-only target files will be overwritten
*
* @throws IOException if the copying fails.
*
* @since Ant 1.8.2
*/
public static void copyResource(final Resource source, final Resource dest,
final FilterSetCollection filters, final Vector* simple but sub-optimal comparison algorithm. written for working * rather than fast. Better would be a block read into buffers followed * by long comparisons apart from the final 1-7 bytes. *
* * @param r1 the Resource whose content is to be compared. * @param r2 the other Resource whose content is to be compared. * @return a negative integer, zero, or a positive integer as the first * argument is less than, equal to, or greater than the second. * @throws IOException if the Resources cannot be read. * @since Ant 1.7 */ private static int binaryCompare(final Resource r1, final Resource r2) throws IOException { try (InputStream in1 = new BufferedInputStream(r1.getInputStream()); InputStream in2 = new BufferedInputStream(r2.getInputStream())) { for (int b1 = in1.read(); b1 != -1; b1 = in1.read()) { final int b2 = in2.read(); if (b1 != b2) { return b1 > b2 ? 1 : -1; } } return in2.read() == -1 ? 0 : -1; } } /** * Text compares the contents of two Resources. * Ignores different kinds of line endings. * @param r1 the Resource whose content is to be compared. * @param r2 the other Resource whose content is to be compared. * @return a negative integer, zero, or a positive integer as the first * argument is less than, equal to, or greater than the second. * @throws IOException if the Resources cannot be read. * @since Ant 1.7 */ private static int textCompare(final Resource r1, final Resource r2) throws IOException { try (BufferedReader in1 = new BufferedReader(new InputStreamReader(r1.getInputStream())); BufferedReader in2 = new BufferedReader( new InputStreamReader(r2.getInputStream()))) { String expected = in1.readLine(); while (expected != null) { final String actual = in2.readLine(); if (!expected.equals(actual)) { if (actual == null) { return 1; } return expected.compareTo(actual); } expected = in1.readLine(); } return in2.readLine() == null ? 0 : -1; //NOSONAR } } /** * Log which Resources (if any) have been modified in the future. * @param logTo the ProjectComponent to do the logging. * @param rc the collection of Resources to check. * @param granularity the timestamp granularity to use. * @since Ant 1.7 */ private static void logFuture(final ProjectComponent logTo, final ResourceCollection rc, final long granularity) { final long now = System.currentTimeMillis() + granularity; final Date sel = new Date(); sel.setMillis(now); sel.setWhen(TimeComparison.AFTER); final Restrict future = new Restrict(); future.add(sel); future.add(rc); for (final Resource r : future) { logTo.log("Warning: " + r.getName() + " modified in the future.", Project.MSG_WARN); } } private static void copyWithFilterSets(final Resource source, final Resource dest, final FilterSetCollection filters, final Vector