All Projects → core-lib → loadkit

core-lib / loadkit

Licence: Apache-2.0 license
Java 资源加载器,充分拓展ClassLoader#getResources(name)的能力,实现递归加载,支持普通风格 / 包名风格 / ANT风格 / 正则风格路径的资源加载同时支持自定义过滤器,通常作为框架的基础类库。

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to loadkit

Pihole Regex
Custom regex filter list for use with Pi-hole.
Stars: ✭ 799 (+1948.72%)
Mutual labels:  regex, filter
core
An advanced and highly optimized Java library to build frameworks: it's useful for scanning class paths, generating classes at runtime, facilitating the use of reflection, scanning the filesystem, executing stringified source code and much more...
Stars: ✭ 100 (+156.41%)
Mutual labels:  loader, classloader
FileRenamerDiff
A File Renamer App featuring a difference display before and after the change.
Stars: ✭ 32 (-17.95%)
Mutual labels:  regex, file
Xlog
Android logger, pretty, powerful and flexible, log to everywhere, save to file, all you want is here.
Stars: ✭ 2,468 (+6228.21%)
Mutual labels:  filter, file
Androidutilcode
AndroidUtilCode 🔥 is a powerful & easy to use library for Android. This library encapsulates the functions that commonly used in Android development which have complete demo and unit test. By using it's encapsulated APIs, you can greatly improve the development efficiency. The program mainly consists of two modules which is utilcode, which is commonly used in development, and subutil which is rarely used in development, but the utils can be beneficial to simplify the main module. 🔥
Stars: ✭ 30,239 (+77435.9%)
Mutual labels:  regex, file
Boswatch
Python Script to process input data from rtl_fm and multimon-NG - multiple Plugin support
Stars: ✭ 101 (+158.97%)
Mutual labels:  regex, filter
regXwild
⏱ Superfast ^Advanced wildcards++? | Unique algorithms that was implemented on native unmanaged C++ but easily accessible in .NET via Conari (with caching of 0x29 opcodes +optimizations) etc.
Stars: ✭ 20 (-48.72%)
Mutual labels:  regex, filter
morphmorph
😱 Isomorphic transformations. Map, transform, filter, and morph your objects
Stars: ✭ 26 (-33.33%)
Mutual labels:  filter
pct
Build automation for OpenEdge ABL
Stars: ✭ 87 (+123.08%)
Mutual labels:  ant
ArminC-uBlock-Settings
⚙️ ArminC's settings for uBlock₀ - remove most of the ads, pop-ups and trackers.
Stars: ✭ 24 (-38.46%)
Mutual labels:  filter
cryptaddress.now
A minimal service to detect which cryptocurrency an address corresponds to.
Stars: ✭ 23 (-41.03%)
Mutual labels:  regex
SVGLoadersPack-Android
Android SVGLoadersPack - SVG animations and Loaders in Android
Stars: ✭ 27 (-30.77%)
Mutual labels:  loader
angular-translate-loader
"angular-translate" loader for webpack
Stars: ✭ 15 (-61.54%)
Mutual labels:  loader
github-diff-explorer
The GitHub Diff Explorer is a Chrome/Firefox extension that generates a seamless file explorer with a minimalist focus.
Stars: ✭ 27 (-30.77%)
Mutual labels:  file
Qt OpenCV
Qt/QtQuick apps using OpenCV
Stars: ✭ 19 (-51.28%)
Mutual labels:  filter
Waarp-All
This version is a major version for all Waarp Modules, previously being split.
Stars: ✭ 18 (-53.85%)
Mutual labels:  file
expand-brackets
Expand POSIX bracket expressions (character classes) in glob patterns.
Stars: ✭ 26 (-33.33%)
Mutual labels:  regex
vue-loading
Loading bar for Vue.js apps using axios
Stars: ✭ 19 (-51.28%)
Mutual labels:  loader
cypress-upload-file-post-form
Solution for two Cypress testing use-cases I came across with: perform a direct http FORM request to the server containing a file and other parameters and upload a file into a form before submission
Stars: ✭ 59 (+51.28%)
Mutual labels:  file
Finite-State-Machines
Implementation of the algorithm in the C#. https://tproger.ru/translations/finite-state-machines-theory-and-implementation/
Stars: ✭ 13 (-66.67%)
Mutual labels:  ant

LoadKit

Java 资源加载器,充分拓展ClassLoader#getResources(name)的能力,实现递归加载,支持普通风格 / 包名风格 / ANT风格 / 正则风格路径的资源加载同时支持自定义过滤器,通常作为框架的基础类库。

由于ClassLoader#getResources(name)方法提供的资源加载能力非常有限,不支持递归和搜索的特性,但是开发一个框架往往需要按照约定或配置去加载一些当前项目的资源或者扫描指定包目录下的类,LoadKit能提供非常便利的API以满足需求。

功能特性

  • 纯JDK的API,无第三方依赖。
  • 支持多种路径风格的资源加载。
  • 完全惰性加载,避免性能浪费。
  • 可自定义资源过滤器实现精确加载。
  • 底层支持file 和 jar 两个URL协议,满足绝大部分项目需求。
  • 传递URLStreamHandler,支持自定义的URLStreamHandler。

环境依赖

JDK 1.5 +

使用步骤

<project>
    <!-- 设置 jitpack.io 仓库 -->
    <repositories>
        <repository>
            <id>jitpack.io</id>
            <url>https://jitpack.io</url>
        </repository>
    </repositories>
    <!-- 添加 LoadKit 依赖 -->
    <dependencies>
        <dependency>
            <groupId>com.github.core-lib</groupId>
            <artifactId>loadkit</artifactId>
            <version>v1.0.1</version>
        </dependency>
    </dependencies>
</project>

示例代码

// 从当前的classpath中加载io/loadkit目录的资源,但不递归加载子目录。
Loaders.std().load("io/loadkit");
// 从当前的classpath中加载io目录的资源,而且递归加载子目录。
Loaders.std().load("io", true);
// 从当前的classpath中加载io以及所有递归子目录并且名称以Loader.class结尾的资源。
Loaders.std().load("io", true, (name, url) -> name.endsWith("Loader.class"));
// 上面的API默认采用的时当前线程的上下文类加载器,如果上下文类加载器不存在时则采用ClassLoader.getSystemClassLoader();
// 同时也可以采用下面的方式指定类加载器。
Loaders.std(otherClassLoader);
// 当加载某个package下的类资源时也要用路径的方式来写包名的话其实不太直观,这时可以采用pkg资源加载器。
Loaders.pkg().load("io.loadkit"); // 不递归
Loaders.pkg().load("io.loadkit", true); // 递归
// 递归加载io.loadkit包下名称以Loader.class结尾的资源
Loaders.pkg().load("io.loadkit", (name, url) -> name.endsWith("Loader.class")); 
// package资源加载器实际上是一个委派加载器,只是内部将包名转换成路径方式然后委派给实际的资源加载器。
// 缺省情况下采用的是Loaders.std()资源加载器,也可以通过指定ClassLoader和delegate,实现更灵活的资源加载方式。
Loaders.pkg(otherClassLoader);
Loaders.pkg(Loaders.std(otherClassLoader));
// 在package资源加载器中要加载io.loadkit包下的名称Loader.class结尾的资源是需要自定义过滤器,
// 即便使用了Lambda表达式,但是采用ANT表达式就更简洁。
// * 任意个字符,但不包括子目录
// ** 任意个字符,而且包括子目录
// ? 单个字符,可以使用多个表达多个字符,例如:load??? 可匹配loadkit 但不匹配loader
Loaders.ant().load("io/loadkit/*Loader.class");
// 上面的ANT风格路径的资源加载器加载io.loadkit包的资源时,需要用 “/” 来分隔目录,用来加载包资源不太直观。
// 这时可以采用delegate模式用package资源加载器去包装一个ANT资源加载器,
// 让资源加载同时拥有package 和 ant 两个加载器的解析能力。
Loaders.pkg(Loaders.ant()).load("io.loadkit.*"); // 加载 io.loadkit.*
// 有ANT表达式的资源加载器,自然也会有正则表达式的资源加载器。
Loaders.regex().load("io/loadkit/\\w+Loader.class"); // 加载 io.loadkit包下名称以Loader.class 结尾的资源。
// Loader#load(); 方法只接收一个Filter参数,当过滤逻辑比较多而且不好写在一个过滤器,当然这样的类也是违背了"单一职责原则"的。
Filters.and(Filter...filters); // AND 连接的混合过滤器
Filters.or(Filter...filters); // OR 连接的混合过滤器
// 来将多个子过滤器混合成一个过滤器,或者:
Filters.all(Filter...filters); // AND 连接的混合过滤器的另一种表达方式
Filters.any(Filter...filters); // OR 连接的混合过滤器的另一种表达方式

变更记录

  • v1.0.1
    • 修复ANT路径表达式**/*无法匹配当前目录的问题
  • v1.0.0
    • 第一个正式版发布

协议声明

Apache-2.0

联系作者

QQ 646742615 不会钓鱼的兔子

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].