当前位置:网站首页>Hutool Usage Summary (VIP collection version)

Hutool Usage Summary (VIP collection version)

2022-06-10 15:06:00 Java Tony

Catalog

One 、 brief introduction

Two 、 Design philosophy and advantages

Design philosophy

advantage

3、 ... and 、 install

Maven Quoted total quantity

Maven On-demand reference

Gradle quote

Four 、 Components

Component package description

Detailed description of component package

5、 ... and 、 Code using

String related

BigDecimal Addition, subtraction, multiplication and division

Time tools (hutool-core)

IO Stream correlation

Common tools

Linguistic characteristics

JavaBean

Collection classes

Map

Codec code

Text operation

annotation

The comparator

abnormal

mathematics

picture

The Internet

The configuration file (Hutool-setting)

journal (Hutool-log)

cache (Hutool-cache)

JSON(Hutool-json)

Encryption and decryption (Hutool-crypto)

DFA lookup (Hutool-dfa)

database (Hutool-db)

HTTP client (Hutool-http)

Timing task (Hutool-cron)

Expand (Hutool-extra)

section (Hutool-aop)

Script (Hutool-script)

Office The document operation (Hutool-poi)

system call (Hutool-system)

Graphic verification code (Hutool-captcha)

The Internet Socket(Hutool-socket)


One 、 brief introduction

Hutool It's a small and complete Java Tool library , Encapsulate... In a static way , Reduce the correlation API Cost of learning , Improve work efficiency , send Java With the elegance of functional language , Give Way Java Language can also “ Sweet ”.

Hutool The tools and methods in are refined by each user , It covers Java Develop all aspects of the underlying code , It is a sharp tool to solve small problems in large-scale project development , It is also the efficiency responsibility in small projects ;

  • Web Development
  • No coupling with other frames
  • Height replaceable

Two 、 Design philosophy and advantages

Design philosophy

Hutool The design idea is to minimize repetitive definitions , Let the util This package As far as possible , In general, there are the following ideas :

  • Method takes precedence over object
  • Automatic recognition is better than user-defined
  • Convenience and flexibility coexist
  • Adaptation and compatibility
  • The optional dependency principle
  • No invasion principle

advantage

Other tools follow Huttol comparison , What are the shortcomings? :

  • Apache Family bucket : English annotation , Method needs to be checked
  • Guava:Jar Big bag ,API Awkward
  • Jodd: And Hutool Most similar , Incomplete functions
  • Nutz: Tools and methods are very easy to use , But it's a framework
  • Voovan: Tools and methods are very easy to use , It's solved IO Questions first , The application scenario is not wide

3、 ... and 、 install

Maven Quoted total quantity

        <dependency>
            <groupId>cn.hutool</groupId>
            <artifactId>hutool-all</artifactId>
            <version>5.8.2</version>
        </dependency>

Maven On-demand reference

For example, quote hutool-aop

        <dependency>
            <groupId>cn.hutool</groupId>
            <artifactId>hutool-aop</artifactId>
            <version>5.8.2</version>
        </dependency>

Gradle quote

implementation 'cn.hutool:hutool-all:5.8.2'

Four 、 Components

Component package description

One Java Basic tools , The file 、 flow 、 Encryption and decryption 、 transcoding 、 Regular 、 Threads 、XML etc. JDK Method to encapsulate , Make up all kinds of Util Tool class , The following components are also provided :

modular Introduce
hutool-aopJDK Dynamic agent encapsulation , Provide non IOC Next aspect support
hutool-bloomFilter Bloon filtration , Provide some Hash Algorithm's bloom filtering
hutool-cache Simple cache implementation
hutool-core The core , Include Bean operation 、 date 、 Various Util etc.
hutool-cron Timing task module , Provide classes Crontab Expression timing task
hutool-crypto Encryption and decryption module , Provide symmetry 、 Asymmetric and digest algorithm encapsulation
hutool-dbJDBC Data operation after encapsulation , be based on ActiveRecord thought
hutool-dfa be based on DFA Multi keyword search of model
hutool-extra Extension module , Encapsulate... To a third party ( template engine 、 mail 、Servlet、 QR code 、Emoji、FTP、 Participle, etc )
hutool-http be based on HttpUrlConnection Of Http Client encapsulation
hutool-log Automatic recognition of the log door
hutool-script Script execution encapsulation , for example Javascript
hutool-setting More powerful Setting Configuration files and Properties encapsulation
hutool-system System parameter call encapsulation (JVM Information, etc )
hutool-jsonJSON Realization
hutool-captcha Picture verification code implementation
hutool-poi in the light of POI in Excel and Word Encapsulation
hutool-socket be based on Java Of NIO and AIO Of Socket encapsulation
hutool-jwtJSON Web Token (JWT) Encapsulation implementation

Each module can be introduced separately according to the requirements , Or by introducing hutool-all Way to introduce all modules .

Detailed description of component package

PackageDescription
cn.hutoolHutool It's a small and complete Java Tool library , Encapsulate... In a static way , Reduce the correlation API Cost of learning , Improve work efficiency , send Java With the elegance of functional language , Give Way Java Language can also “ Sweet ”.
cn.hutool.aopJDK Dynamic agent encapsulation , Provide non IOC Next aspect support
cn.hutool.aop.aspects Cut to achieve , Provide some basic facet implementations
cn.hutool.aop.interceptor Proxy interceptor implementation
cn.hutool.aop.proxy The proxy implementation
cn.hutool.bloomfilter Bloon filtration , Provide some Hash Algorithm's bloom filtering
cn.hutool.bloomfilter.bitMapBitMap Realization
cn.hutool.bloomfilter.filter Various Hash Filter implementation of the algorithm
cn.hutool.cache Provide a simple cache implementation , This module refers to jodd Tools Cache modular
cn.hutool.cache.file Provide cache implementation for files
cn.hutool.cache.impl Provide various cache implementations
cn.hutool.captcha Picture verification code implementation
cn.hutool.captcha.generator Verification code generation strategy implementation
cn.hutool.coreHutool Core method and data structure package
cn.hutool.core.annotation Annotation package , Provides enhanced annotations and annotation tool classes
cn.hutool.core.beanBean The relevant operation , Include Bean Information description ,Bean Path expression 、 dynamic Bean、Bean Tools etc.
cn.hutool.core.bean.copierBean Copy implementation , Including copy options, etc
cn.hutool.core.bean.copier.providerBean Value provider mode encapsulation
cn.hutool.core.builder Builder tools
Used to construct specific objects or results
cn.hutool.core.clone Cloning encapsulates
cn.hutool.core.codecBaseN as well as BCD Coding encapsulation
cn.hutool.core.collection Assemble and Iterator encapsulation , Including collection tools CollUtil,Iterator and Iterable Tools IterUtil
cn.hutool.core.comparator Various comparators (Comparator) Implementation and encapsulation
cn.hutool.core.compiler Compile at run time java Source code , Dynamically load classes from strings or external files
cn.hutool.core.compress Compress, decompress and package
cn.hutool.core.convert Universal type converter and implementation classes of various type conversions , among Convert Is the converter inlet , Provide all kinds of toXXX Methods and convert Method
cn.hutool.core.convert.impl Implementation classes for various types of transformations , They are all Converter Interface implementation , Used to put unknown Object The type is converted to the specified type
cn.hutool.core.date Date encapsulation , The core of the date is DateTime class ,DateUtil Provide entry for date operation
cn.hutool.core.date.chinese Summary of lunar calendar related categories , Including the lunar month 、 Heaven and earth 、 Lunar Festival 、24 Solar terms, etc
cn.hutool.core.date.format Provide thread safe date format formatting and parsing implementation
cn.hutool.core.exceptions Special exception encapsulation , Also provide exception tools ExceptionUtil
cn.hutool.core.gettergetXXX Method interface and abstract implementation
cn.hutool.core.img Image processing related tool class encapsulation
cn.hutool.core.img.gifGIF Handle , come from :https://github.com/rtyley/animated-gif-lib-for-java
cn.hutool.core.ioIO Related encapsulation and tool classes , Include Inputstream and OutputStream Implementation class , Tools include flow tools IoUtil、 File tools FileUtil and Buffer Tools BufferUtil
cn.hutool.core.io.checksumIO Verify related libraries and tools
cn.hutool.core.io.checksum.crc16CRC16 The related algorithms are encapsulated as Checksum
cn.hutool.core.io.copyIO Stream copy related encapsulation related encapsulation
cn.hutool.core.io.file Encapsulation of file read / write , Include file copies 、 File read 、 The document says 、 Line processing, etc
cn.hutool.core.io.file.visitorFileVisitor Functional implementation , Including recursive deletion 、 Copy, etc
cn.hutool.core.io.resource in the light of ClassPath And the encapsulation of resource reading in the file , The main entry is tools ResourceUtil
cn.hutool.core.io.unit Data unit related encapsulation , Include DataUnit Data units and DataSize data size
cn.hutool.core.io.watch be based on JDK7+ WatchService File and directory listening encapsulation , Support multi-level directory
cn.hutool.core.io.watch.watchers Observer implementation class in file listener , Including deferred processing 、 Processing chain, etc
cn.hutool.core.lang Language Feature Pack , Including a large number of convenient data structures , For example, verifiers Validator, Distributed ID generator Snowflake etc.
cn.hutool.core.lang.ansi Command line terminal ANSI Escape sequence related encapsulation , Such as ANSI Color, etc.
cn.hutool.core.lang.caller Caller interface and implementation . The caller can be obtained through this method 、 Multi level caller and judge whether it is called
cn.hutool.core.lang.copier Copy Abstract implementation , Through abstract copy , Can implement file 、 flow 、Buffer Copy between
cn.hutool.core.lang.func Function encapsulation
The interface is inspired by ActFramework
A function interface represents a function , Used to wrap a function as an object
stay JDK8 Before ,Java A function of cannot be passed as a parameter , Nor can it exist as a return value , This interface is used to wrap a function into an object , So as to pass the object
cn.hutool.core.lang.generator Provide generator interface and related packages
cn.hutool.core.lang.hash Provide Hash Encapsulation of algorithms
cn.hutool.core.lang.id Provide all kinds of ID Generate
cn.hutool.core.lang.intern The canonical representation encapsulates
So called normalization , That is, when two objects equals when , Normalized objects can implement ==
The related encapsulation in this package is similar to String#intern()
cn.hutool.core.lang.loader The abstract interface and implementation of loader , Including the implementation of lazy loading
cn.hutool.core.lang.mutable Provides encapsulation of variable value objects , For encapsulation int、long Equal immutable value , Make it variable
cn.hutool.core.lang.reflect Provide reflection related function objects and classes
cn.hutool.core.lang.tree Provide generic tree generation , characteristic :
cn.hutool.core.lang.tree.parser
cn.hutool.core.mapMap Related packaging , Provide special Map Realize and Map Tools MapUtil
cn.hutool.core.map.multi Multi parameter type Map Realization , Include values of the collection type Map and Table
cn.hutool.core.math Provide mathematical calculation related packages , Including arrangement and combination , The entrance is MathUtil
cn.hutool.core.net Network related tools
cn.hutool.core.net.multipart File upload package
cn.hutool.core.net.urlURL Related tools
cn.hutool.core.streamJava8 Of stream Related packaging
cn.hutool.core.swingSwing and awt Related packaging
cn.hutool.core.swing.clipboard Clipboard related tools , Including clipboard monitoring
cn.hutool.core.text Provides encapsulation of text related operations , It also includes Unicode Tools UnicodeUtil
cn.hutool.core.text.csv Provide CSV File read / write encapsulation , The entrance is CsvUtil
See :https://datatracker.ietf.org/doc/html/rfc4180
cn.hutool.core.text.escape Provides various escape and anti escape implementations
cn.hutool.core.text.finder Text search implementation , Include : Find characters in text ( positive 、 reverse ) Find matching characters in text ( positive 、 reverse ) Find the string in the text ( positive 、 reverse ) Find the regular string in the text ( positive )
cn.hutool.core.text.replacer Text replacement class abstraction and implementation
cn.hutool.core.text.split
cn.hutool.core.thread Provide threading and high concurrency encapsulation , The entrance is ThreadUtil
cn.hutool.core.thread.lock Lock implementation
cn.hutool.core.thread.threadlocalThreadLocal Related packaging
cn.hutool.core.util Provide various tools and methods , According to the classification, the entrance is XXXUtil, Such as string tools StrUtil etc.
cn.hutool.cron Timing task module , Provide classes Crontab Expression timing task , Implementation reference Cron4j, At the same time, it can support the definition of second level scheduled tasks and year ( Compatible with Crontab、Cron4j、Quartz expression )
The timing task module consists of three parts : Scheduler  Timed task scheduler , It is used for adding and deleting overall management tasks 、 Start stop and trigger operation . Task  Timed task implementation , Used to define specific tasks  CronPattern  Timed task expression , Used to define task trigger time meanwhile , Provides CronUtil Tool class , Maintain a global Scheduler.
cn.hutool.cron.listener Timed task execution monitoring interface and its partial implementation
cn.hutool.cron.pattern Timed task expression parsing , The core is CronPattern
cn.hutool.cron.pattern.matcher Timed task expression matcher , For internal use
A single expression uses PatternMatcher Express
PatternMatcher from 7 individual PartMatcher form , Respectively represent... In the timed task expression 7 A place :
cn.hutool.cron.pattern.parser Timed task expression parser , For internal use
cn.hutool.cron.task Abstract encapsulation and implementation of jobs in scheduled tasks , Include Runnable Implementation and reflection implementation
Task Represents a specific task , When the time matching requirements are met , Will execute Task.execute() Method .
cn.hutool.cron.timingwheel Time wheel implementation , Rewrote kafka Of TimingWheel
The time wheel is usually realized as a ring structure , Like a clock , Divided into many slots , A slot represents a time interval , Each slot uses a two-way linked list to store scheduled tasks . The pointer beats periodically , Jump to a slot , Execute the timing task of the slot .
cn.hutool.crypto Encryption and decryption module , Realized with JDK The encapsulation of encryption and decryption algorithm in , The entrance is SecureUtil, Realized :
cn.hutool.crypto.asymmetric Implementation of asymmetric encryption , Include RSA etc.
cn.hutool.crypto.digest Implementation of encryption algorithm , The entrance is DigestUtil
cn.hutool.crypto.digest.macHMAC, Its full name is “Hash Message Authentication Code”, Chinese name “ Hash message identifier ”
Hash algorithm is mainly used , Take a key and a message as input , Generate a message digest as output .
General , The message authentication code is used to verify that the message is transmitted in two common Messages between units that share a key .
HMAC It can be used in conjunction with any iterative hash function .MD5 and SHA-1 This is the hash function .HMAC You can also use a key to calculate and confirm the message authentication value .
cn.hutool.crypto.digest.otpOTP yes One-Time Password Abbreviation , Indicates a one-time password .
cn.hutool.crypto.symmetric Implementation of symmetric encryption algorithm , Include AES、DES、DESede etc.
cn.hutool.crypto.symmetric.fpe
cn.hutool.dbHutool-db It's a JDBC Database operation tool class encapsulated on the basis of , By packing , Use ActiveRecord Think about operating the database .
stay Hutool-db in , Use Entity( It's essentially a Map) Instead of Bean Make database operation more flexible , At the same time provide Bean and Entity The transformation of provides traditional ORM Compatible support for .
cn.hutool.db.dialect Database dialect encapsulation , Including database dialect and dialect automatic recognition
cn.hutool.db.dialect.impl Database dialect implementation , Include MySQL、Oracle、PostgreSQL、Sqlite3、H2、SqlServer2012 etc.
cn.hutool.db.ds Data source encapsulation , Encapsulation of various database connection pools
cn.hutool.db.ds.beeBeeCP encapsulation see :https://github.com/Chris2018998/BeeCP
cn.hutool.db.ds.c3p0C3P0 encapsulation
cn.hutool.db.ds.dbcpDBCP encapsulation
cn.hutool.db.ds.druidDruid encapsulation
cn.hutool.db.ds.hikariHikari encapsulation
cn.hutool.db.ds.jndiJNDI encapsulation
cn.hutool.db.ds.pooledHutool Simple implementation of connection pool
cn.hutool.db.ds.simpleJDBC in DriverManager Easy to package
cn.hutool.db.ds.tomcatTomcat-Pool encapsulation
cn.hutool.db.handlerJDBC Result set (ResultSet) Conversion encapsulation , By implementing RsHandler Interface , take ResultSet Convert to the data type we want
cn.hutool.db.metaJDBC Data table metadata information encapsulation , Including table structure 、 Encapsulation of column information , The entrance is MetaUtil
cn.hutool.db.nosqlNoSQL encapsulation , Include Redis and MongoDB And so on
cn.hutool.db.nosql.mongoMongoDB Encapsulation of database operations
cn.hutool.db.nosql.redisRedis(Jedis) Encapsulation of database operations
cn.hutool.db.sqlSQL Statement and Statement Build encapsulation
cn.hutool.db.transaction Transaction related classes and operations
cn.hutool.dfaDFA Its full name is :Deterministic Finite Automaton, That is, to be sure that there is a finite automaton .
It's not hard to explain the principle , It is to construct a tree with all the keywords , And then walk through the tree with the text , Traversing to the leaf node means that the keyword exists in the article .
Let's ignore the time to build the keyword tree , Every time you look up the text, you just need to O(n) The complexity can be done .
cn.hutool.extra because Hutool The principle is not to rely on other configuration files , But most of the time, we need to do some tool classification support for the third-party libraries , therefore Hutoo-extra Package is mainly used to support tool class support of third-party libraries .
cn.hutool.extra.cglibCglib Library method encapsulation
cn.hutool.extra.compress be based on commons-compress Compression and decompression package
Support includes :gzip, bzip2, xz, lzma, Pack200, DEFLATE, Brotli, DEFLATE64, ZStandard and Z, the archiver formats are 7z,
ar, arj, cpio, dump, tar and zip Equiform .
cn.hutool.extra.compress.archiver be based on commons-compress The packaging ( Compress ) encapsulation
cn.hutool.extra.compress.extractor be based on commons-compress Unpacking ( decompression ) encapsulation
cn.hutool.extra.emoji be based on https://github.com/vdurmont/emoji-java Of Emoji Expression tools
cn.hutool.extra.expression Expression language engine encapsulation
cn.hutool.extra.expression.engine Expression language engine encapsulation
cn.hutool.extra.expression.engine.aviatorAviator Engine encapsulation , see :https://github.com/killme2008/aviatorscript
cn.hutool.extra.expression.engine.jexlJexl3 Engine encapsulation , see :https://github.com/apache/commons-jexl
cn.hutool.extra.expression.engine.jfireelJfireEL Engine encapsulation
see :https://gitee.com/eric_ds/jfireEL
cn.hutool.extra.expression.engine.mvelMVEL (MVFLEX Expression Language) Engine encapsulation
see :https://github.com/mvel/mvel
cn.hutool.extra.expression.engine.rhinorhino Engine encapsulation
see :https://github.com/mozilla/rhino
cn.hutool.extra.expression.engine.spelSpring-Expression Engine encapsulation
see :https://github.com/spring-projects/spring-framework/tree/master/spring-expression
cn.hutool.extra.ftp be based on Apache Commons Net Packaged FTP Tools
cn.hutool.extra.mail Email encapsulation , be based on javax-mail library , The entrance is MailUtil
cn.hutool.extra.pinyin Phonetic tool encapsulation , The entrance is PinyinUtil
cn.hutool.extra.pinyin.engine Pinyin concrete implementation
cn.hutool.extra.pinyin.engine.bopomofo4j Encapsulates the Bopomofo4j The engine of .
cn.hutool.extra.pinyin.engine.houbbpinyin Encapsulates the Pinyin The engine of .
cn.hutool.extra.pinyin.engine.jpinyin Encapsulates the Jpinyin The engine of .
cn.hutool.extra.pinyin.engine.pinyin4j Encapsulates the Pinyin4j The engine of .
cn.hutool.extra.pinyin.engine.tinypinyin Encapsulates the TinyPinyin The engine of .
cn.hutool.extra.qrcode QR code encapsulation , be based on zxing library , The entrance is QrCodeUtil
cn.hutool.extra.servletServlet encapsulation , Include Servlet Parameters to obtain 、 Upload files 、Response Write etc , The entrance is ServletUtil
cn.hutool.extra.springSpring Related tool encapsulation
cn.hutool.extra.sshJsch encapsulation , Including port mapping 、SFTP Package, etc , The entrance is JschUtil
cn.hutool.extra.template Third party template engine encapsulation , Provide a unified interface for adapting to the third-party template engine
cn.hutool.extra.template.engine Third party template engine implementation
cn.hutool.extra.template.engine.beetlBeetl Realization , For an introduction to the template engine, see :http://ibeetl.com/
cn.hutool.extra.template.engine.enjoyJfinal Family Enjoy Template Engine Implementation , see :https://jfinal.com/doc/6-1
cn.hutool.extra.template.engine.freemarkerFreemarker Realization
see :https://freemarker.apache.org/
cn.hutool.extra.template.engine.jetbrickjetbrick-template Realization , For an introduction to the template engine, see :https://github.com/subchen/jetbrick-template-2x
cn.hutool.extra.template.engine.jetbrick.loaderjetbrick-template Realization , Special resource loader
For an introduction to the template engine, see :https://github.com/subchen/jetbrick-template-2x
cn.hutool.extra.template.engine.rythmRythm Realization , see :http://www.rythmengine.org/
cn.hutool.extra.template.engine.thymeleafThymeleaf Realization , see :https://www.thymeleaf.org/
cn.hutool.extra.template.engine.velocityVelocity Realization
see :http://velocity.apache.org/
cn.hutool.extra.template.engine.witWit Realization , see :http://zqq90.github.io/webit-script/
cn.hutool.extra.tokenizer Chinese word segmentation
By defining a unified interface , Adapt to the third-party word segmentation engine
cn.hutool.extra.tokenizer.engine Third party word segmentation engine implementation
cn.hutool.extra.tokenizer.engine.analysisLucene-analysis Word segmentation Abstract encapsulation
Project address :https://github.com/apache/lucene-solr/tree/master/lucene/analysis
cn.hutool.extra.tokenizer.engine.ansjAnsj Participle implementation
Project address :https://github.com/NLPchina/ansj_seg
cn.hutool.extra.tokenizer.engine.hanlpHanLP Word segmentation engine implementation
Project address :https://github.com/hankcs/HanLP
cn.hutool.extra.tokenizer.engine.ikanalyzerIKAnalyzer Word segmentation engine implementation
Project address :https://github.com/yozhao/IKAnalyzer
cn.hutool.extra.tokenizer.engine.jcsegJcseg Word segmentation engine implementation
Project address :https://gitee.com/lionsoul/jcseg
cn.hutool.extra.tokenizer.engine.jiebaJieba Word segmentation engine implementation
Project address :https://github.com/huaban/jieba-analysis
cn.hutool.extra.tokenizer.engine.mmsegmmseg4j Word segmentation engine implementation
Project address :https://github.com/chenlb/mmseg4j-core
cn.hutool.extra.tokenizer.engine.mynlpMYNLP chinese NLP Toolkit word segmentation implementation
Project address :https://github.com/mayabot/mynlp/
cn.hutool.extra.tokenizer.engine.wordWord Word segmentation engine implementation
Project address :https://github.com/ysc/word
cn.hutool.extra.validation be based on JSR-380 Standard calibration tool class , Encapsulates the javax.validation Of API
cn.hutool.httpHutool-http in the light of JDK Of HttpUrlConnection Make a layer of packaging , To simplify the HTTPS request 、 Upload files 、Cookie Memory and other operations , send Http The request becomes extremely simple .
cn.hutool.http.body The request body encapsulates the implementation
cn.hutool.http.cookie Customize Cookie
cn.hutool.http.serverHttp Server encapsulation
cn.hutool.http.server.actionHttpServer encapsulation
cn.hutool.http.server.filterFilter Realize packaging
cn.hutool.http.server.handlerHttpHandler Realize packaging
cn.hutool.http.sslSSL encapsulation
cn.hutool.http.useragentUser-Agent analysis
cn.hutool.http.webserviceWebservice Client encapsulation implementation
cn.hutool.jsonJSON encapsulation , be based on json.org Official library transformation
cn.hutool.json.serializeJSON Custom serialization and deserialization interfaces and default implementations
cn.hutool.json.xmlJSON And XML Mutual conversion encapsulation , be based on json.org Official library transformation
cn.hutool.jwtJSON Web Token (JWT) encapsulation
cn.hutool.jwt.signersJWT Signature encapsulation
cn.hutool.logHutool-log It's just a general facade for logs , Function like Slf4j.
Join according to ClassPath Medium jar The implementation of packet dynamic detection log , Make the log more convenient and flexible .
cn.hutool.log.dialect Implementation encapsulation of the third-party log library
cn.hutool.log.dialect.commonsApache-Commons-Logging The implementation of the log base is encapsulated
cn.hutool.log.dialect.console Implementation encapsulation of console output
cn.hutool.log.dialect.jbossjboss-logging Realization
cn.hutool.log.dialect.jdkJDK-Logging Implementation encapsulation of
cn.hutool.log.dialect.log4jLog4j Implementation encapsulation of
cn.hutool.log.dialect.log4j2Log4j2 Implementation encapsulation of
cn.hutool.log.dialect.logtubeLogTube Implementation encapsulation of
cn.hutool.log.dialect.slf4jSlf4j Implementation encapsulation of
cn.hutool.log.dialect.tinylogtinylog Implementation encapsulation of
Packaging includes TinyLog and TinyLog2
cn.hutool.log.level Log print interface definitions defined by log level
cn.hutool.poiPOI Encapsulation implementation
Java in the light of MS Office There are only a few libraries of operations , The more famous one is Apache Of POI library .
This library is extremely powerful , But it's not easy to use .Hutool in the light of POI Encapsulate some common tools , send Java operation Excel Wait until the file becomes extremely simple .
cn.hutool.poi.excelPOI Chinese vs Excel Read write encapsulation , The entrance is ExcelUtil
cn.hutool.poi.excel.cellExcel Cell related classes in , The entrance is CellUtil
cn.hutool.poi.excel.cell.settersExcel Set related classes in the cells in the , some CellSetter Implementation class of
cn.hutool.poi.excel.cell.values
cn.hutool.poi.excel.editors Cell value editor , For internal use
cn.hutool.poi.excel.reader Data reading interface and its implementation , This package defines SheetReader, Through the implementation of this interface , Realization sheet The data in is read as different types .
cn.hutool.poi.excel.saxSax Way to operate Excel Way of encapsulation
cn.hutool.poi.excel.sax.handlerSax Read the definition and implementation of BOC processor
cn.hutool.poi.excel.styleExcel Style encapsulation , The entrance is :StyleUtil
cn.hutool.poi.exceptionsPOI Related anomalies
cn.hutool.poi.ofd Open layout document (Open Fixed-layout Document ) encapsulation , be based on ofdrw(https://gitee.com/Trisia/ofdrw)
cn.hutool.poi.wordPOI Chinese vs Word Operation package
cn.hutool.scriptScript The module is mainly for Java Of javax.script encapsulation , Can run Javascript Script .
cn.hutool.settingSetting The module is mainly for Properties File read / write encapsulation , At the same time, define a set of configuration file specifications , Achieve a well compatible configuration tool .
cn.hutool.setting.dialect The configuration file implements encapsulation , for example Properties encapsulation Props
cn.hutool.setting.profile Configure environment encapsulation , for example Profile You can customize the location of configuration files in different environments
cn.hutool.setting.yamlYAML Read write encapsulation of files , be based on snakeyaml
cn.hutool.socketSocket Socket related tool class encapsulation
cn.hutool.socket.aioAIO Related packaging
cn.hutool.socket.nioNIO Related packaging
cn.hutool.socket.protocol Message protocol interface and its implementation
cn.hutool.systemSystem The module mainly obtains the system 、JVM、 Memory 、CPU Etc , In order to dynamically monitor the system status
cn.hutool.system.oshiOshi Library encapsulation
https://github.com/oshi/oshi

5、 ... and 、 Code using

Official references

String related

/**
     *  String related 
     */
    @Test
    public void test1() {
        int a = 1;
        String a1 = Convert.toStr(a);
        System.out.println(a1);
        long[] b = {1,2,3,4,5};
        String b1 = Convert.toStr(b);
        System.out.println(b1);
        
        String str = " You can't see the Yellow River coming up , Running to the sea and never returning ";
        // Use of string formatting 
        System.out.println(StrUtil.format(" String content :{}", str));
        // Determines if the string is empty 
        System.out.println(" Whether the string is empty :" + StrUtil.isEmpty(str));
        // Original usage 
        System.out.println(" Whether the string is empty 2:" + StringUtils.isEmpty(str));
        System.out.println(" Whether the string is empty 3:" + StringUtils.isBlank(str));
    }

BigDecimal Addition, subtraction, multiplication and division

/**
     * BigDecimal Addition, subtraction, multiplication and division 
     *
     * @author libusi
     */
    @Test
    public void test2() {
        BigDecimal b1 = new BigDecimal("8.256");
        BigDecimal b2 = new BigDecimal("6.347");

        // Add 
        BigDecimal addResult = NumberUtil.add(b1, b2);
        System.out.println(" Addition result :" + addResult);

        // Subtraction 
        BigDecimal subResult = NumberUtil.sub(b1, b2);
        System.out.println(" Subtraction results :" + subResult);

        // Multiplication 
        BigDecimal mulResult = NumberUtil.mul(b1, b2);
        System.out.println(" The result of multiplication :" + mulResult);

        // division 
        BigDecimal divResult = NumberUtil.div(b1, b2);
        System.out.println(" Division result :" + divResult);

        // Keep two decimal places 
        BigDecimal roundResult = NumberUtil.round(b1, 2);
        System.out.println(" Keep two decimal places :" + roundResult);
    }

Time tools (hutool-core

The date and time package is Hutool One of the core packages of , Provide targeted JDK in Date and Calendar Encapsulation of objects


IO Stream correlation

io Package packaging is mainly aimed at convection 、 Read write encapsulation of files , It's mainly about tools , Provides encapsulation of common functions


Common tools

The tool classes in this package are unclassified , Provide some common tools and methods .
This package is classified as XXXUtil, Provide a large number of tools and methods . In a tool class , Mainly by class method (static Method ) Mainly , And each class cannot be instantiated as an object , A method is an independent function , No interaction .


Linguistic characteristics

Linguistic characteristics , namely lang package , Mainly aimed at JDK The perfection of some data structures and interfaces in


JavaBean

in the light of JavaBean There has been a BeanUtil Tool encapsulation , And extended .


Collection classes

The collection package includes Enumeration、Iterator And so on


Map

Earliest Map The related tools are included in CollUtil Medium , But considering that Map And set are not the same kind of data structure , So stand alone , And Hutool Encapsulates many custom Map class , Therefore, it is packed separately .


Codec code

code Code and decode , contain Base62,Base64 and Base32 And so on .


Text operation

Contains the CSV File processing tools , Reusable string generator ,Unicode Code conversion tools and string cutting tools


annotation

Tool classes that encapsulate methods such as annotation acquisition


The comparator

Various comparators (Comparator) Implementation and encapsulation


abnormal

Encapsulate for exceptions , For example, the package is RuntimeException


mathematics

This tool is NumberUtil A supplement to ,NumberUtil Packaging that favors simple mathematical calculations ,MathUtil Biased towards complex mathematical calculations


picture

Picture tools and picture editors


The Internet

Web tools and URL generator


The configuration file (Hutool-setting)

Setting In addition to compatibility Properties Out of file format , It also provides some unique features , These functions include :
Various encoding methods support
Variables support
Group support


journal (Hutool-log)

Accurately speaking ,Hutool-log It's just a general facade for logs , Function like Slf4j


cache (Hutool-cache)

Hutool-cache The module was first jodd-cache Inspired by the ( Most of the logic today is still related to jodd bring into correspondence with ), This module provides a simple implementation of caching , Very useful for simple caching requirements in small projects .


JSON(Hutool-json)

Undeniable? , Now excellent JSON There are so many frames , I often use something like Ali's FastJSON,Jackson And so on are all excellent bags , Outstanding performance , Simple and easy to use .Hutool At first, I didn't want to write one by myself JSON, But in the encapsulation of various tools , Find out JSON Already indispensable , So it will json.org Official JSON Analysis is included in it , To transform . In the process of transformation , Actively absorb the advantages of other class libraries , Optimize member methods , Abstract interfaces and classes , To form Hutool-json.


Encryption and decryption (Hutool-crypto)

There are three kinds of encryption :
Symmetric encryption (symmetric), for example :AES、DES etc.
Asymmetric encryption (asymmetric), for example :RSA、DSA etc.
Abstract encryption (digest), for example :MD5、SHA-1、SHA-256、HMAC etc.
hutool-crypto These three encryption types are encapsulated separately , And provide most commonly used encryption algorithms .

package com.god.demo.utils;

import cn.hutool.core.codec.Base64;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.asymmetric.KeyType;
import cn.hutool.crypto.asymmetric.RSA;
import cn.hutool.crypto.digest.DigestAlgorithm;
import cn.hutool.crypto.digest.DigestUtil;
import cn.hutool.crypto.digest.Digester;
import cn.hutool.crypto.symmetric.AES;
import cn.hutool.crypto.symmetric.SymmetricAlgorithm;
import cn.hutool.crypto.symmetric.SymmetricCrypto;
import org.junit.jupiter.api.Test;

public class SmTest {

    /**
     * md5 encryption 
     */
    @Test
    public void test2() {
        String content = " You don't see yellow SecureUtil The water of the river comes up from the sky , Running to the sea and never returning ";
        String encrypt = SecureUtil.md5(content);

        System.out.println(" Content before encryption :" + content);
        System.out.println(" Encrypted content :" + encrypt);
    }

    // Abstract encryption algorithm 
    @Test
    public void fun1() {
        // Get a summary 
        //MD5
        String content = " You don't see yellow SecureUtil The water of the river comes up from the sky , Running to the sea and never returning ";
        String encrypt = SecureUtil.md5(content);

        System.out.println(" Content before encryption :" + content);
        System.out.println(" Encrypted content :" + encrypt);

        // Mode one 
        Digester md5 = new Digester(DigestAlgorithm.MD5);
        String str = md5.digestHex(content);
        System.out.println(str);

        // Mode two 
        String string = DigestUtil.md5Hex(content);
        System.out.println(string);
    }

    // Asymmetric encryption 
    @Test
    public void fun2() {
        // Asymmetric encryption 
        RSA rsa = new RSA();
        // Get private key 
        rsa.getPrivateKey();
        rsa.getPrivateKeyBase64();
        // Get the public key 
        rsa.getPublicKey();
        rsa.getPublicKeyBase64();

        // Public key encryption , Private key encryption 
        byte[] encrypt = rsa.encrypt(StrUtil.bytes("RAS test ", CharsetUtil.CHARSET_UTF_8), KeyType.PublicKey);
        byte[] decrypt = rsa.decrypt(encrypt, KeyType.PrivateKey);
        String encode = Base64.encode(decrypt);
        System.out.println(encode);
        // Private key encryption , Public key decryption 
        byte[] encrypt2 = rsa.encrypt(StrUtil.bytes("RAS test ", CharsetUtil.CHARSET_UTF_8), KeyType.PrivateKey);
        byte[] decrypt2 = rsa.decrypt(encrypt2, KeyType.PublicKey);
        String encode2 = Base64.encode(decrypt2);
        System.out.println(encode2);
    }

    @Test
    public void fun4() {
        String content = "asdf1234";
        byte[] key = "hahaaha".getBytes();
        // structure 
        SymmetricCrypto aes = new SymmetricCrypto(SymmetricAlgorithm.AES, key);
        // encryption 
        byte[] encrypt = aes.encrypt(content);
        // Decrypt 
        byte[] decrypt = aes.decrypt(encrypt);
    }

    // Symmetric encryption 
    @Test
    public void fun3() {
        // The first one is : With AES Algorithm 
        String content = "test chinese ";
        // Random key generation 
        byte[] key = SecureUtil.generateKey(SymmetricAlgorithm.AES.getValue()).getEncoded();
        // structure 
        SymmetricCrypto aes = new SymmetricCrypto(SymmetricAlgorithm.AES, key);
        // encryption 
        byte[] encrypt = aes.encrypt(content);
        // Decrypt 
        byte[] decrypt = aes.decrypt(encrypt);

        // encryption 16 Hexadecimal said 
        String encryptHex = aes.encryptHex(content);
        System.out.println("AES encryption 16 Hexadecimal said :" + encryptHex);
        // Decrypt to string 
        String decryptStr = aes.decryptStr(encryptHex, CharsetUtil.CHARSET_UTF_8);
        System.out.println("AES Decrypt to string :" + decryptStr);

        // The second kind  DESede encryption 
        String content2 = "test chinese ";
        byte[] key2 = SecureUtil.generateKey(SymmetricAlgorithm.DESede.getValue()).getEncoded();
        SymmetricCrypto des = new SymmetricCrypto(SymmetricAlgorithm.DESede, key2);
        // encryption 
        byte[] encrypt2 = des.encrypt(content2);
        // Decrypt 
        byte[] decrypt2 = des.decrypt(encrypt2);

        // Encrypted to 16 Base string (Hex Express )
        String encryptHex2 = des.encryptHex(content2);
        System.out.println("DESede encryption 16 Hexadecimal said :" + encryptHex2);
        String decryptStr2 = des.decryptStr(encryptHex2);
        System.out.println("DESede Decrypt to string :" + decryptStr2);

        // The third kind of AES encapsulation 
        String content3 = "test chinese ";
        // Random key generation 
        byte[] key3 = SecureUtil.generateKey(SymmetricAlgorithm.AES.getValue()).getEncoded();
        // structure 
        AES aes3 = SecureUtil.aes(key3);
        // encryption 
        byte[] encrypt3 = aes3.encrypt(content3);
        // Decrypt 
        byte[] decrypt3 = aes3.decrypt(encrypt3);
        // Encrypted to 16 Hexadecimal said 
        String encryptHex3 = aes3.encryptHex(content3);
        System.out.println("AES Encapsulation encryption 16 Hexadecimal said :" + encryptHex3);
        // Decrypt to string 
        String decryptStr3 = aes3.decryptStr(encryptHex3, CharsetUtil.CHARSET_UTF_8);
        System.out.println("AES Encapsulate and decrypt as string :" + decryptStr3);
    }
}


DFA lookup (Hutool-dfa)

in the light of DFA Algorithm and some implementation on the Internet ,Hutool It has been sorted out and improved , Finally, it will form the present Hutool-dfa modular

database (Hutool-db)

Hutool-db It's a JDBC Database operation tool class encapsulated on the basis of , By packing , Use ActiveRecord Think about operating the database . stay Hutool-db in , Use Entity( It's essentially a Map) Instead of Bean Make database operation more flexible , At the same time provide Bean and Entity The transformation of provides traditional ORM Compatible support for .


HTTP client (Hutool-http)

Hutool-http in the light of JDK Of HttpUrlConnection Make a layer of packaging , To simplify the HTTPS request 、 Upload files 、Cookie Memory and other operations , send Http The request becomes extremely simple


Timing task (Hutool-cron)

Hutool The timing task module and Linux Of Crontab It's very similar in use , Through one cron.setting The configuration file , Simple call start() The method can be used simply .

It also provides second matching and year matching Quartz There are only functions , The expressions of timed tasks are also compatible with Crontab(Cron4j) and Quartz The expression of .


Expand (Hutool-extra)

because Hutool The principle is not to rely on other configuration files , But most of the time, we need to do some tool classification support for the third-party libraries , therefore Hutoo-extra Package is mainly used to support tool class support of third-party libraries
Bloon filtration (Hutool-bloomFilter)

The bloon filter ( English :Bloom Filter) yes 1970 Proposed by bron in . It's actually a very long binary vector and a series of random mapping functions . The bloom filter can be used to retrieve whether an element is in a collection . Its advantage is that the space efficiency and query time are far more than the general algorithm , The disadvantage is that it has certain error recognition rate and deletion difficulty .

The principle of Bloom filter is , When an element is added to a collection , adopt K Hash functions map this element to... In a group of bits K A little bit , Set them as 1. Search time , We just need to see if these points are all 1 Just ( about ) Know if it's in the collection : If any of these points 0, The inspected element must not be in ; If it's all 1, Then the inspected element is likely to be . This is the basic idea of bloon filter .

Reference resources :https://www.cnblogs.com/z941030/p/9218356.html


section (Hutool-aop)

AOP The module is mainly for JDK Dynamic proxy in , Abstract dynamic proxy is faceted class Aspect, adopt ProxyUtil The proxy tool class merges the faceted object with the proxied object , Generate a proxy object , Thus, common functions can be performed before and after the execution of each method .


Script (Hutool-script)

script The module is mainly for Java Of javax.script encapsulation , Can run Javascript Script .

This module is very simple . The main functions are focused on SCriptUtil In this tool class .


Office The document operation (Hutool-poi)

Hutool-poi Is aimed at Apache POI Encapsulation , Therefore, users need to introduce POI library ,Hutool Default not to introduce .


system call (Hutool-system)

System property calls -SystemUtil and Oshi encapsulation -OshiUtil


Graphic verification code (Hutool-captcha)

Verification code generation and verification function


The Internet Socket(Hutool-socket)

When developing web applications , We'll meet again Socket The concept .Socket It's an abstract concept , An application passes through a Socket To establish a remote connection , and Socket Through internal TCP/IP The protocol transmits data to the network .
JDK Provided in Socket function , Include :
BIO
NIO
AIO
Hutool Only aim at NIO and AIO It's a simple package , For simplification Socket Asynchronous development .
 

For more specific usage, please refer to Official documents

Please like it , Form good habits !

Please leave a message if you have any questions !

原网站

版权声明
本文为[Java Tony]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/161/202206101442535599.html