org.apache.tools.ant.util.FileUtils.getFileUtils()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(9.4k)|赞(0)|评价(0)|浏览(99)

本文整理了Java中org.apache.tools.ant.util.FileUtils.getFileUtils()方法的一些代码示例,展示了FileUtils.getFileUtils()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtils.getFileUtils()方法的具体详情如下:
包路径:org.apache.tools.ant.util.FileUtils
类名称:FileUtils
方法名:getFileUtils

FileUtils.getFileUtils介绍

[英]Method to retrieve The FileUtils, which is shared by all users of this method.
[中]方法检索FileUtils,该文件由此方法的所有用户共享。

代码示例

代码示例来源:origin: org.apache.ant/ant

/**
 * convert a file to a URL;
 *
 * @param fileToConvert File
 * @return the file converted to a URL
 */
private String toURL(File fileToConvert) {
  //create the URL
  //ant equivalent of  fileToConvert.toURI().toURL().toExternalForm();
  return FileUtils.getFileUtils().toURI(fileToConvert.getAbsolutePath());
}

代码示例来源:origin: org.apache.ant/ant

/**
 * Copy task constructor.
 */
public Copy() {
  fileUtils = FileUtils.getFileUtils();
  granularity = fileUtils.getFileTimestampGranularity();
}

代码示例来源:origin: jenkinsci/jenkins

sealBase = new URL(FileUtils.getFileUtils().toURI(container.getAbsolutePath()));
} catch (MalformedURLException e) {

代码示例来源:origin: apache/groovy

private void createNewArgs(String txt) throws IOException {
  final String[] args = cmdline.getCommandline();
  // Temporary file - delete on exit, create (assured unique name).
  final File tempFile = FileUtils.getFileUtils().createTempFile(PREFIX, SUFFIX, null, true, true);
  final String[] commandline = new String[args.length + 1];
  ResourceGroovyMethods.write(tempFile, txt);
  commandline[0] = tempFile.getCanonicalPath();
  System.arraycopy(args, 0, commandline, 1, args.length);
  super.clearArgs();
  for (String arg : commandline) {
    final Commandline.Argument argument = super.createArg();
    argument.setValue(arg);
  }
}

代码示例来源:origin: org.apache.ant/ant

/**
 * Finds modules in the expanded modulesourcepath entry.
 * @param root the project root
 * @param pathToModule the path to modules folder
 * @param pathInModule the path in module to source folder
 * @param collector the map to put modules into
 * @since 1.9.7
 */
private static void findModules(
  final File root,
  final String pathToModule,
  final String pathInModule,
  final Map<String,Collection<File>> collector) {
  final File f = FileUtils.getFileUtils().resolveFile(root, pathToModule);
  if (!f.isDirectory()) {
    return;
  }
  for (File module : f.listFiles(File::isDirectory)) {
    final String moduleName = module.getName();
    final File moduleSourceRoot = pathInModule == null
        ? module : new File(module, pathInModule);
    Collection<File> moduleRoots = collector.computeIfAbsent(moduleName, k -> new ArrayList<>());
    moduleRoots.add(moduleSourceRoot);
  }
}

代码示例来源:origin: org.apache.ant/ant

private void writeFile() throws BuildException {
  // Write to RAM first, as an OOME could otherwise produce a truncated file:
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  try {
    properties.store(baos, comment);
  } catch (IOException x) { // should not happen
    throw new BuildException(x, getLocation());
  }
  try {
    try (OutputStream os = Files.newOutputStream(propertyfile.toPath())) {
      os.write(baos.toByteArray());
    } catch (IOException x) { // possibly corrupt
      FileUtils.getFileUtils().tryHardToDelete(propertyfile);
      throw x;
    }
  } catch (IOException x) { // opening, writing, or closing
    throw new BuildException(x, getLocation());
  }
}

代码示例来源:origin: org.apache.ant/ant

/**
 * Resolve a filename with Project's help - if we know one that is.
 */
private static File resolveFile(Project project, String relativeName) {
  return FileUtils.getFileUtils().resolveFile(
    (project == null) ? null : project.getBaseDir(), relativeName);
}

代码示例来源:origin: org.apache.ant/ant

/**
 * get the URL of the schema
 * @return a URL to the schema
 * @throws BuildException if not
 */
public String getSchemaLocationURL() {
  boolean hasFile = file != null;
  boolean hasURL = isSet(url);
  //error if both are empty, or both are set
  if (!hasFile && !hasURL) {
    throw new BuildException(ERROR_NO_LOCATION + namespace);
  }
  if (hasFile && hasURL) {
    throw new BuildException(ERROR_TWO_LOCATIONS + namespace);
  }
  String schema = url;
  if (hasFile) {
    if (!file.exists()) {
      throw new BuildException(ERROR_NO_FILE + file);
    }
    try {
      schema = FileUtils.getFileUtils().getFileURL(file).toString();
    } catch (MalformedURLException e) {
      //this is almost implausible, but required handling
      throw new BuildException(ERROR_NO_URL_REPRESENTATION + file, e);
    }
  }
  return schema;
}

代码示例来源: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

/**
 * sets the build file to which the XML context belongs
 * @param buildFile  ant build file
 */
public void setBuildFile(File buildFile) {
  this.buildFile = buildFile;
  if (buildFile != null) {
    this.buildFileParent = new File(buildFile.getParent());
    implicitTarget.setLocation(new Location(buildFile.getAbsolutePath()));
    try {
      setBuildFile(FileUtils.getFileUtils().getFileURL(buildFile));
    } catch (MalformedURLException ex) {
      throw new BuildException(ex);
    }
  } else {
    this.buildFileParent = null;
  }
}

代码示例来源:origin: org.apache.ant/ant

/**
 * Is the archive up to date in relationship to a list of files.
 * @param r the files to check
 * @return true if the archive is up to date.
 * @since Ant 1.7
 */
protected boolean archiveIsUpToDate(final Resource r) {
  return SelectorUtils.isOutOfDate(new FileResource(tarFile), r,
                   FileUtils.getFileUtils()
                   .getFileTimestampGranularity());
}

代码示例来源:origin: org.apache.ant/ant

return FileUtils.getFileUtils().getFileURL(file);
} catch (Exception ex) {
  message =

代码示例来源:origin: org.apache.ant/ant

/**
 * The heart of the matter. This is where the selector gets to decide
 * on the inclusion of a file in a particular fileset.
 *
 * @param basedir the base directory the scan is being done from
 * @param filename is the name of the file to check
 * @param file is a java.io.File object the selector can use
 * @return whether the file should be selected or not
 */
@Override
public boolean isSelected(final File basedir, final String filename, final File file) {
  // throw BuildException on error
  validate();
  // Determine file whose existence is to be checked
  final String[] destfiles = map.mapFileName(filename);
  // If filename does not match the To attribute of the mapper
  // then filter it out of the files we are considering
  if (destfiles == null) {
    return false;
  }
  // Sanity check
  if (destfiles.length != 1 || destfiles[0] == null) {
    throw new BuildException("Invalid destination file results for "
        + targetdir + " with filename " + filename);
  }
  final String destname = destfiles[0];
  final File destfile = FileUtils.getFileUtils().resolveFile(targetdir, destname);
  return destfile.exists() == destmustexist;
}

代码示例来源:origin: org.apache.ant/ant

String url = systemid;
if (url.startsWith("file:")) {
  url = FileUtils.getFileUtils().fromURI(url);

代码示例来源:origin: org.apache.ant/ant

final FileUtils fileUtils = FileUtils.getFileUtils();
dir = fileUtils.normalize(dir.getAbsolutePath());

代码示例来源:origin: org.apache.ant/ant

private void collectFileListFromModulePath() {
  final FileUtils fu = FileUtils.getFileUtils();
  for (String pathElement : moduleSourcepath.list()) {
    boolean valid = false;
    for (Map.Entry<String, Collection<File>> modules : resolveModuleSourcePathElement(
      getProject().getBaseDir(), pathElement).entrySet()) {
      final String moduleName = modules.getKey();
      for (File srcDir : modules.getValue()) {
        if (srcDir.exists()) {
          valid = true;
          final DirectoryScanner ds = getDirectoryScanner(srcDir);
          final String[] files = ds.getIncludedFiles();
          scanDir(srcDir, fu.resolveFile(destDir, moduleName), files);
        }
      }
    }
    if (!valid) {
      throw new BuildException("modulesourcepath \""
                   + pathElement
                   + "\" does not exist!", getLocation());
    }
  }
}

代码示例来源:origin: org.apache.ant/ant

BufferedWriter out = null;
try {
  tmpFile = FileUtils.getFileUtils().createTempFile("jikes",
      "tmp", null, false, true);
  out = new BufferedWriter(new FileWriter(tmpFile));

代码示例来源:origin: org.apache.ant/ant

private static boolean areSame(final Resource resource1, final Resource resource2) throws IOException {
  if (resource1 == null || resource2 == null) {
    return false;
  }
  final FileProvider fileResource1 = resource1.as(FileProvider.class);
  final FileProvider fileResource2 = resource2.as(FileProvider.class);
  return fileResource1 != null && fileResource2 != null
      && FileUtils.getFileUtils().areSame(fileResource1.getFile(), fileResource2.getFile());
}

代码示例来源:origin: org.apache.ant/ant

/**
 * @since Ant 1.7
 */
private void expandStream(String name, InputStream stream, File dir)
  throws IOException {
  try (TarInputStream tis = new TarInputStream(
    compression.decompress(name, new BufferedInputStream(stream)),
    getEncoding())) {
    log("Expanding: " + name + " into " + dir, Project.MSG_INFO);
    boolean empty = true;
    FileNameMapper mapper = getMapper();
    TarEntry te;
    while ((te = tis.getNextEntry()) != null) {
      empty = false;
      extractFile(FileUtils.getFileUtils(), null, dir, tis,
            te.getName(), te.getModTime(),
            te.isDirectory(), mapper);
    }
    if (empty && getFailOnEmptyArchive()) {
      throw new BuildException("archive '%s' is empty", name);
    }
    log("expand complete", Project.MSG_VERBOSE);
  }
}

代码示例来源:origin: org.apache.ant/ant

FileUtils fu = FileUtils.getFileUtils();
File tmpFile = fu.createTempFile("modified-", ".tmp", null, true, false);
Resource tmpResource = new FileResource(tmpFile);

相关文章