本文整理了Java中org.apache.nifi.util.file.FileUtils.deleteFile()
方法的一些代码示例,展示了FileUtils.deleteFile()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtils.deleteFile()
方法的具体详情如下:
包路径:org.apache.nifi.util.file.FileUtils
类名称:FileUtils
方法名:deleteFile
[英]Deletes the given file. If the given file exists but could not be deleted this will be printed as a warning to the given logger
[中]
代码示例来源:origin: apache/nifi
/**
* Deletes the given file. If the given file exists but could not be deleted this will be printed as a warning to the given logger
*
* @param file the file to delete
* @param logger the logger to provide logging information to about the operation
* @return true if given file no longer exists
*/
public static boolean deleteFile(final File file, final Logger logger) {
return FileUtils.deleteFile(file, logger, 1);
}
代码示例来源:origin: apache/nifi
public static void deleteFile(final File file, final boolean recurse) throws IOException {
if (file.isDirectory() && recurse) {
FileUtils.deleteFiles(Arrays.asList(file.listFiles()), recurse);
}
//now delete the file itself regardless of whether it is plain file or a directory
if (!FileUtils.deleteFile(file, null, 5)) {
throw new IOException("Unable to delete " + file.getAbsolutePath());
}
}
代码示例来源:origin: apache/nifi
/**
* Deletes all files (not directories) in the given directory (recursive) that match the given filename filter. If any file cannot be deleted then this is printed at warn to the given logger.
*
* @param directory the directory to scan
* @param filter if null then no filter is used
* @param logger the logger
* @param recurse whether to recurse subdirectories or not
* @param deleteEmptyDirectories default is false; if true will delete directories found that are empty
*/
public static void deleteFilesInDir(final File directory, final FilenameFilter filter, final Logger logger, final boolean recurse, final boolean deleteEmptyDirectories) {
// ensure the specified directory is actually a directory and that it exists
if (null != directory && directory.isDirectory()) {
final File ingestFiles[] = directory.listFiles();
for (File ingestFile : ingestFiles) {
boolean process = (filter == null) ? true : filter.accept(directory, ingestFile.getName());
if (ingestFile.isFile() && process) {
FileUtils.deleteFile(ingestFile, logger, 3);
}
if (ingestFile.isDirectory() && recurse) {
FileUtils.deleteFilesInDir(ingestFile, filter, logger, recurse, deleteEmptyDirectories);
if (deleteEmptyDirectories && ingestFile.list().length == 0) {
FileUtils.deleteFile(ingestFile, logger, 3);
}
}
}
}
}
代码示例来源:origin: apache/nifi
/**
* Deletes all of the given files. If any exist and cannot be deleted that will be printed at warn to the given logger.
*
* @param files can be null
* @param logger can be null
*/
public static void deleteFile(final List<File> files, final Logger logger) {
FileUtils.deleteFile(files, logger, 1);
}
代码示例来源:origin: apache/nifi
/**
* Deletes given files.
*
* @param files the files to delete
* @param recurse will recurse if true; false otherwise
* @throws IOException if any issues deleting specified files
*/
public static void deleteFiles(final Collection<File> files, final boolean recurse) throws IOException {
for (final File file : files) {
FileUtils.deleteFile(file, recurse);
}
}
代码示例来源:origin: apache/nifi
/**
* Renames the given file from the source path to the destination path. This handles multiple attempts. This should only be used to rename within a given directory. Renaming across directories
* might not work well. See the <code>File.renameTo</code> for more information.
*
* @param source the file to rename
* @param destination the file path to rename to
* @param maxAttempts the max number of attempts to attempt the rename
* @param replace if true and a rename attempt fails will check if a file is already at the destination path. If so it will delete that file and attempt the rename according the remaining
* maxAttempts. If false, any conflicting files will be left as they were and the rename attempts will fail if conflicting.
* @throws IOException if rename isn't successful
*/
public static void renameFile(final File source, final File destination, final int maxAttempts, final boolean replace) throws IOException {
final int attempts = (replace || maxAttempts < 1) ? Math.max(2, maxAttempts) : maxAttempts;
boolean renamed = false;
for (int i = 0; i < attempts; i++) {
renamed = source.renameTo(destination);
if (!renamed) {
FileUtils.deleteFile(destination, null, 5);
} else {
break; //rename has succeeded
}
}
if (!renamed) {
throw new IOException("Attempted " + maxAttempts + " times but unable to rename from \'" + source.getPath() + "\' to \'" + destination.getPath() + "\'");
}
}
代码示例来源:origin: apache/nifi
FileUtils.deleteFile(indexDirectory, true);
logger.debug("Successfully deleted directory {}", indexDirectory);
} catch (final IOException e) {
代码示例来源:origin: apache/nifi
fos.close();
if (!FileUtils.deleteFile(file, null, 5)) {
throw new IOException("Failed to delete file after shredding");
代码示例来源:origin: apache/nifi
@BeforeClass
public static void setupBeforeClass() {
System.setProperty("derby.stream.error.file", "target/derby.log");
// remove previous test database, if any
final File dbLocation = new File(DB_LOCATION);
try {
FileUtils.deleteFile(dbLocation, true);
} catch (IOException ioe) {
// Do nothing, may not have existed
}
}
代码示例来源:origin: apache/nifi
@BeforeClass
public static void setupBeforeClass() throws IOException {
System.setProperty("derby.stream.error.file", "target/derby.log");
// remove previous test database, if any
final File dbLocation = new File(DB_LOCATION);
try {
FileUtils.deleteFile(dbLocation, true);
} catch (IOException ioe) {
// Do nothing, may not have existed
}
}
代码示例来源:origin: apache/nifi
@BeforeClass
public static void setupBeforeClass() throws IOException {
System.setProperty("derby.stream.error.file", "target/derby.log");
// remove previous test database, if any
final File dbLocation = new File(DB_LOCATION);
try {
FileUtils.deleteFile(dbLocation, true);
} catch (IOException ioe) {
// Do nothing, may not have existed
}
}
代码示例来源:origin: apache/nifi
@BeforeClass
public static void setupBeforeClass() throws IOException {
System.setProperty("derby.stream.error.file", "target/derby.log");
// remove previous test database, if any
final File dbLocation = new File(DB_LOCATION);
try {
FileUtils.deleteFile(dbLocation, true);
} catch (IOException ioe) {
// Do nothing, may not have existed
}
}
代码示例来源:origin: apache/nifi
fos = null;
fis = null;
if (move && !FileUtils.deleteFile(source, null, 5)) {
if (logger == null) {
FileUtils.deleteFile(destination, null, 5);
throw new IOException("Could not remove file " + source.getAbsolutePath());
} else {
代码示例来源:origin: apache/nifi
@AfterClass
public static void cleanUpAfterClass() throws Exception {
try {
DriverManager.getConnection("jdbc:derby:" + DB_LOCATION + ";shutdown=true");
} catch (SQLNonTransientConnectionException e) {
// Do nothing, this is what happens at Derby shutdown
}
// remove previous test database, if any
final File dbLocation = new File(DB_LOCATION);
try {
FileUtils.deleteFile(dbLocation, true);
} catch (IOException ioe) {
// Do nothing, may not have existed
}
}
代码示例来源:origin: apache/nifi
@AfterClass
public static void cleanUpAfterClass() throws Exception {
try {
DriverManager.getConnection("jdbc:derby:" + DB_LOCATION + ";shutdown=true");
} catch (SQLNonTransientConnectionException e) {
// Do nothing, this is what happens at Derby shutdown
}
// remove previous test database, if any
final File dbLocation = new File(DB_LOCATION);
try {
FileUtils.deleteFile(dbLocation, true);
} catch (IOException ioe) {
// Do nothing, may not have existed
}
}
代码示例来源:origin: apache/nifi
@AfterClass
public static void cleanUpAfterClass() throws Exception {
try {
DriverManager.getConnection("jdbc:derby:" + DB_LOCATION + ";shutdown=true");
} catch (SQLNonTransientConnectionException e) {
// Do nothing, this is what happens at Derby shutdown
}
// remove previous test database, if any
final File dbLocation = new File(DB_LOCATION);
try {
FileUtils.deleteFile(dbLocation, true);
} catch (IOException ioe) {
// Do nothing, may not have existed
}
}
代码示例来源:origin: apache/nifi
@AfterClass
public static void cleanUpAfterClass() throws Exception {
try {
DriverManager.getConnection("jdbc:derby:" + DB_LOCATION + ";shutdown=true");
} catch (SQLNonTransientConnectionException e) {
// Do nothing, this is what happens at Derby shutdown
}
// remove previous test database, if any
final File dbLocation = new File(DB_LOCATION);
try {
FileUtils.deleteFile(dbLocation, true);
} catch (IOException ioe) {
// Do nothing, may not have existed
}
}
代码示例来源:origin: org.apache.nifi/nifi-utils
/**
* Deletes the given file. If the given file exists but could not be deleted this will be printed as a warning to the given logger
*
* @param file the file to delete
* @param logger the logger to provide logging information to about the operation
* @return true if given file no longer exists
*/
public static boolean deleteFile(final File file, final Logger logger) {
return FileUtils.deleteFile(file, logger, 1);
}
代码示例来源:origin: org.apache.nifi/nifi-utils
/**
* Deletes all of the given files. If any exist and cannot be deleted that will be printed at warn to the given logger.
*
* @param files can be null
* @param logger can be null
*/
public static void deleteFile(final List<File> files, final Logger logger) {
FileUtils.deleteFile(files, logger, 1);
}
代码示例来源:origin: org.apache.nifi/nifi-utils
/**
* Deletes given files.
*
* @param files the files to delete
* @param recurse will recurse if true; false otherwise
* @throws IOException if any issues deleting specified files
*/
public static void deleteFiles(final Collection<File> files, final boolean recurse) throws IOException {
for (final File file : files) {
FileUtils.deleteFile(file, recurse);
}
}
内容来源于网络,如有侵权,请联系作者删除!