今天还是没事看了看elfinder源码,发现之前说的两个版本实现都是基于不同的jdkelfinder源码浏览-Volume文件系统操作类(1)

带前端页面的是基于1.6中File实现,另一个是基于1.7中的Path实现,

今天看了一个非常有意思的匿名类应用,先看基础java中一个引人深思的匿名内部类

其中引起我注意的是一个文件搜索的实现,

项目代码并没有引起我的问题,但深思的是基于1.8源码的实现使用了一个

@@@@@DirectoryStream.Filter<Path>接口,此接口是一个包装接口,使用了java1.8中的接口函数式方法@FunctionalInterface@@@@@@@@@@@@@@@@

请先参考java1.7中新增的NIOJAVA NIO:Path ,File

首先先看一看此方法应用,此方法获取给定的工作空间中非隐藏的文件列表,

包装Volume类
  @Override
public Target[] listChildren(Target target) throws IOException {
//其中这里使用了一个NioHelper工具类封装了之前定义的Path接口,来获取非隐藏文件 List<Path> childrenResultList = NioHelper.listChildrenNotHidden(fromTarget(target));
List<Target> targets = new ArrayList<>(childrenResultList.size());
for (Path path : childrenResultList) {
targets.add(fromPath(path));
}
return targets.toArray(new Target[targets.size()]);
}

令人深思的是下面我们它的实现

NIOHelper类

此类是我今天看到的一个匿名接口使用

  /**
* Gets children paths from the give directory (excluding hidden files).
* 带有文件过滤的
* @param dir path to the directory.
* @return the children paths from the give directory.
* @throws IOException if something goes wrong.
*/
public static List<Path> listChildrenNotHidden(Path dir) throws IOException {
// not hidden file filter
//
DirectoryStream.Filter<Path> notHiddenFilter = new DirectoryStream.Filter<Path>() {
public boolean accept(Path path) throws IOException {
return !Files.isHidden(path);
}
};
    //调用了同级类中的方法listChildren
return listChildren(dir, notHiddenFilter);
}
  /**
* Gets children paths from the give directory appling the given filter.
* 依据NIO中Files类中newDirectoryStream方法传入一个
    DirectoryStream.Filter接口来判断是否是隐藏目录,如果是就舍弃,不是就加入一个list中,
    然后使用Collrctions中的unmodifiableList设置此list不可更改,
    通过判断传入的dir来让Collrctions中emptyList方法设置返回的list是否是一个空的
* @param dir path to the directory. * @param filter the filter to be applied * @return the children paths from the give directory. * @throws IOException if something goes wrong. */ 
public static List<Path> listChildren(Path dir, DirectoryStream.Filter<? super Path> filter) throws IOException {
    if (isFolder(dir)) { List<Path> list = new ArrayList<>();
try (DirectoryStream<Path> directoryStream = (filter != null ? Files.newDirectoryStream(dir, filter) : Files.newDirectoryStream(dir))) {
for (Path p : directoryStream) {
list.add(p);
}
}
return Collections.unmodifiableList(list);
}
return Collections.emptyList();
}

至此我们已经看完了这个实现的具体应用,发现原来匿名类是如此的强大,完全少写很多之前写代码中的逻辑判断

elfinder中通过DirectoryStream.Filter实现筛选隐藏目录(二)的更多相关文章

  1. django-filter 使用Filter来筛选你的数据

    django-filter Django-filter is a generic, reusable application to alleviate writing some of the more ...

  2. Python day11 filter函数筛选数据,reduce函数压缩数据的源码详解

    1.filter滤波器函数定义一个数组,需求:过滤出带ii的字符串 arr=['dsdsdii','qqwe','pppdiimmm','sdsa','sshucsii','iisdsa'] def ...

  3. js Array 中的 map, filter 和 reduce

    原文中部分源码来源于:JS Array.reduce 实现 Array.map 和 Array.filter Array 中的高阶函数 ---- map, filter, reduce map() - ...

  4. Angularjs在控制器(controller.js)的js代码中使用过滤器($filter)格式化日期/时间实例

    Angularjs内置的过滤器(filter)为我们的数据信息格式化提供了比较强大的功能,比如:格式化时间,日期.格式化数字精度.语言本地化.格式化货币等等.但这些过滤器一般都是在VIEW中使用的,比 ...

  5. Android中的Intent Filter匹配规则介绍

    本文主要介绍了隐式Intent匹配目标组件的规则,若有叙述不清晰或是不准确的地方希望大家指出,谢谢大家: ) 1. Intent简介 Intent用于在一个组件(Component,如Activity ...

  6. java Servlet中的过滤器Filter

    web.xml中元素执行的顺序listener->filter->struts拦截器->servlet. 1.过滤器的概念 Java中的Filter 并不是一个标准的Servlet ...

  7. jQuery中find()和filter()的区别

    filter(expr):筛选出与指定表达式匹配的元素的元素集合,其中expr可以是多个选择器的组合.是对自身集合元素的筛选. find()会在元素内寻找匹配元素,而filter()是筛选元素:是对它 ...

  8. IOS开发中UIBarButtonItem上按钮切换或隐藏实现案例

    IOS开发中UIBarButtonItem上按钮切换或隐藏案例实现案例是本文要介绍的内容,这个代码例子的背景是:导航条右侧有个 edit button,左侧是 back button 和 add bu ...

  9. css3中强大的filter(滤镜)属性

    CSS3中强大的filter(滤镜)属性 博主最近在做网站的过程中发现了一个非常强大的CSS3属性,就是filter(滤镜)属性,喜欢p图的朋友看名字都应该知道这是什么神器了吧.当然,这个属性的效果肯 ...

随机推荐

  1. kolla管理openstack容器

    本文以nova-api容器为例,说明kolla如何将nova-api配置文件传入容器,容器如何启动nova-api服务并读取配置文件 注:第一部分比较无趣,二三部分 会有意思一些 1. nova-ap ...

  2. http缓存(http caching)

    通过使用缓存web网站和web应用的性能能够得到显著的提升.Web caches能够减小延迟和网络流量,从而缩短展示资源所花费的时间. 在http中控制缓存行为的首部字段是Cache-Control, ...

  3. Effective Java 第三版——35. 使用实例属性替代序数

    Tips <Effective Java, Third Edition>一书英文版已经出版,这本书的第二版想必很多人都读过,号称Java四大名著之一,不过第二版2009年出版,到现在已经将 ...

  4. 获取NVIDIA显卡的温度

    NVIDIA显卡在硬件上有温度传感器,可以感知显卡的运行环境.温度数据的获取,一般是通过调用NVIDIA的SDK的相关函数即可.SDK的下载的网址(https://developer.nvidia.c ...

  5. FusionCharts中图的属性的总结归纳

    FusionCharts中图的属性的总结归纳 1.横坐标label间隔显示 labelStep="4" 2.柱状图有椭圆角 useRoundEdges="1"

  6. FusionCharts 3D帕累托图报错

    今天我在设计3D帕累托图时,是由原来的2D帕累托图页面重命名而来,但是当我重命名后发现HTML文件打不开,而且还报错,真不知道是什么原因引起的.因此,我就将这个错误截图,保存下来,希望以后能够解决,或 ...

  7. Django学习-1-管理我的django程序

    网页中文文档 http://python.usyiyi.cn/documents/django_182/topics/db/models.html Django性能测试工具 https://githu ...

  8. 基于 angular 规范的 commit

    基于 angular 规范的 commit commit格式如下: <type>: <subject> <BLANK LINE> <body> type ...

  9. Defeat the Enemy UVALive - 7146

      Long long ago there is a strong tribe living on the earth. They always have wars and eonquer other ...

  10. 【NFS】nfs安装调优

    nfs [root@flymaster ~]# rpm -qa nfs-utils rpcbindnfs-utils-1.2.3-75.el6.x86_64rpcbind-0.2.0-13.el6_9 ...