ResourceUtils
Code IndexAdd Codota to your IDE (free)

Best code snippets using org.apache.tools.ant.util.ResourceUtils(Showing top 15 results out of 315)

origin: org.apache.ant/ant

/**
 * Calls File.setLastModified(long time). Originally written to
 * to dynamically bind to that call on Java1.2+.
 *
 * @param file the file whose modified time is to be set
 * @param time the time to which the last modified time is to be set.
 *             if this is -1, the current time is used.
 */
public void setFileLastModified(File file, long time) {
  ResourceUtils.setLastModified(new FileResource(file), time);
}
origin: org.apache.ant/ant

private static Reader filterWith(Project project, String encoding,
  Vector<FilterChain> filterChains, InputStream input) {
  Reader r = new InputStreamReader(input, charsetFor(encoding));
  if (filterChains != null && !filterChains.isEmpty()) {
    final ChainReaderHelper crh = new ChainReaderHelper();
    crh.setBufferSize(FileUtils.BUF_SIZE);
    crh.setPrimaryReader(r);
    crh.setFilterChains(filterChains);
    crh.setProject(project);
    r = crh.getAssembledReader();
  }
  return new BufferedReader(r);
}
origin: org.apache.ant/ant

private static void log(final Project project, final String message) {
  log(project, message, Project.MSG_VERBOSE);
}
origin: org.apache.ant/ant

/**
 * Compare two Resources by content.
 * @param foo the first Resource.
 * @param bar the second Resource.
 * @return a negative integer, zero, or a positive integer as the first
 *         argument is less than, equal to, or greater than the second.
 * @throws BuildException if I/O errors occur.
 * @see org.apache.tools.ant.util.ResourceUtils#compareContent(Resource, Resource, boolean)
 */
protected int resourceCompare(Resource foo, Resource bar) {
  try {
    return ResourceUtils.compareContent(foo, bar, !binary);
  } catch (IOException e) {
    throw new BuildException(e);
  }
}
origin: org.apache.ant/ant

/**
 * Convenience method to copy content from one Resource to another.
 * No filtering is performed.
 *
 * @param source the Resource to copy from.
 *                   Must not be <code>null</code>.
 * @param dest   the Resource to copy to.
 *                 Must not be <code>null</code>.
 *
 * @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);
}
origin: org.apache.ant/ant

/**
 * Convenience method to copy content from one Resource to another.
 * No filtering is performed.
 *
 * @param source the Resource to copy from.
 *                   Must not be <code>null</code>.
 * @param dest   the Resource to copy to.
 *                 Must not be <code>null</code>.
 * @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);
}
origin: org.apache.ant/ant

private static void copyUsingStreams(final Resource source, final Resource dest,
                   final boolean append, final Project project)
  throws IOException {
  if (areSame(source, dest)) {
    // copying the "same" file to itself will corrupt the file, so we skip it
    log(project, "Skipping (self) copy of " + source +  " to " + dest);
    return;
  }
  try (InputStream in = source.getInputStream();
     OutputStream out = getOutputStream(dest, append, project)) {
    final byte[] buffer = new byte[FileUtils.BUF_SIZE];
    int count = 0;
    do {
      out.write(buffer, 0, count);
      count = in.read(buffer, 0, buffer.length);
    } while (count != -1);
  }
}
origin: org.apache.ant/ant

/**
 * Does the work.
 *
 * @exception BuildException if something goes wrong with the build
 */
public void execute() throws BuildException {
  final String msg = "".equals(message) ? StringUtils.LINE_SEP : message;
  try {
    ResourceUtils
        .copyResource(new StringResource(msg), output == null
               ? new LogOutputResource(this, logLevel)
               : output,
               null, null, false, false, append, null,
               "".equals(encoding) ? null : encoding,
               getProject(), force);
  } catch (IOException ioe) {
    throw new BuildException(ioe, getLocation());
  }
}
origin: org.apache.ant/ant

/**
 * Tells which sources should be reprocessed based on the
 * last modification date of targets.
 * @param logTo where to send (more or less) interesting output.
 * @param source ResourceCollection.
 * @param mapper filename mapper indicating how to find the target Resources.
 * @param targets object able to map a relative path as a Resource.
 * @param granularity The number of milliseconds leeway to give
 * before deciding a target is out of date.
 * @return ResourceCollection.
 * @since Ant 1.7
 */
public static ResourceCollection selectOutOfDateSources(final ProjectComponent logTo,
                            final ResourceCollection source,
                            final FileNameMapper mapper,
                            final ResourceFactory targets,
                            final long granularity) {
  logFuture(logTo, source, granularity);
  return selectSources(logTo, source, mapper, targets,
    sr -> target -> SelectorUtils.isOutOfDate(sr, target, granularity));
}
origin: org.apache.ant/ant

/**
 * Tells which source files should be reprocessed based on the
 * last modification date of target files.
 * @param logTo where to send (more or less) interesting output.
 * @param source array of resources bearing relative path and last
 * modification date.
 * @param mapper filename mapper indicating how to find the target
 * files.
 * @param targets object able to map as a resource a relative path
 * at <b>destination</b>.
 * @return array containing the source files which need to be
 * copied or processed, because the targets are out of date or do
 * not exist.
 */
public static Resource[] selectOutOfDateSources(final ProjectComponent logTo,
                        final Resource[] source,
                        final FileNameMapper mapper,
                        final ResourceFactory targets) {
  return selectOutOfDateSources(logTo, source, mapper, targets,
                 FILE_UTILS.getFileTimestampGranularity());
}
origin: org.apache.ant/ant

private Resource[] selectOutOfDateResources(final Resource[] initial,
                      final FileNameMapper mapper) {
  final Resource[] rs = selectFileResources(initial);
  Resource[] result =
    ResourceUtils.selectOutOfDateSources(this, rs, mapper,
                       getZipScanner(),
                       ZIP_FILE_TIMESTAMP_GRANULARITY);
  if (!doFilesonly) {
    final Union u = new Union();
    u.addAll(Arrays.asList(selectDirectoryResources(initial)));
    final ResourceCollection rc =
      ResourceUtils.selectSources(this, u, mapper,
                    getZipScanner(),
                    MISSING_DIR_PROVIDER);
    if (!rc.isEmpty()) {
      final List<Resource> newer = new ArrayList<>();
      newer.addAll(Arrays.asList(((Union) rc).listResources()));
      newer.addAll(Arrays.asList(result));
      result = newer.toArray(result);
    }
  }
  return result;
}
origin: org.apache.ant/ant

/**
 * Styles all existing resources.
 *
 * @param stylesheet style sheet to use
 * @since Ant 1.7
 */
private void processResources(final Resource stylesheet) {
  for (final Resource r : resources) {
    if (!r.isExists()) {
      continue;
    }
    File base = baseDir;
    String name = r.getName();
    final FileProvider fp = r.as(FileProvider.class);
    if (fp != null) {
      final FileResource f = ResourceUtils.asFileResource(fp);
      base = f.getBaseDir();
      if (base == null) {
        name = f.getFile().getAbsolutePath();
      }
    }
    process(base, name, destDir, stylesheet);
  }
}
origin: org.apache.ant/ant

/**
 * Execute the concat task.
 */
@Override
public void execute() {
  validate();
  if (binary && dest == null) {
    throw new BuildException(
      "dest|destfile attribute is required for binary concatenation");
  }
  ResourceCollection c = getResources();
  if (isUpToDate(c)) {
    log(dest + " is up-to-date.", Project.MSG_VERBOSE);
    return;
  }
  if (c.isEmpty() && ignoreEmpty) {
    return;
  }
  try {
    //most of these are defaulted because the concat-as-a-resource code hijacks a lot:
    ResourceUtils.copyResource(new ConcatResource(c), dest == null
                  ? new LogOutputResource(this, Project.MSG_WARN)
                  : dest,
                  null, null, true, false, append, null,
                  null, getProject(), force);
  } catch (IOException e) {
    throw new BuildException("error concatenating content to " + dest, e);
  }
}
origin: org.apache.ant/ant

private static void copyUsingFileChannels(final File sourceFile,
                     final File destFile, final Project project)
  throws IOException {
  if (FileUtils.getFileUtils().areSame(sourceFile, destFile)) {
    // copying the "same" file to itself will corrupt the file, so we skip it
    log(project, "Skipping (self) copy of " + sourceFile +  " to " + destFile);
    return;
  }
  final File parent = destFile.getParentFile();
  if (parent != null && !parent.isDirectory()
    && !(parent.mkdirs() || parent.isDirectory())) {
    throw new IOException("failed to create the parent directory"
               + " for " + destFile);
  }
  try (FileChannel srcChannel =
    FileChannel.open(sourceFile.toPath(), StandardOpenOption.READ);
      FileChannel destChannel = FileChannel.open(destFile.toPath(),
        StandardOpenOption.CREATE,
        StandardOpenOption.TRUNCATE_EXISTING,
        StandardOpenOption.WRITE)) {
    long position = 0;
    final long count = srcChannel.size();
    while (position < count) {
      final long chunk =
        Math.min(MAX_IO_CHUNK_SIZE, count - position);
      position +=
        destChannel.transferFrom(srcChannel, position, chunk);
    }
  }
}
origin: org.apache.ant/ant

/**
 * Compares the contents of two files.
 *
 * @param f1 the file whose content is to be compared.
 * @param f2 the other file whose content is to be compared.
 * @param textfile true if the file is to be treated as a text file and
 *        differences in kind of line break are to be ignored.
 *
 * @return true if the content of the files is the same.
 *
 * @throws IOException if the files cannot be read.
 * @since Ant 1.6.3
 */
public boolean contentEquals(File f1, File f2, boolean textfile) throws IOException {
  return ResourceUtils.contentEquals(new FileResource(f1), new FileResource(f2), textfile);
}
org.apache.tools.ant.utilResourceUtils

Javadoc

This class provides utility methods to process Resources.

Most used methods

  • copyResource
    Convenience method to copy content from one Resource to another specifying whether token filtering m
  • asFileResource
    Convenience method to turn any fileProvider into a basic FileResource with the file's immediate pare
  • selectOutOfDateSources
    Tells which source files should be reprocessed based on the last modification date of target files.
  • areSame
  • binaryCompare
    Binary compares the contents of two Resources. simple but sub-optimal comparison algorithm. written
  • charsetFor
  • compareContent
    Compare the content of two Resources. A nonexistent Resource's content is "less than" that of an exi
  • contentEquals
    Compares the contents of two Resources.
  • copyUsingFileChannels
  • copyUsingStreams
  • copyWithFilterChainsOrTranscoding
  • copyWithFilterSets
  • copyWithFilterChainsOrTranscoding,
  • copyWithFilterSets,
  • filterWith,
  • getOutputStream,
  • log,
  • logFuture,
  • selectSources,
  • setLastModified,
  • textCompare

Popular classes and methods

  • setRequestProperty (URLConnection)
    Sets the value of the specified request header field. The value will only be used by the current URL
  • getSharedPreferences (Context)
  • addToBackStack (FragmentTransaction)
  • Kernel (java.awt.image)
  • FileReader (java.io)
    A specialized Reader that reads from a file in the file system. All read requests made by calling me
  • Proxy (java.net)
    This class represents a proxy setting, typically a type (http, socks) and a socket address. A Proxy
  • SecureRandom (java.security)
    This class generates cryptographically secure pseudo-random numbers. It is best to invoke SecureRand
  • ThreadPoolExecutor (java.util.concurrent)
    An ExecutorService that executes each submitted task using one of possibly several pooled threads, n
  • Notification (javax.management)
    Notifications are events emitted by NotificationEmitters
  • JLabel (javax.swing)

For IntelliJ IDEA,
Android Studio or Eclipse

  • Codota IntelliJ IDEA pluginCodota Android Studio pluginCode IndexSign in
  • EnterpriseFAQAboutContact Us
  • Terms of usePrivacy policyCodeboxFind Usages
Add Codota to your IDE (free)