当前位置: 首页>>代码示例>>Java>>正文


Java DirectoryIteratorException类代码示例

本文整理汇总了Java中java.nio.file.DirectoryIteratorException的典型用法代码示例。如果您正苦于以下问题:Java DirectoryIteratorException类的具体用法?Java DirectoryIteratorException怎么用?Java DirectoryIteratorException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DirectoryIteratorException类属于java.nio.file包,在下文中一共展示了DirectoryIteratorException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: jButton1ActionPerformed

import java.nio.file.DirectoryIteratorException; //导入依赖的package包/类
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    // TODO add your handling code here:
          Path dir = Paths.get(txt_path.getText());
    if (dir.getParent()==null) {
        return;
    }
    dtm.setRowCount(0);
  
    try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir.getParent())) {
        for (Path file : stream) {

            dtm.addRow(new Object[]{file.getFileName()});
        }
    } catch (IOException | DirectoryIteratorException x) {

    }
    txt_path.setText(dir.getParent().toString());
    
}
 
开发者ID:sametkaya,项目名称:Java_Swing_Programming,代码行数:20,代码来源:Ornek6.java

示例4: 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

示例5: 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

示例6: readConfigFiles

import java.nio.file.DirectoryIteratorException; //导入依赖的package包/类
/**
 * Read a.yaml file according to a class type.
 *
 * @param path          folder which contain the config files
 * @param classType     Class type of the.yaml bean
 * @param fileNameRegex file name regex
 * @param <T>           Class T
 * @return Config file bean
 * @throws CarbonIdentityMgtConfigException Error in reading configuration file
 */
public static <T> List<T> readConfigFiles(Path path, Class<T> classType, String fileNameRegex)
        throws CarbonIdentityMgtConfigException {

    List<T> configEntries = new ArrayList<>();
    if (Files.exists(path)) {
        try (DirectoryStream<Path> stream = Files.newDirectoryStream(path, fileNameRegex)) {
            for (Path file : stream) {
                Reader in = new InputStreamReader(Files.newInputStream(file), StandardCharsets.UTF_8);
                CustomClassLoaderConstructor constructor =
                        new CustomClassLoaderConstructor(classType.getClassLoader());
                Yaml yaml = new Yaml(constructor);
                yaml.setBeanAccess(BeanAccess.FIELD);
                configEntries.add(yaml.loadAs(in, classType));
            }
        } catch (DirectoryIteratorException | IOException e) {
            throw new CarbonIdentityMgtConfigException(String.format("Failed to read identity connector files " +
                    "from path: %s", path.toString()), e);
        }
    }
    return configEntries;
}
 
开发者ID:wso2,项目名称:carbon-identity-mgt,代码行数:32,代码来源:FileUtil.java

示例7: getRandomCasa

import java.nio.file.DirectoryIteratorException; //导入依赖的package包/类
public static File getRandomCasa(int size) {
	List<String> casas = new ArrayList<>();
	Path dir = Paths.get(Main.getPlugin().getDataFolder() + File.separator + "casas" + File.separator);
	if (Files.exists(dir)) {
		try(DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) {
			for (Path path : stream) {
				String fn = path.getFileName().toString().split(".schematic")[0];
				if (fn.split("-").length == 2) {
					int smin = Integer.parseInt(fn.split("_")[1].split("-")[0]);
					int smax = Integer.parseInt(fn.split("_")[1].split("-")[1]);
					if (size >= smin && size <= smax) {
						casas.add(path.getFileName().toString());
					}
				}
			}
		} catch (IOException | DirectoryIteratorException e) {
			e.printStackTrace();
		}
		
		if (!casas.isEmpty()) {
			int i = new Random().nextInt(casas.size());
			return new File(dir.toString(), casas.get(i));
		}
	}
	return null;
}
 
开发者ID:leonardosnt,项目名称:OldBukkit,代码行数:27,代码来源:TerrenosManager.java

示例8: 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

示例9: collectPlotFiles

import java.nio.file.DirectoryIteratorException; //导入依赖的package包/类
private static Map<String, Collection<Path>> collectPlotFiles(List<String> plotDirectories, String numericAccountId)
{
  Map<String, Collection<Path>> plotFilesLookup = new HashMap<>();
  for(String plotDirectory : plotDirectories)
  {
    Path folderPath = Paths.get(plotDirectory);
    try (DirectoryStream<Path> plotFilesStream = Files.newDirectoryStream(folderPath))
    {
      List<Path> plotFilePaths = new ArrayList<>();
      for(Path plotFilePath : plotFilesStream)
      {
        if(plotFilePath.toString().contains(numericAccountId))
        {
          plotFilePaths.add(plotFilePath);
        }
      }
      plotFilesLookup.put(plotDirectory, plotFilePaths);
    }
    catch(IOException | DirectoryIteratorException e)
    {
      LOG.error(e.getMessage());
    }
  }
  return plotFilesLookup;
}
 
开发者ID:de-luxe,项目名称:burstcoin-jminer,代码行数:26,代码来源:Plots.java

示例10: listFiles

import java.nio.file.DirectoryIteratorException; //导入依赖的package包/类
private static List<Path> listFiles(Path dir)
{
    if ((dir != null) && Files.isDirectory(dir)) {
        try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) {
            ImmutableList.Builder<Path> builder = ImmutableList.builder();
            for (Path file : stream) {
                builder.add(file);
            }

            return builder.build();
        }
        catch (IOException | DirectoryIteratorException x) {
            log.warn(x, "Warning.");
            throw Throwables.propagate(x);
        }
    }
    return ImmutableList.of();
}
 
开发者ID:qubole,项目名称:presto-kinesis,代码行数:19,代码来源:KinesisTableDescriptionSupplier.java

示例11: fillContentList

import java.nio.file.DirectoryIteratorException; //导入依赖的package包/类
private boolean fillContentList(Path dir) {
    contentlist.clear();

    // add parent path only if possible
    Path parentPath = dir.getParent();
    if (parentPath != null) {
        contentlist.add(new PathFixture(parentPath));
    }

    if (dir != null && Files.isDirectory(dir)) {
        try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) {
            for (Path entry : stream) {
                contentlist.add(new PathFixture(entry));
            }
        }
        catch (DirectoryIteratorException | IOException ex) {
            log.warn(ex.getMessage());
        }

    }

    return (contentlist.size() >= 1 ? true : false);
}
 
开发者ID:e4c,项目名称:EclipseCommander,代码行数:24,代码来源:PathCompositeLayer.java

示例12: computeNext

import java.nio.file.DirectoryIteratorException; //导入依赖的package包/类
@Override
protected synchronized Path computeNext() {
  checkOpen();

  try {
    if (fileNames == null) {
      fileNames = view.snapshotWorkingDirectoryEntries().iterator();
    }

    while (fileNames.hasNext()) {
      Name name = fileNames.next();
      Path path = view.getWorkingDirectoryPath().resolve(name);

      if (filter.accept(path)) {
        return path;
      }
    }

    return endOfData();
  } catch (IOException e) {
    throw new DirectoryIteratorException(e);
  }
}
 
开发者ID:google,项目名称:jimfs,代码行数:24,代码来源:JimfsSecureDirectoryStream.java

示例13: FileMover

import java.nio.file.DirectoryIteratorException; //导入依赖的package包/类
/**
 * @param dirStructure the directory structure the destination should adhere to 
* @param sourcePath the path to the files to move
 * @param destinationPath the path to where the files should be moved
 */
public FileMover(DirectoryStructure dirStructure, String sourcePath, String destinationPath) {
    this.dirStructure = dirStructure;
    this.sourcePath = sourcePath;
    this.destinationPath = destinationPath;
    this.verbose = false;
    
    Path sourceDir = Paths.get(this.sourcePath + "/");
    
    //Construct the list of all the files to move
    DirectoryStream<Path> stream;
    try {
        stream = Files.newDirectoryStream(sourceDir);
        for(Path currentFile : stream) {
            BasicFileAttributes fileAttributes = Files.readAttributes(currentFile, BasicFileAttributes.class);
            System.out.println(currentFile.toString());
            if(!fileAttributes.isDirectory() || Arrays.asList(getAppleFiles()).contains(getFileExtension(currentFile))) {
                this.filesToMove.add(currentFile);
            }
        }
    }
    catch(IOException | DirectoryIteratorException e) {
        System.err.println(e);
    }
}
 
开发者ID:nokeeo,项目名称:JavaClean,代码行数:30,代码来源:FileMover.java

示例14: countSubDirs

import java.nio.file.DirectoryIteratorException; //导入依赖的package包/类
private long countSubDirs(Path path) throws IOException {
	try (DirectoryStream<Path> ds = Files.newDirectoryStream(path, Files::isDirectory)) {
		return Iterables.size(ds);
	} catch (DirectoryIteratorException e) {
		throw new IOException(e);
	}
}
 
开发者ID:cryptomator,项目名称:fuse-nio-adapter,代码行数:8,代码来源:ReadOnlyDirectoryHandler.java

示例15: readdir

import java.nio.file.DirectoryIteratorException; //导入依赖的package包/类
public int readdir(Path path, Pointer buf, FuseFillDir filler, long offset, FuseFileInfo fi) throws IOException {
		// fill in names and basic file attributes - however only the filetype is used...
//		Files.walkFileTree(node, EnumSet.noneOf(FileVisitOption.class), 1, new SimpleFileVisitor<Path>() {
//
//			@Override
//			public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
//				FileStat stat = attrUtil.basicFileAttributesToFileStat(attrs);
//				if (attrs.isDirectory()) {
//					stat.st_mode.set(FileStat.S_IFDIR | FileStat.ALL_READ | FileStat.S_IXUGO);
//				} else {
//					stat.st_mode.set(FileStat.S_IFREG | FileStat.ALL_READ);
//				}
//				filter.apply(buf, file.getFileName().toString(), stat, 0);
//				return FileVisitResult.CONTINUE;
//			}
//		});

		// just fill in names, getattr gets called for each entry anyway
		try (DirectoryStream<Path> ds = Files.newDirectoryStream(path)) {
			Iterator<Path> sameAndParent = Iterators.forArray(SAME_DIR, PARENT_DIR);
			Iterator<Path> iter = Iterators.concat(sameAndParent, ds.iterator());
			while (iter.hasNext()) {
				String fileName = iter.next().getFileName().toString();
				if (filler.apply(buf, fileName, null, 0) != 0) {
					return -ErrorCodes.ENOMEM();
				}
			}
			return 0;
		} catch (DirectoryIteratorException e) {
			throw new IOException(e);
		}
	}
 
开发者ID:cryptomator,项目名称:fuse-nio-adapter,代码行数:33,代码来源:ReadOnlyDirectoryHandler.java


注:本文中的java.nio.file.DirectoryIteratorException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。