本文整理了Java中org.apache.tools.ant.util.FileUtils.tryHardToDelete()
方法的一些代码示例,展示了FileUtils.tryHardToDelete()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtils.tryHardToDelete()
方法的具体详情如下:
包路径:org.apache.tools.ant.util.FileUtils
类名称:FileUtils
方法名:tryHardToDelete
[英]Accommodate Windows bug encountered in both Sun and IBM JDKs. Others possible. If the delete does not work, call System.gc(), wait a little and try again.
[中]适应Sun和IBM JDK中遇到的Windows错误。其他可能的。如果删除不起作用,请呼叫系统。gc(),请稍等,然后重试。
代码示例来源:origin: org.apache.ant/ant
/**
* Accommodate Windows bug encountered in both Sun and IBM JDKs.
* Others possible. If the delete does not work, call System.gc(),
* wait a little and try again.
*
* @param f File
* @return whether deletion was successful
* @since Ant 1.8.0
*/
public boolean tryHardToDelete(File f) {
return tryHardToDelete(f, ON_WINDOWS);
}
代码示例来源:origin: org.apache.ant/ant
/**
* Accommodate Windows bug encountered in both Sun and IBM JDKs.
* Others possible. If the delete does not work, call System.gc(),
* wait a little and try again.
*/
private boolean delete(File f) {
if (!FILE_UTILS.tryHardToDelete(f, performGc)) {
if (deleteOnExit) {
int level = quiet ? Project.MSG_VERBOSE : Project.MSG_INFO;
log("Failed to delete " + f + ", calling deleteOnExit."
+ " This attempts to delete the file when the Ant jvm"
+ " has exited and might not succeed.", level);
f.deleteOnExit();
return true;
}
return false;
}
return true;
}
代码示例来源: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
/**
* Go and delete the directory tree.
* @param d the directory to delete
* @param deleteFiles whether to delete files
*/
protected void deleteDir(File d, boolean deleteFiles) {
String[] list = d.list();
if (list == null) {
return;
} // on an io error list() can return null
for (String s : list) {
File f = new File(d, s);
if (f.isDirectory()) {
deleteDir(f);
} else if (deleteFiles
&& !getFileUtils().tryHardToDelete(f, performGc)) {
throw new BuildException("Unable to delete file %s",
f.getAbsolutePath());
} else {
throw new BuildException(
"UNEXPECTED ERROR - The file %s should not exist!",
f.getAbsolutePath());
}
}
log("Deleting directory " + d.getAbsolutePath(), verbosity);
if (!getFileUtils().tryHardToDelete(d, performGc)) {
throw new BuildException("Unable to delete directory %s",
d.getAbsolutePath());
}
}
代码示例来源:origin: org.apache.ant/ant
return;
if (to.exists() && !(areSame(from, to) || tryHardToDelete(to))) {
throw new IOException("Failed to delete " + to + " while trying to rename " + from);
if (!tryHardToDelete(from)) {
throw new IOException("Failed to delete " + from + " while trying to rename it.");
代码示例来源:origin: org.apache.ant/ant
/**
* Try to move the file via a rename, but if this fails or filtering
* is enabled, copy the file then delete the sourceFile.
*/
private void moveFile(File fromFile, File toFile, boolean filtering, boolean overwrite) {
boolean moved = false;
try {
log("Attempting to rename: " + fromFile + " to " + toFile, verbosity);
moved = renameFile(fromFile, toFile, filtering, forceOverwrite);
} catch (IOException ioe) {
throw new BuildException("Failed to rename " + fromFile + " to "
+ toFile + " due to " + ioe.getMessage(), ioe, getLocation());
}
if (!moved) {
copyFile(fromFile, toFile, filtering, overwrite);
if (!getFileUtils().tryHardToDelete(fromFile, performGc)) {
throw new BuildException("Unable to delete file %s",
fromFile.getAbsolutePath());
}
}
}
代码示例来源:origin: org.apache.ant/ant
"can't replace read-only destination file %s", destFile));
if (!getFileUtils().tryHardToDelete(destFile)) {
throw new IOException(String.format(
"failed to delete read-only destination file %s",
&& !getFileUtils().tryHardToDelete(destFile, performGc)) {
throw new BuildException("Unable to remove existing file %s",
destFile);
代码示例来源:origin: org.apache.ant/ant
} finally {
if (tmpFile != null && tmpFile.exists()) {
FILE_UTILS.tryHardToDelete(tmpFile);
代码示例来源:origin: org.apache.ant/ant
throw new ReadOnlyTargetFileException(destFile);
if (!FILE_UTILS.tryHardToDelete(destFile)) {
throw new IOException(
"failed to delete read-only destination file " + destFile);
代码示例来源: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-compress
/**
* Creates a copy of the target archive in update or recreate mode
* because some entries may later be read and archived from it.
*/
private File maybeCopyTarget() {
File copyOfDest = null;
try {
if (!Mode.FORCE_CREATE.equals(getMode().getValue())
&& !Mode.CREATE.equals(getMode().getValue())) {
copyOfDest = FILE_UTILS.createTempFile(getTaskName(), ".tmp",
null, true, false);
ResourceUtils.copyResource(getDest(),
new FileResource(copyOfDest));
}
} catch (IOException ioex) {
if (copyOfDest != null && copyOfDest.exists()) {
FILE_UTILS.tryHardToDelete(copyOfDest);
}
throw new BuildException("Failed to copy target archive", ioex);
}
return copyOfDest;
}
代码示例来源:origin: org.apache.ant/ant-compress
FILE_UTILS.tryHardToDelete(copyOfDest);
代码示例来源:origin: org.apache.ant/ant-junit
} finally {
try {
FILE_UTILS.tryHardToDelete(casesFile);
} catch (final Exception e) {
log(e.toString(), Project.MSG_ERR);
代码示例来源:origin: org.apache.ant/ant-junit
outstream.close();
} catch (final IOException e) {
FILE_UTILS.tryHardToDelete(propsFile);
throw new BuildException("Error creating temporary properties "
+ "file.", e, getLocation());
FileUtils.close(br);
if (vmWatcher.exists()) {
FILE_UTILS.tryHardToDelete(vmWatcher);
if (!FILE_UTILS.tryHardToDelete(propsFile)) {
String msg = "Could not delete temporary properties file '"
+ propsFile.getAbsolutePath() + "'.";
内容来源于网络,如有侵权,请联系作者删除!