本文整理汇总了Java中java.nio.file.DirectoryIteratorException.getCause方法的典型用法代码示例。如果您正苦于以下问题:Java DirectoryIteratorException.getCause方法的具体用法?Java DirectoryIteratorException.getCause怎么用?Java DirectoryIteratorException.getCause使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.file.DirectoryIteratorException
的用法示例。
在下文中一共展示了DirectoryIteratorException.getCause方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkDirs
import java.nio.file.DirectoryIteratorException; //导入方法依赖的package包/类
/**
* Recurse down a directory tree, checking all child directories.
* @param dir
* @throws DiskErrorException
*/
public static void checkDirs(File dir) throws DiskErrorException {
checkDir(dir);
IOException ex = null;
try (DirectoryStream<java.nio.file.Path> stream =
Files.newDirectoryStream(dir.toPath())) {
for (java.nio.file.Path entry: stream) {
File child = entry.toFile();
if (child.isDirectory()) {
checkDirs(child);
}
}
} catch (DirectoryIteratorException de) {
ex = de.getCause();
} catch (IOException ie) {
ex = ie;
}
if (ex != null) {
throw new DiskErrorException("I/O error when open a directory: "
+ dir.toString(), ex);
}
}
示例2: listDirectory
import java.nio.file.DirectoryIteratorException; //导入方法依赖的package包/类
/**
* Return the complete list of files in a directory as strings.<p/>
*
* This is better than File#listDir because it does not ignore IOExceptions.
*
* @param dir The directory to list.
* @param filter If non-null, the filter to use when listing
* this directory.
* @return The list of files in the directory.
*
* @throws IOException On I/O error
*/
public static List<String> listDirectory(File dir, FilenameFilter filter)
throws IOException {
ArrayList<String> list = new ArrayList<String> ();
try (DirectoryStream<Path> stream =
Files.newDirectoryStream(dir.toPath())) {
for (Path entry: stream) {
String fileName = entry.getFileName().toString();
if ((filter == null) || filter.accept(dir, fileName)) {
list.add(fileName);
}
}
} catch (DirectoryIteratorException e) {
throw e.getCause();
}
return list;
}
示例3: testEmptyPackageDirectory
import java.nio.file.DirectoryIteratorException; //导入方法依赖的package包/类
@Test
public void testEmptyPackageDirectory(Path base) throws Exception {
Path src = base.resolve("src");
createSources(src);
// need an empty package directory, to check whether
// the behavior of subpackage and package
Path pkgdir = src.resolve("m1/m1pro/");
try (DirectoryStream<Path> stream = Files.newDirectoryStream(pkgdir, "*.java")) {
for (Path entry : stream) {
Files.deleteIfExists(entry);
}
} catch (DirectoryIteratorException ex) {
// I/O error encounted during the iteration
throw ex.getCause();
}
execTask("--module-source-path", src.toString(),
"-subpackages", "m1/m1pro");
checkPackagesSpecified("m1pro", "m1pro.pro1", "m1pro.pro2");
// empty package directory should cause an error
execNegativeTask("--module-source-path", src.toString(),
"m1/m1pro");
}
示例4: PollingWatchKey
import java.nio.file.DirectoryIteratorException; //导入方法依赖的package包/类
PollingWatchKey(Path dir, PollingWatchService watcher, Object fileKey)
throws IOException
{
super(dir, watcher);
this.fileKey = fileKey;
this.valid = true;
this.tickCount = 0;
this.entries = new HashMap<Path,CacheEntry>();
// get the initial entries in the directory
try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) {
for (Path entry: stream) {
// don't follow links
long lastModified =
Files.getLastModifiedTime(entry, LinkOption.NOFOLLOW_LINKS).toMillis();
entries.put(entry.getFileName(), new CacheEntry(lastModified, tickCount));
}
} catch (DirectoryIteratorException e) {
throw e.getCause();
}
}
示例5: tearDown
import java.nio.file.DirectoryIteratorException; //导入方法依赖的package包/类
/**
* Resets the Mojo by setting {@link #mojo} to {@code null} and deletes the
* test directory.
*
* @throws IOException Thrown if the test directory could not be deleted
*/
@After
public void tearDown() throws IOException {
//Unset Mojo instance
mojo = null;
//Delete test directory
final Path testDir = Paths.get(TEST_DIR);
if (Files.exists(testDir)) {
//First get all files in the test directory (if the test directory
//exists and delete them. This is necessary because there is no
//method for recursivly deleting a directory in the Java API.
try (final DirectoryStream<Path> files = Files.newDirectoryStream(
testDir)) {
for (final Path file : files) {
Files.deleteIfExists(file);
}
} catch (DirectoryIteratorException ex) {
throw ex.getCause();
}
//Delete the (now empty) test directory.
Files.deleteIfExists(testDir);
}
}
示例6: listResFiles
import java.nio.file.DirectoryIteratorException; //导入方法依赖的package包/类
private static List<Path> listResFiles(Path dir, String pattern) throws IOException {
List<Path> result = new ArrayList<>();
try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir, pattern)) {
for (Path entry : stream) {
result.add(entry);
}
} catch (DirectoryIteratorException ex) {
throw ex.getCause();
}
return result;
}
示例7: update
import java.nio.file.DirectoryIteratorException; //导入方法依赖的package包/类
/**
* Update the application file with the content from the update directory.
* @param applicationFile The application file to be updated
* @param updateDir The update directory holding the new file versions
* @param removeUpdateFiles If true, the updated files are deleted from the update directory
* @return The path to the newly updated application file, or null if there was no update performed
* @throws IOException In case of an error
*/
public static Path update(Path applicationFile, Path updateDir, boolean removeUpdateFiles) throws IOException {
Path newApplicationJar = null;
// Extract the application name from the application file
String applicationName = applicationFile.getFileName().toString();
// Strip the extension
applicationName = applicationName.substring(0, applicationName.lastIndexOf("."));
ArrayList<Path> updateFiles = new ArrayList<>();
try (DirectoryStream<Path> stream = Files.newDirectoryStream(updateDir, applicationName + "*.{jar,JAR,war,WAR,rar,RAR,ear,EAR}")) {
for (Path entry : stream) {
updateFiles.add(entry);
}
} catch (DirectoryIteratorException ex) {
// I/O error encounted during the iteration, the cause is an IOException
throw ex.getCause();
}
if (!updateFiles.isEmpty()) {
Path updateFile = updateFiles.get(0);
newApplicationJar = Files.copy(updateFile, applicationFile, StandardCopyOption.REPLACE_EXISTING);
if (removeUpdateFiles) {
Files.delete(updateFile);
}
}
return newApplicationJar;
}
示例8: addTree
import java.nio.file.DirectoryIteratorException; //导入方法依赖的package包/类
static Collection<Path> addTree(Path directory, Collection<Path> all, String ext) throws IOException {
try (DirectoryStream<Path> ds = Files.newDirectoryStream(directory)) {
for (Path child : ds) {
if (Files.isDirectory(child)) {
addTree(child, all, ext);
} else if (child.toString().toLowerCase().endsWith(ext)) {
all.add(child);
}
}
} catch (DirectoryIteratorException ex) {
// I/O error encounted during the iteration, the cause is an IOException
throw ex.getCause();
}
return all;
}
示例9: listDirectoryMixes
import java.nio.file.DirectoryIteratorException; //导入方法依赖的package包/类
List<Path> listDirectoryMixes(Path resourceFolder) throws IOException {
List<Path> result = new ArrayList<>();
try (DirectoryStream<Path> stream = Files.newDirectoryStream(
resourceFolder, "*.{mix}")) {
for (Path entry : stream) {
result.add(entry);
}
} catch (DirectoryIteratorException ex) {
throw ex.getCause();
}
return result;
}
示例10: listFiles
import java.nio.file.DirectoryIteratorException; //导入方法依赖的package包/类
/**
* Returns an immutable list of paths to the files contained in the given directory.
*
* @throws NoSuchFileException if the file does not exist <i>(optional specific exception)</i>
* @throws NotDirectoryException if the file could not be opened because it is not a directory
* <i>(optional specific exception)</i>
* @throws IOException if an I/O error occurs
*/
public static ImmutableList<Path> listFiles(Path dir) throws IOException {
try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) {
return ImmutableList.copyOf(stream);
} catch (DirectoryIteratorException e) {
throw e.getCause();
}
}