本文整理了Java中org.apache.tools.ant.util.FileUtils
类的一些代码示例,展示了FileUtils
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtils
类的具体详情如下:
包路径:org.apache.tools.ant.util.FileUtils
类名称:FileUtils
[英]This class also encapsulates methods which allow Files to be referred to using abstract path names which are translated to native system file paths at runtime as well as copying files or setting their last modification time.
[中]此类还封装了一些方法,这些方法允许使用抽象路径名引用文件,这些抽象路径名在运行时转换为本机系统文件路径,还可以复制文件或设置其上次修改时间。
代码示例来源: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
/**
* Notify the <code>Redirector</code> that it is now okay to set any output
* and/or error properties.
*/
public void setProperties() {
synchronized (outMutex) {
FileUtils.close(baos);
}
synchronized (errMutex) {
FileUtils.close(errorBaos);
}
}
代码示例来源:origin: org.apache.ant/ant
/**
* Convenience method to copy a file from a source to a destination. No filtering is performed.
*
* @param sourceFile the file to copy from. Must not be <code>null</code>.
* @param destFile the file to copy to. Must not be <code>null</code>.
*
* @throws IOException if the copying fails.
*/
public void copyFile(File sourceFile, File destFile) throws IOException {
copyFile(sourceFile, destFile, null, false, false);
}
代码示例来源:origin: org.apache.ant/ant
/**
* Copy task constructor.
*/
public Copy() {
fileUtils = FileUtils.getFileUtils();
granularity = fileUtils.getFileTimestampGranularity();
}
代码示例来源: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
/**
* 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.wso2.carbon.commons/org.wso2.carbon.identity.user.store.configuration.deployer
String encFileName = absolutePath.substring(0, index + 1) + UserStoreConfigurationConstants.XML_EXTENSION;
OutputStream outputStream;
outputStream = new FileOutputStream(encFileName);
secondaryStoreDocument.serialize(outputStream);
FileUtils.delete(file);
代码示例来源:origin: maven/maven
throws IOException
File f = fileUtils.resolveFile( dest, entryName );
try
fos = new FileOutputStream( f );
fos.write( buffer, 0, length );
fos.close();
fos = null;
fileUtils.setFileLastModified( f, entryDate.getTime() );
代码示例来源:origin: com.github.goldin/maven-common
OutputStream outstream = null;
try {
File file = getProject().resolveFile(new File(dir, filename).getPath());
pdir.mkdirs();
outstream = new BufferedOutputStream(new FileOutputStream(file));
ftp.retrieveFile(resolveFile(filename), outstream);
skipped++;
} else {
throw new BuildException(s);
FTPFile[] remote = ftp.listFiles(resolveFile(filename));
if (remote.length > 0) {
FILE_UTILS.setFileLastModified(file,
remote[0].getTimestamp()
.getTime().getTime());
FileUtils.close(outstream);
代码示例来源:origin: org.codehaus.mojo/nbm-maven-plugin
a.putValue( "Class-Path", classPath );
a.remove( new Attributes.Name( "Maven-Class-Path" ) );
OutputStream os = new FileOutputStream( moduleFile );
try
FileUtils.getFileUtils().copyFile( jarFile, moduleFile, null, true, false );
FileUtils.getFileUtils().copyFile( source, target, null, true, false );
if ( externals != null && externals.contains(artifact.getGroupId() + ":" + artifact.getArtifactId())) // MNBMODULE-138
getLog().info( "Generating JavaHelp Index..." );
JHIndexer jhTask = (JHIndexer) antProject.createTask( "jhindexer" );
jhTask.setBasedir( b );
jhTask.setDb( p );
throw new MojoExecutionException( e.getMessage(), e );
Jar jar = (Jar) antProject.createTask( "jar" );
jar.setDestFile( new File( helpJarLocation, moduleJarName + ".jar" ) );
set = new FileSet();
throw new MojoExecutionException( e.getMessage(), e );
MakeListOfNBM makeTask = (MakeListOfNBM) antProject.createTask( "genlist" );
throw new MojoExecutionException( e.getMessage(), e );
代码示例来源:origin: org.ow2.jonas/bootstrap-ant
throw new BuildException("Replace: source file " + src.getPath() + " doesn't exist", getLocation());
File temp = fileUtils.createTempFile("rep", ".tmp", fileUtils.getParentFile(src));
temp.deleteOnExit();
try {
reader = encoding == null ? new FileReader(src) : new InputStreamReader(new FileInputStream(src), encoding);
writer = encoding == null ? new FileWriter(temp) : new OutputStreamWriter(new FileOutputStream(temp), encoding);
String buf = fileUtils.readFully(br);
if (buf == null) {
buf = "";
if (replacefilters.size() > 0) {
newString = processReplacefilters(newString, src.getPath());
Project tempProject = new Project();
Delete delete = new Delete();
delete.setProject(tempProject);
throw new BuildException("IOException in " + src + " - " + ioe.getClass().getName() + ":" + ioe.getMessage(), ioe,
getLocation());
} finally {
代码示例来源:origin: com.googlecode.jslint4java/jslint4java-ant
public void output(JSLintResult result) {
File f = new File(file, testFileName(result));
Writer w = null;
try {
w = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f), "UTF-8"));
if (form.header() != null) {
w.write(form.header());
}
w.write(form.format(result));
if (form.footer() != null) {
w.write(form.footer());
}
} catch (IOException e) {
throw new BuildException(e);
} finally {
FileUtils.close(w);
}
}
代码示例来源:origin: org.metaeffekt.dcc/dcc-commons
public static void writeToFile(Properties properties, File file, String comment) throws IOException {
// write to memory first to prevent other side-effects
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
properties.store(baos, comment);
} finally {
baos.close();
}
OutputStream os = new FileOutputStream(file);
try {
os.write(baos.toByteArray());
} catch (IOException ex) {
FileUtils.getFileUtils().tryHardToDelete(file);
throw ex;
} finally {
os.close();
}
}
代码示例来源:origin: org.apache.ant/ant
dir = getProject().getBaseDir();
newProject.setBaseDir(dir);
if (savedDir != null) {
newProject.setInheritedProperty(MagicNames.PROJECT_BASEDIR,
dir.getAbsolutePath());
File file = FILE_UTILS.resolveFile(dir, antFile);
antFile = file.getAbsolutePath();
+ (locals.isEmpty() ? "[default]" : locals.toString())
+ " in build file " + antFile, Project.MSG_VERBOSE);
newProject.setUserProperty(MagicNames.ANT_FILE, antFile);
throw new BuildException(
"%s task at the top level must not invoke its own build file.",
getTaskName());
if (locals.isEmpty()) {
String defaultTarget = newProject.getDefaultTarget();
if (defaultTarget != null) {
FileUtils.close(out);
代码示例来源:origin: org.apache.ant/ant
FilterChain fc = new FilterChain();
fc.add(filter);
fcv = new Vector<>(1);
fcv.add(fc);
File tmpFile = FILE_UTILS.createTempFile("fixcrlf", "", null, true, true);
try {
FILE_UTILS.copyFile(srcFile, tmpFile, null, fcv, true, false,
encoding, outputEncoding == null ? encoding : outputEncoding,
getProject());
destIsWrong = !FILE_UTILS.contentEquals(destFile, tmpFile);
log(destFile + (destIsWrong ? " is being written"
: " is not written, as the contents are identical"),
FILE_UTILS.rename(tmpFile, destFile);
if (preserveLastModified) {
log("preserved lastModified for " + destFile,
Project.MSG_DEBUG);
FILE_UTILS.setFileLastModified(destFile, lastModified);
throw new BuildException("error running fixcrlf on file " + srcFile, e);
} finally {
if (tmpFile != null && tmpFile.exists()) {
FILE_UTILS.tryHardToDelete(tmpFile);
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
super.execute();
try {
for (int i = 0; i < rcs.size(); i++) {
ResourceCollection rc = (ResourceCollection) rcs.elementAt(i);
Iterator<Resource> resources = rc.iterator();
while (resources.hasNext()) {
Resource r = (Resource) resources.next();
if (!r.isExists()) {
continue;
throw new BuildException("Unable to recognize the path separator for src file: " + file);
File specificDestinationFile = new File(destDir, specificFilePart);
if (specificFile.exists()) {
fileUtils.copyFile(specificFile, specificDestinationFile);
continue;
File generalFile = new File(licenseDir, generalFilePart);
if (generalFile.exists()) {
fileUtils.copyFile(generalFile, specificDestinationFile);
continue;
File moreGeneralFile = new File(licenseDir, moreGeneralFilePart);
if (moreGeneralFile.exists()) {
fileUtils.copyFile(moreGeneralFile, specificDestinationFile);
throw new BuildException(e);
代码示例来源:origin: org.apache.ant/ant
List<Transaction> savedTransaction = new Vector<>(transactions);
String savedSqlCommand = sqlCommand;
throw new BuildException("Source file " + srcFile
+ " is not a file!", getLocation());
OutputStream os = null;
FileProvider fp =
output.as(FileProvider.class);
if (fp != null) {
os = FileUtils.newOutputStream(fp.getFile().toPath(), append);
} else {
if (append) {
Appendable a =
output.as(Appendable.class);
if (a != null) {
os = a.getAppendOutputStream();
os = output.getOutputStream();
if (append) {
log("Ignoring append=true for non-appendable"
FileUtils.close(out);
FileUtils.close(getStatement());
} catch (SQLException ex) {
FileUtils.close(getConnection());
代码示例来源:origin: org.apache.ant/ant
checkTaskName();
final List<String> packagesToDoc = new Vector<>();
final Path sourceDirs = new Path(getProject());
tmpList = FILE_UTILS.createTempFile("javadoc", "", null, true, true);
toExecute.createArgument()
.setValue("@" + tmpList.getAbsolutePath());
tmpList.delete();
throw new BuildException("Error creating temporary file",
e, getLocation());
} finally {
FileUtils.close(wr);
final int ret = exe.execute();
if (ret != 0 && failOnError) {
throw new BuildException("Javadoc returned " + ret,
getLocation());
throw new BuildException("Javadoc issued warnings.",
getLocation());
FileUtils.close(out);
FileUtils.close(err);
代码示例来源:origin: org.apache.ant/ant
analyzedDeps.addAll(classFile.getClassRefs());
} finally {
FileUtils.close(inStream);
FileUtils.close(zipFile);
files.removeAllElements();
files.addAll(containers);
classes.removeAllElements();
classes.addAll(dependencies);
代码示例来源:origin: org.apache.ant/ant
helperImpl.project.setDefault(def);
} else {
throw new BuildException("The default attribute is required");
helperImpl.project.setName(name);
helperImpl.project.addReference(name, helperImpl.project);
helperImpl.project.setBasedir(baseDir);
} else {
File resolvedBaseDir = FILE_UTILS.resolveFile(helperImpl.buildFileParent,
baseDir);
helperImpl.project.setBaseDir(resolvedBaseDir);
内容来源于网络,如有侵权,请联系作者删除!