本文整理汇总了Java中java.nio.file.DirectoryStream.Filter类的典型用法代码示例。如果您正苦于以下问题:Java Filter类的具体用法?Java Filter怎么用?Java Filter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Filter类属于java.nio.file.DirectoryStream包,在下文中一共展示了Filter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testAndFilterLogicallyAndsAllFiltersAndDoesNotAcceptIfOneOfTheFiltersIsFalse
import java.nio.file.DirectoryStream.Filter; //导入依赖的package包/类
@Test
public void testAndFilterLogicallyAndsAllFiltersAndDoesNotAcceptIfOneOfTheFiltersIsFalse() throws IOException {
Filter<Path> filter1 = context.mock(Filter.class, "filter1");
Filter<Path> filter2 = context.mock(Filter.class, "filter2");
Filter<Path> filter3 = context.mock(Filter.class, "filter3");
Path mockPath = context.mock(Path.class);
context.checking(new Expectations() {{
atMost(1).of(filter1).accept(with(any(Path.class))); will(returnValue(true));
atMost(1).of(filter2).accept(with(any(Path.class))); will(returnValue(true));
atMost(1).of(filter3).accept(with(any(Path.class))); will(returnValue(false));
}});
AggregateAndFilter andFilter = new AggregateAndFilter(Sets.newHashSet(filter1, filter2, filter3));
Assert.assertFalse(andFilter.accept(mockPath));
}
示例2: testAndFilterLogicallyAndsAllFiltersAndAcceptsIfAllOfTheFiltersAreTrue
import java.nio.file.DirectoryStream.Filter; //导入依赖的package包/类
@Test
public void testAndFilterLogicallyAndsAllFiltersAndAcceptsIfAllOfTheFiltersAreTrue() throws IOException {
Filter<Path> filter1 = context.mock(Filter.class, "filter1");
Filter<Path> filter2 = context.mock(Filter.class, "filter2");
Filter<Path> filter3 = context.mock(Filter.class, "filter3");
Path mockPath = context.mock(Path.class);
context.checking(new Expectations() {{
atMost(1).of(filter1).accept(with(any(Path.class))); will(returnValue(true));
atMost(1).of(filter2).accept(with(any(Path.class))); will(returnValue(true));
atMost(1).of(filter3).accept(with(any(Path.class))); will(returnValue(true));
}});
AggregateAndFilter andFilter = new AggregateAndFilter(Sets.newHashSet(filter1, filter2, filter3));
Assert.assertTrue(andFilter.accept(mockPath));
}
示例3: testOrFilterLogicallyOrsAllFiltersAndDoesNotAcceptIfAllOfTheFiltersAreFalse
import java.nio.file.DirectoryStream.Filter; //导入依赖的package包/类
@Test
public void testOrFilterLogicallyOrsAllFiltersAndDoesNotAcceptIfAllOfTheFiltersAreFalse() throws IOException {
Filter<Path> filter1 = context.mock(Filter.class, "filter1");
Filter<Path> filter2 = context.mock(Filter.class, "filter2");
Filter<Path> filter3 = context.mock(Filter.class, "filter3");
Path mockPath = context.mock(Path.class);
context.checking(new Expectations() {{
atMost(1).of(filter1).accept(with(any(Path.class))); will(returnValue(false));
atMost(1).of(filter2).accept(with(any(Path.class))); will(returnValue(false));
atMost(1).of(filter3).accept(with(any(Path.class))); will(returnValue(false));
}});
AggregateOrFilter orFilter = new AggregateOrFilter(Sets.newHashSet(filter1, filter2, filter3));
Assert.assertFalse(orFilter.accept(mockPath));
}
示例4: testOrFilterLogicallyOrsAllFiltersAndAcceptsIfAnyOfTheFiltersAreTrue
import java.nio.file.DirectoryStream.Filter; //导入依赖的package包/类
@Test
public void testOrFilterLogicallyOrsAllFiltersAndAcceptsIfAnyOfTheFiltersAreTrue() throws IOException {
Filter<Path> filter1 = context.mock(Filter.class, "filter1");
Filter<Path> filter2 = context.mock(Filter.class, "filter2");
Filter<Path> filter3 = context.mock(Filter.class, "filter3");
Path mockPath = context.mock(Path.class);
context.checking(new Expectations() {{
atMost(1).of(filter1).accept(with(any(Path.class))); will(returnValue(false));
atMost(1).of(filter2).accept(with(any(Path.class))); will(returnValue(false));
atMost(1).of(filter3).accept(with(any(Path.class))); will(returnValue(true));
}});
AggregateOrFilter orFilter = new AggregateOrFilter(Sets.newHashSet(filter1, filter2, filter3));
Assert.assertTrue(orFilter.accept(mockPath));
}
示例5: newDirectoryStream
import java.nio.file.DirectoryStream.Filter; //导入依赖的package包/类
@Override
public DirectoryStream<Path> newDirectoryStream(Path dir,
final Filter<? super Path> filter) throws IOException {
final BundleFileSystem fs = (BundleFileSystem) dir.getFileSystem();
final DirectoryStream<Path> stream = origProvider(dir)
.newDirectoryStream(fs.unwrap(dir), new Filter<Path>() {
@Override
public boolean accept(Path entry) throws IOException {
return filter.accept(fs.wrap(entry));
}
});
return new DirectoryStream<Path>() {
@Override
public void close() throws IOException {
stream.close();
}
@Override
public Iterator<Path> iterator() {
return fs.wrapIterator(stream.iterator());
}
};
}
示例6: parsePathFilter
import java.nio.file.DirectoryStream.Filter; //导入依赖的package包/类
/**
* Constructs a filter according to the {@link PathMatcher} rules implemented by
* {@link DefaultPathMatcher}.
*
* @param pathFilterString
* @return A filter for the pattern
* @see FileSystem#getPathMatcher(String)
* @throws IllegalArgumentException
* If the syntax and pattern cannot be parsed
*/
public Filter<Path> parsePathFilter(String syntaxAndPattern, String fileSystemPathSeparator) throws IllegalArgumentException {
final DefaultPathMatcher matcher = new DefaultPathMatcher(syntaxAndPattern, fileSystemPathSeparator);
return new Filter<Path>() {
@Override
public boolean accept(Path path) throws IOException {
return matcher.matches(path);
}
};
}
示例7: createPathFilters
import java.nio.file.DirectoryStream.Filter; //导入依赖的package包/类
/**
* Creates an {@link AggregateOrFilter} from all of the filters, so that if any of them match
* then the path is accepted. Filters are created using {@link #parsePathFilter(String)}.
*
* @param commandOptions
* @return null if there are no filters created or the {@link AggregateOrFilter}
*
* @see #parsePathFilter(String)
*/
public Filter<Path> createPathFilters(List<UserCommandOption> commandOptions, String fileSystemPathSeparator) {
if (commandOptions == null || commandOptions.isEmpty()) {
return null;
}
AggregateOrFilter orFilter = new AggregateOrFilter();
for (UserCommandOption opt : commandOptions) {
Filter<Path> filter = parsePathFilter(opt.getValue(), fileSystemPathSeparator);
orFilter.addAggregateFilter(filter);
}
return orFilter;
}
示例8: listDirectoryContents
import java.nio.file.DirectoryStream.Filter; //导入依赖的package包/类
protected int listDirectoryContents(FileSystemProvider provider, FileSystem fileSystem,
Filter<Path> pathFilters, Path path, boolean recursive) {
AtomicInteger pathsCounter = new AtomicInteger(0);
FileSystemProviderHelper.iterateOverDirectoryContents(fileSystem, Optional.ofNullable(path),
PathFilters.ACCEPT_ALL_FILTER, recursive,
subPath -> {
pathsCounter.addAndGet(printCloudPathAttributes(fileSystem, pathFilters, subPath.getResultPath()));
return true;
});
return pathsCounter.get();
}
示例9: newDirectoryStream
import java.nio.file.DirectoryStream.Filter; //导入依赖的package包/类
/**
* Directory access is checked using {@link #checkAccess(BlobStoreContext, CloudPath, Set)}
* with {@link AclEntryPermission#LIST_DIRECTORY}.
*/
@Override
public CloudDirectoryStream newDirectoryStream(BlobStoreContext context, CloudPath dir,
Filter<CloudPath> filter, boolean isRecursive) throws IOException {
checkAccess(context, dir, NEW_DIRECTORY_STREAM_PERMS);
CloudPath dirPath = dir;
boolean isContainer = dirPath.getRoot() == null;
// Search in a container if root is null, otherwise check to find a directory
if (!isContainer) {
// Attempt to read attributes
try {
CloudBasicFileAttributes attributes = readAttributes(context, CloudBasicFileAttributes.class, dir);
// Look at the parent if this is a file
if (!attributes.isDirectory()) {
dirPath = dir.getParent();
}
} catch (FileNotFoundException e) {
LOG.warn("Cloud file path '{}' does not exist, will assume that this is a directory", dir);
}
}
return new CloudDirectoryStream(dirPath, isContainer, isRecursive, filter);
}
开发者ID:brdara,项目名称:java-cloud-filesystem-provider,代码行数:31,代码来源:DefaultCloudFileSystemImplementation.java
示例10: checkAccepts
import java.nio.file.DirectoryStream.Filter; //导入依赖的package包/类
boolean checkAccepts(Filter<Path> filter, Path entry) {
try {
return filter.accept(entry);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例11: newDirectoryStream
import java.nio.file.DirectoryStream.Filter; //导入依赖的package包/类
@Override
public DirectoryStream<Path> newDirectoryStream(Path dir, Filter<? super Path> filter) throws IOException {
MCRPath mcrPath = MCRFileSystemUtils.checkPathAbsolute(dir);
MCRFilesystemNode node = resolvePath(mcrPath);
if (node instanceof MCRDirectory) {
return new MCRDirectoryStream((MCRDirectory) node, mcrPath);
}
throw new NotDirectoryException(dir.toString());
}
示例12: newDirectoryStream
import java.nio.file.DirectoryStream.Filter; //导入依赖的package包/类
@Override
public DirectoryStream<Path> newDirectoryStream(Path dir,
Filter<? super Path> filter)
throws IOException
{
throw new UnsupportedOperationException();
}
示例13: newDirectoryStream
import java.nio.file.DirectoryStream.Filter; //导入依赖的package包/类
@Override
public DirectoryStream<Path> newDirectoryStream(Path dir,
Filter<? super Path> filter)
throws IOException
{
JPath jPath = (JPath) dir;
return new JDirectoryStream(jPath, filter);
}
示例14: fromDirectoryStream
import java.nio.file.DirectoryStream.Filter; //导入依赖的package包/类
private <T extends Resource> Map<String, T> fromDirectoryStream(Filter<Path> filter, Function<Path, T> mapper, Comparator<T> comparator) {
//linkedhashmap as we want to preserve the insertion order
try (DirectoryStream<Path> dirs = Files.newDirectoryStream(path, filter)) {
return StreamSupport.stream(dirs.spliterator(), false)
.map(mapper)
.sorted(comparator)
.collect(Collectors.toMap(Resource::getName, Function.identity(), (k, v) -> {throw new IllegalStateException("duplicate key " + k);}, LinkedHashMap::new));
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
示例15: listFiles
import java.nio.file.DirectoryStream.Filter; //导入依赖的package包/类
public static List<Path> listFiles(Path path, Filter<? super Path> filter) throws IOException
{
List<Path> files = new ArrayList<>();
try(DirectoryStream<Path> ds = Files.newDirectoryStream(path, filter))
{
for(Path p : ds)
{
files.add(p);
}
}
return files;
}