本文整理汇总了Java中java.nio.file.DirectoryStream.Filter方法的典型用法代码示例。如果您正苦于以下问题:Java DirectoryStream.Filter方法的具体用法?Java DirectoryStream.Filter怎么用?Java DirectoryStream.Filter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.file.DirectoryStream
的用法示例。
在下文中一共展示了DirectoryStream.Filter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: cleanupOldFiles
import java.nio.file.DirectoryStream; //导入方法依赖的package包/类
private void cleanupOldFiles(final String prefix, final String currentStateFile, Path[] locations) throws IOException {
final DirectoryStream.Filter<Path> filter = new DirectoryStream.Filter<Path>() {
@Override
public boolean accept(Path entry) throws IOException {
final String entryFileName = entry.getFileName().toString();
return Files.isRegularFile(entry)
&& entryFileName.startsWith(prefix) // only state files
&& currentStateFile.equals(entryFileName) == false; // keep the current state file around
}
};
// now clean up the old files
for (Path dataLocation : locations) {
try (DirectoryStream<Path> stream = Files.newDirectoryStream(dataLocation.resolve(STATE_DIR_NAME), filter)) {
for (Path stateFile : stream) {
Files.deleteIfExists(stateFile);
}
}
}
}
示例2: listFiles
import java.nio.file.DirectoryStream; //导入方法依赖的package包/类
private List<Path> listFiles(Path sourceDirectory, DirectoryStream.Filter<Path> filter)
{
List<Path> files = new ArrayList<Path>();
try (DirectoryStream<Path> paths = (filter != null) ? Files.newDirectoryStream(sourceDirectory, filter) : Files.newDirectoryStream(sourceDirectory))
{
for (Iterator<Path> it = paths.iterator(); it.hasNext();)
{
files.add(it.next());
}
}
catch (IOException e)
{
log.error(e.getMessage());
}
return files;
}
示例3: TaildirMatcher
import java.nio.file.DirectoryStream; //导入方法依赖的package包/类
/**
* Package accessible constructor. From configuration context it represents a single
* <code>filegroup</code> and encapsulates the corresponding <code>filePattern</code>.
* <code>filePattern</code> consists of two parts: first part has to be a valid path to an
* existing parent directory, second part has to be a valid regex
* {@link java.util.regex.Pattern} that match any non-hidden file names within parent directory
* . A valid example for filePattern is <code>/dir0/dir1/.*</code> given
* <code>/dir0/dir1</code> is an existing directory structure readable by the running user.
* <p></p>
* An instance of this class is created for each fileGroup
*
* @param fileGroup arbitrary name of the group given by the config
* @param filePattern parent directory plus regex pattern. No wildcards are allowed in directory
* name
* @param cachePatternMatching default true, recommended in every setup especially with huge
* parent directories. Don't set when local system clock is not used
* for stamping mtime (eg: remote filesystems)
* @see TaildirSourceConfigurationConstants
*/
TaildirMatcher(String fileGroup, String filePattern, boolean cachePatternMatching) {
// store whatever came from configuration
this.fileGroup = fileGroup;
this.filePattern = filePattern;
this.cachePatternMatching = cachePatternMatching;
// calculate final members
File f = new File(filePattern);
this.parentDir = f.getParentFile();
String regex = f.getName();
final PathMatcher matcher = FS.getPathMatcher("regex:" + regex);
this.fileFilter = new DirectoryStream.Filter<Path>() {
@Override
public boolean accept(Path entry) throws IOException {
return matcher.matches(entry.getFileName()) && !Files.isDirectory(entry);
}
};
// sanity check
Preconditions.checkState(parentDir.exists(),
"Directory does not exist: " + parentDir.getAbsolutePath());
}
示例4: iteratorOf
import java.nio.file.DirectoryStream; //导入方法依赖的package包/类
/**
* returns the list of child paths of the given directory "path"
*
* @param path name of the directory whose content is listed
* @return iterator for child paths of the given directory path
*/
Iterator<Path> iteratorOf(JrtPath path, DirectoryStream.Filter<? super Path> filter)
throws IOException {
Node node = checkNode(path).resolveLink(true);
if (!node.isDirectory()) {
throw new NotDirectoryException(path.getName());
}
if (filter == null) {
return node.getChildren()
.stream()
.map(child -> (Path)(path.resolve(new JrtPath(this, child.getNameString()).getFileName())))
.iterator();
}
return node.getChildren()
.stream()
.map(child -> (Path)(path.resolve(new JrtPath(this, child.getNameString()).getFileName())))
.filter(p -> { try { return filter.accept(p);
} catch (IOException x) {}
return false;
})
.iterator();
}
示例5: getImportableDirectoriesInDirectory
import java.nio.file.DirectoryStream; //导入方法依赖的package包/类
protected final AnalysedDirectory getImportableDirectoriesInDirectory(ImportableItem directory, final int count)
{
DirectoryStream.Filter<Path> filter = null;
if (count != -1)
{
filter = new DirectoryStream.Filter<Path>()
{
private int i = count;
@Override
public boolean accept(Path entry) throws IOException
{
return Files.isDirectory(entry) && i-- > 0;
}
};
}
else
{
filter = new DirectoryStream.Filter<Path>()
{
@Override
public boolean accept(Path entry) throws IOException
{
return Files.isDirectory(entry);
}
};
}
AnalysedDirectory analysedDirectory = directoryAnalyser.analyseDirectory(directory, filter);
return analysedDirectory;
}
示例6: ZipDirectoryStream
import java.nio.file.DirectoryStream; //导入方法依赖的package包/类
ZipDirectoryStream(ZipPath zipPath,
DirectoryStream.Filter<? super java.nio.file.Path> filter)
throws IOException
{
this.zipfs = zipPath.getFileSystem();
this.path = zipPath.getResolvedPath();
this.filter = filter;
// sanity check
if (!zipfs.isDirectory(path))
throw new NotDirectoryException(zipPath.toString());
}
示例7: newDirectoryStream
import java.nio.file.DirectoryStream; //导入方法依赖的package包/类
@Override
public DirectoryStream<Path> newDirectoryStream(Path dir, DirectoryStream.Filter<? super Path> filter)
throws IOException
{
triggerEx(dir, "newDirectoryStream");
return wrap(Files.newDirectoryStream(unwrap(dir), filter));
}
示例8: JrtDirectoryStream
import java.nio.file.DirectoryStream; //导入方法依赖的package包/类
JrtDirectoryStream(JrtPath dir,
DirectoryStream.Filter<? super java.nio.file.Path> filter)
throws IOException
{
this.dir = dir;
if (!dir.jrtfs.isDirectory(dir, true)) { // sanity check
throw new NotDirectoryException(dir.toString());
}
this.filter = filter;
}
示例9: dirStreamFilterData
import java.nio.file.DirectoryStream; //导入方法依赖的package包/类
@DataProvider(name = "dirStreamFilterData")
private Object[][] dirStreamFilterData() {
return new Object[][] {
{
"/",
(DirectoryStream.Filter<Path>)(Files::isDirectory),
"isDirectory"
},
{
"/modules/java.base/java/lang",
(DirectoryStream.Filter<Path>)(Files::isRegularFile),
"isFile"
}
};
}
示例10: getBucket
import java.nio.file.DirectoryStream; //导入方法依赖的package包/类
/**
* Retrieves a bucket identified by its name.
*
* @param bucketName name of the bucket to be retrieved
* @return the Bucket or null if not found
*/
public Bucket getBucket(final String bucketName) {
final DirectoryStream.Filter<Path> filter =
file -> (Files.isDirectory(file) && file.getFileName().endsWith(bucketName));
final List<Bucket> buckets = findBucketsByFilter(filter);
return buckets.size() > 0 ? buckets.get(0) : null;
}
示例11: findBucketsByFilter
import java.nio.file.DirectoryStream; //导入方法依赖的package包/类
/**
* Searches for folders in the rootFolder that match the given {@link DirectoryStream.Filter}
*
* @param filter the Filter to apply
* @return List of found Folders
*/
private List<Bucket> findBucketsByFilter(final DirectoryStream.Filter<Path> filter) {
final List<Bucket> buckets = new ArrayList<>();
try (DirectoryStream<Path> stream = Files.newDirectoryStream(rootFolder.toPath(), filter)) {
for (final Path path : stream) {
buckets.add(bucketFromPath(path));
}
} catch (final IOException e) {
LOG.error("Could not Iterate over Bucket-Folders", e);
}
return buckets;
}
示例12: setUpBeforeClass
import java.nio.file.DirectoryStream; //导入方法依赖的package包/类
/**
* Called once
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception {
// clean workspace
FileDeleter.delete(workspace.toPath());
// extract test-scenarios.
DirectoryStream.Filter<Path> filter = new DirectoryStream.Filter<Path>() {
@Override
public boolean accept(Path file) throws IOException {
String fname = file.getFileName().toString();
return fname.startsWith("scenario") && fname.endsWith("txt");
}
};
Path dir = scenarioRepository.toPath();
try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir, filter)) {
for (Path scenario : stream) {
String x = scenario.getFileName().toString();
String outDir = x.substring(0, x.indexOf(".txt")); // "scenario01";
String scenarioContent = readFile(scenario);
// Format is '#' separated, first line is filename
boolean skipFirst = true;
for (String junk : Splitter.on('#').split(scenarioContent)) {
if (skipFirst) {
skipFirst = false;
continue;
}
List<String> lines = Splitter.on("\n").splitToList(junk);
if (!lines.isEmpty()) {
Iterator<String> it = lines.iterator();
String filename = it.next().trim();
File f = new File(workspace, outDir + "/" + filename);
String content = Joiner.on('\n').join(it);
writeFile(f, content);
}
}
}
}
}
示例13: files
import java.nio.file.DirectoryStream; //导入方法依赖的package包/类
/**
* Returns an array of all files in the given directory matching.
*/
public static Path[] files(Path from, DirectoryStream.Filter<Path> filter) throws IOException {
try (DirectoryStream<Path> stream = Files.newDirectoryStream(from, filter)) {
return toArray(stream);
}
}
示例14: listBuckets
import java.nio.file.DirectoryStream; //导入方法依赖的package包/类
/**
* Lists all buckets managed by this FileStore
*
* @return List of all Buckets
*/
public List<Bucket> listBuckets() {
final DirectoryStream.Filter<Path> filter = file -> (Files.isDirectory(file));
return findBucketsByFilter(filter);
}
示例15: analyseDirectory
import java.nio.file.DirectoryStream; //导入方法依赖的package包/类
/**
* Analyses the given directory.
*
* @param directory The directory to analyse (note: <u>must</u> be a directory) <i>(must not be null)</i>.
* @return An <code>AnalysedDirectory</code> object <i>(will not be null)</i>.
*/
public AnalysedDirectory analyseDirectory(ImportableItem directory, DirectoryStream.Filter<Path> filter);