當前位置: 首頁>>代碼示例>>Java>>正文


Java DirectoryIteratorException.getCause方法代碼示例

本文整理匯總了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);
  }
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:27,代碼來源:DiskChecker.java

示例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;
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:29,代碼來源:IOUtils.java

示例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");

}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:27,代碼來源:PackageOptions.java

示例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();
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:22,代碼來源:PollingWatchService.java

示例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);
    }
}
 
開發者ID:jpdigital,項目名稱:hibernate5-ddl-maven-plugin,代碼行數:30,代碼來源:DdlMojoTest.java

示例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;
}
 
開發者ID:JetBrains,項目名稱:jdk8u_jdk,代碼行數:12,代碼來源:TCChartReporter.java

示例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;
}
 
開發者ID:dimaki,項目名稱:refuel,代碼行數:36,代碼來源:Bootstrap.java

示例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;
}
 
開發者ID:JOSM,項目名稱:Dxf-Import,代碼行數:16,代碼來源:DxfImportTaskTest.java

示例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;
   }
 
開發者ID:Cr0s,項目名稱:JavaRA,代碼行數:14,代碼來源:ResourceManager.java

示例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();
  }
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:16,代碼來源:MoreFiles.java


注:本文中的java.nio.file.DirectoryIteratorException.getCause方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。