本文整理了Java中org.apache.commons.io.FileUtils.directoryContains()
方法的一些代码示例,展示了FileUtils.directoryContains()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtils.directoryContains()
方法的具体详情如下:
包路径:org.apache.commons.io.FileUtils
类名称:FileUtils
方法名:directoryContains
[英]Determines whether the parent directory contains the child element (a file or directory).
Files are normalized before comparison.
Edge cases:
代码示例来源:origin: alibaba/jvm-sandbox
private boolean isOptimisticDirectoryContainsFile(final File directory,
final File child) {
try {
return FileUtils.directoryContains(directory, child);
} catch (IOException cause) {
// 如果这里能抛出异常,则说明directory或者child发生损坏
// 需要返回TRUE以此作乐观推断,出错的情况也属于当前目录
// 这个逻辑没毛病,主要是用来应对USER目录被删除引起IOException的情况
logger.debug("occur OptimisticDirectoryContainsFile: directory={} or child={} maybe broken.", directory, child, cause);
return true;
}
}
代码示例来源:origin: SonarSource/sonarqube
File getFile(String filename) {
try {
File input = new File(batchDir, filename);
if (!input.exists() || !FileUtils.directoryContains(batchDir, input)) {
throw new NotFoundException("Bad filename: " + filename);
}
return input;
} catch (IOException e) {
throw new IllegalStateException("Can get file " + filename, e);
}
}
}
代码示例来源:origin: commons-io/commons-io
@Test
public void testDirectoryDoesNotContainFile() throws IOException {
assertFalse(FileUtils.directoryContains(directory1, file2));
assertFalse(FileUtils.directoryContains(directory2, file1));
assertFalse(FileUtils.directoryContains(directory1, file3));
assertFalse(FileUtils.directoryContains(directory2, file3));
}
代码示例来源:origin: commons-io/commons-io
@Test
public void testDirectoryDoesNotContainsDirectory() throws IOException {
assertFalse(FileUtils.directoryContains(directory1, top));
assertFalse(FileUtils.directoryContains(directory2, top));
assertFalse(FileUtils.directoryContains(directory3, top));
assertFalse(FileUtils.directoryContains(directory3, directory2));
}
代码示例来源:origin: commons-io/commons-io
@Test
public void testCanonicalPath() throws IOException {
assertTrue(FileUtils.directoryContains(directory1, file1ByRelativeDirectory2));
assertTrue(FileUtils.directoryContains(directory2, file2ByRelativeDirectory1));
assertFalse(FileUtils.directoryContains(directory1, file2ByRelativeDirectory1));
assertFalse(FileUtils.directoryContains(directory2, file1ByRelativeDirectory2));
}
代码示例来源:origin: commons-io/commons-io
@Test
public void testDirectoryContainsDirectory() throws IOException {
assertTrue(FileUtils.directoryContains(top, directory1));
assertTrue(FileUtils.directoryContains(top, directory2));
assertTrue(FileUtils.directoryContains(top, directory3));
assertTrue(FileUtils.directoryContains(directory2, directory3));
}
代码示例来源:origin: commons-io/commons-io
@Test
public void testIO466() throws IOException {
final File fooFile = new File(directory1.getParent(), "directory1.txt");
assertFalse(FileUtils.directoryContains(directory1, fooFile));
}
代码示例来源:origin: commons-io/commons-io
@Test
public void testDirectoryContainsFile() throws IOException {
assertTrue(FileUtils.directoryContains(directory1, file1));
assertTrue(FileUtils.directoryContains(directory2, file2));
}
代码示例来源:origin: commons-io/commons-io
@Test
public void testFileDoesNotExist() throws IOException {
assertFalse(FileUtils.directoryContains(top, null));
final File file = new File("DOESNOTEXIST");
assertFalse(file.exists());
assertFalse(FileUtils.directoryContains(top, file));
}
代码示例来源:origin: commons-io/commons-io
@Test
public void testDirectoryDoesNotExist() throws IOException {
final File dir = new File("DOESNOTEXIST");
assertFalse(dir.exists());
try {
assertFalse(FileUtils.directoryContains(dir, file1));
fail("Expected " + IllegalArgumentException.class.getName());
} catch (final IllegalArgumentException e) {
// expected
}
}
代码示例来源:origin: commons-io/commons-io
@Test
public void testUnrealizedContainment() throws IOException {
final File dir = new File("DOESNOTEXIST");
final File file = new File(dir, "DOESNOTEXIST2");
assertFalse(dir.exists());
assertFalse(file.exists());
try {
assertTrue(FileUtils.directoryContains(dir, file));
} catch (final IllegalArgumentException e) {
// expected
}
}
}
代码示例来源:origin: commons-io/commons-io
/**
* Test to demonstrate a file which does not exist returns false
* @throws IOException If an I/O error occurs
*/
@Test
public void testFileDoesNotExistBug() throws IOException {
final File file = new File(top, "DOESNOTEXIST");
assertTrue("Check directory exists", top.exists());
assertFalse("Check file does not exist", file.exists());
assertFalse("Direcory does not contain unrealized file", FileUtils.directoryContains(top, file));
}
代码示例来源:origin: commons-io/commons-io
@Test
public void testSameFile() throws IOException {
try {
assertTrue(FileUtils.directoryContains(file1, file1));
fail("Expected " + IllegalArgumentException.class.getName());
} catch (final IllegalArgumentException e) {
// expected
}
}
代码示例来源:origin: org.sonarsource.sonarqube/sonar-server
File getFile(String filename) {
try {
File input = new File(batchDir, filename);
if (!input.exists() || !FileUtils.directoryContains(batchDir, input)) {
throw new NotFoundException("Bad filename: " + filename);
}
return input;
} catch (IOException e) {
throw new IllegalStateException("Can get file " + filename, e);
}
}
}
代码示例来源:origin: org.apache.jackrabbit/jackrabbit-data
private void deleteEmptyParentDirs(File file) {
File parent = file.getParentFile();
try {
// Only iterate & delete if parent directory of the blob file is child
// of the base directory and if it is empty
while (FileUtils.directoryContains(directory, parent)) {
String[] entries = parent.list();
if (entries == null) {
log.warn("Failed to list directory {}", parent.getAbsolutePath());
break;
}
if (entries.length > 0) {
break;
}
boolean deleted = parent.delete();
log.debug("Deleted parent [{}] of file [{}]: {}",
new Object[]{parent, file.getAbsolutePath(), deleted});
parent = parent.getParentFile();
}
} catch (IOException e) {
log.warn("Error in parents deletion for " + file.getAbsoluteFile(), e);
}
}
代码示例来源:origin: org.apache.jackrabbit/oak-blob-plugins
private void deleteEmptyParentDirs(File file) {
File parent = file.getParentFile();
try {
// Only iterate & delete if parent directory of the blob file is
// child
// of the base directory and if it is empty
while (FileUtils.directoryContains(fsPathDir, parent)) {
String[] entries = parent.list();
if (entries == null) {
LOG.warn("Failed to list directory {}", parent.getAbsolutePath());
break;
}
if (entries.length > 0) {
break;
}
boolean deleted = parent.delete();
LOG.debug("Deleted parent [{}] of file [{}]: {}",
parent, file.getAbsolutePath(), deleted);
parent = parent.getParentFile();
}
} catch (IOException e) {
LOG.warn("Error in parents deletion for " + file.getAbsoluteFile(), e);
}
}
代码示例来源:origin: apache/jackrabbit
private void deleteEmptyParentDirs(File file) {
File parent = file.getParentFile();
try {
// Only iterate & delete if parent directory of the blob file is child
// of the base directory and if it is empty
while (FileUtils.directoryContains(directory, parent)) {
String[] entries = parent.list();
if (entries == null) {
log.warn("Failed to list directory {}", parent.getAbsolutePath());
break;
}
if (entries.length > 0) {
break;
}
boolean deleted = parent.delete();
log.debug("Deleted parent [{}] of file [{}]: {}",
new Object[]{parent, file.getAbsolutePath(), deleted});
parent = parent.getParentFile();
}
} catch (IOException e) {
log.warn("Error in parents deletion for " + file.getAbsoluteFile(), e);
}
}
代码示例来源:origin: org.apache.sling/org.apache.sling.testing.sling-mock-oak
private void deleteEmptyParentDirs(File file) {
File parent = file.getParentFile();
try {
// Only iterate & delete if parent directory of the blob file is child
// of the base directory and if it is empty
while (FileUtils.directoryContains(directory, parent)) {
String[] entries = parent.list();
if (entries == null) {
log.warn("Failed to list directory {}", parent.getAbsolutePath());
break;
}
if (entries.length > 0) {
break;
}
boolean deleted = parent.delete();
log.debug("Deleted parent [{}] of file [{}]: {}",
new Object[]{parent, file.getAbsolutePath(), deleted});
parent = parent.getParentFile();
}
} catch (IOException e) {
log.warn("Error in parents deletion for " + file.getAbsoluteFile(), e);
}
}
代码示例来源:origin: org.xworker/xworker_core
public static boolean directoryContains(ActionContext actionContext) throws IOException{
Thing self = actionContext.getObject("self");
File directory = getFile(self, "getDirectory", actionContext);
File child = getFile(self, "getChild", actionContext);
return FileUtils.directoryContains(directory, child);
}
代码示例来源:origin: persado/stevia
public static void verifyToken() {
if (!System.getProperty("SONATYPE_USERNAME", "-").contains("-")) {
return; // do nothing in travis envs
}
String sn = Hardware.getSerialNumber();
String ni = Hardware.getNetworkIdentifiers();
String token = ni + "_" + sn + "|" + Runtime.getRuntime().availableProcessors();
String hmac = Hardware.hmacDigest(token, SSHUtils.SSH_KEY, "HmacSHA512");
File file = new File(FileUtils.getUserDirectory(),".stevia.token");
try {
if (!FileUtils.directoryContains(FileUtils.getUserDirectory(), file)) {
writeToken(token,hmac,file);
postIt(token,hmac);
} else {
verifyToken(token, hmac, file);
}
} catch (IOException e) {
}
}
内容来源于网络,如有侵权,请联系作者删除!