org.apache.openejb.loader.IO.doCopyDirectory()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(4.5k)|赞(0)|评价(0)|浏览(136)

本文整理了Java中org.apache.openejb.loader.IO.doCopyDirectory()方法的一些代码示例,展示了IO.doCopyDirectory()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IO.doCopyDirectory()方法的具体详情如下:
包路径:org.apache.openejb.loader.IO
类名称:IO
方法名:doCopyDirectory

IO.doCopyDirectory介绍

暂无

代码示例

代码示例来源:origin: org.apache.openejb/openejb-loader

  1. public static void copyDirectory(final File srcDir, final File destDir) throws IOException {
  2. if (srcDir == null) {
  3. throw new NullPointerException("Source must not be null");
  4. }
  5. if (destDir == null) {
  6. throw new NullPointerException("Destination must not be null");
  7. }
  8. if (!srcDir.exists()) {
  9. throw new FileNotFoundException("Source '" + srcDir + "' does not exist");
  10. }
  11. if (!srcDir.isDirectory()) {
  12. throw new IOException("Source '" + srcDir + "' exists but is not a directory");
  13. }
  14. if (srcDir.getCanonicalPath().equals(destDir.getCanonicalPath())) {
  15. throw new IOException("Source '" + srcDir + "' and destination '" + destDir + "' are the same");
  16. }
  17. // Cater for destination being directory within the source directory (see IO-141)
  18. List<String> exclusionList = null;
  19. if (destDir.getCanonicalPath().startsWith(srcDir.getCanonicalPath())) {
  20. final File[] srcFiles = srcDir.listFiles();
  21. if (srcFiles != null && srcFiles.length > 0) {
  22. exclusionList = new ArrayList<String>(srcFiles.length);
  23. for (final File srcFile : srcFiles) {
  24. final File copiedFile = new File(destDir, srcFile.getName());
  25. exclusionList.add(copiedFile.getCanonicalPath());
  26. }
  27. }
  28. }
  29. doCopyDirectory(srcDir, destDir, exclusionList);
  30. }

代码示例来源:origin: org.apache.tomee/openejb-loader

  1. public static void copyDirectory(final File srcDir, final File destDir) throws IOException {
  2. if (srcDir == null) {
  3. throw new NullPointerException("Source must not be null");
  4. }
  5. if (destDir == null) {
  6. throw new NullPointerException("Destination must not be null");
  7. }
  8. if (!srcDir.exists()) {
  9. throw new FileNotFoundException("Source '" + srcDir + "' does not exist");
  10. }
  11. if (!srcDir.isDirectory()) {
  12. throw new IOException("Source '" + srcDir + "' exists but is not a directory");
  13. }
  14. if (srcDir.getCanonicalPath().equals(destDir.getCanonicalPath())) {
  15. throw new IOException("Source '" + srcDir + "' and destination '" + destDir + "' are the same");
  16. }
  17. // Cater for destination being directory within the source directory (see IO-141)
  18. List<String> exclusionList = null;
  19. if (destDir.getCanonicalPath().startsWith(srcDir.getCanonicalPath())) {
  20. final File[] srcFiles = srcDir.listFiles();
  21. if (srcFiles != null && srcFiles.length > 0) {
  22. exclusionList = new ArrayList<String>(srcFiles.length);
  23. for (final File srcFile : srcFiles) {
  24. final File copiedFile = new File(destDir, srcFile.getName());
  25. exclusionList.add(copiedFile.getCanonicalPath());
  26. }
  27. }
  28. }
  29. doCopyDirectory(srcDir, destDir, exclusionList);
  30. }

代码示例来源:origin: org.apache.openejb/openejb-loader

  1. private static void doCopyDirectory(final File srcDir, final File destDir, final List<String> exclusionList) throws IOException {
  2. final File[] files = srcDir.listFiles();
  3. if (files == null) { // null if security restricted
  4. throw new IOException("Failed to list contents of " + srcDir);
  5. }
  6. if (destDir.exists()) {
  7. if (!destDir.isDirectory()) {
  8. throw new IOException("Destination '" + destDir + "' exists but is not a directory");
  9. }
  10. } else {
  11. if (!destDir.mkdirs()) {
  12. throw new IOException("Destination '" + destDir + "' directory cannot be created");
  13. }
  14. }
  15. if (!destDir.canWrite()) {
  16. throw new IOException("Destination '" + destDir + "' cannot be written to");
  17. }
  18. for (final File file : files) {
  19. final File copiedFile = new File(destDir, file.getName());
  20. if (exclusionList == null || !exclusionList.contains(file.getCanonicalPath())) {
  21. if (file.isDirectory()) {
  22. doCopyDirectory(file, copiedFile, exclusionList);
  23. } else {
  24. copy(file, copiedFile);
  25. }
  26. }
  27. }
  28. }

代码示例来源:origin: org.apache.tomee/openejb-loader

  1. private static void doCopyDirectory(final File srcDir, final File destDir, final List<String> exclusionList) throws IOException {
  2. final File[] files = srcDir.listFiles();
  3. if (files == null) { // null if security restricted
  4. throw new IOException("Failed to list contents of " + srcDir);
  5. }
  6. if (destDir.exists()) {
  7. if (!destDir.isDirectory()) {
  8. throw new IOException("Destination '" + destDir + "' exists but is not a directory");
  9. }
  10. } else {
  11. if (!destDir.mkdirs()) {
  12. throw new IOException("Destination '" + destDir + "' directory cannot be created");
  13. }
  14. }
  15. if (!destDir.canWrite()) {
  16. throw new IOException("Destination '" + destDir + "' cannot be written to");
  17. }
  18. for (final File file : files) {
  19. final File copiedFile = new File(destDir, file.getName());
  20. if (exclusionList == null || !exclusionList.contains(file.getCanonicalPath())) {
  21. if (file.isDirectory()) {
  22. doCopyDirectory(file, copiedFile, exclusionList);
  23. } else {
  24. copy(file, copiedFile);
  25. }
  26. }
  27. }
  28. }

相关文章