This edition recommends a small but complete library of Java utility classes-Hutool。
Through static method encapsulation, Hutool reduces the learning cost of related apis, improves work efficiency, and makes Java have the expression ability of functional language, which is more convenient to use.
The tool method in Hutool comes from the elaboration of each user, it covers all aspects of the underlying code of Java development, it is not only a tool to solve small problems in the development of large projects, but also the efficiency of small projects.
Hutool is a friendly alternative to the “util” package in a project. It saves developers time to package common classes and common tool methods in the project, keeps development focused on the business, and minimizes bugs caused by imperfect packaging.
Inclusion component
A Java basic tool class, the file, stream, encryption and decryption, transcoding, regular, thread, XML and other JDK methods are encapsulated, composed of various Util tool classes, while providing the following components:
module |
introduce |
hutool-aop |
JDK dynamic proxy package, providing non-IOC cross-section support |
hutool-bloomFilter |
Bloom filtering provides Bloom filtering for some Hash algorithms |
hutool-cache |
Simple cache implementation |
hutool-core |
Core, including Bean operations, dates, various UTILs, etc |
hutool-cron |
The Scheduled Tasks module, which provides scheduled tasks like Crontab expressions |
hutool-crypto |
Encryption and decryption module, providing symmetric, asymmetric and abstract algorithm encapsulation |
hutool-db |
JDBC encapsulated data manipulation, based on ActiveRecord ideas |
hutool-dfa |
Multi-keyword search based on DFA model |
hutool-extra |
Extension modules that encapsulate third parties (template engine, mail, Servlet, QR code, Emoji, FTP, word segmentation, etc.) |
hutool-http |
Http client encapsulation based on HttpUrlConnection |
hutool-log |
Automatically identify the log facade of the log implementation |
hutool-script |
Script execution encapsulation, such as Javascript |
hutool-setting |
More powerful Setting profiles and Properties encapsulation |
hutool-system |
System parameter call encapsulation (JVM information, etc.) |
hutool-json |
JSON come true |
hutool-captcha |
Image verification code implementation |
hutool-poi |
Encapsulation of Excel and Word in POI |
hutool-socket |
Socket encapsulation of NIO and AIO based on Java |
hutool-jwt |
JSON Web Token (JWT)Encapsulated implementation |
install and use
Maven
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.7.15</version>
</dependency>
Gradle
implementation 'cn.hutool:hutool-all:5.7.15'
Maven site:
https://repo1.maven.org/maven2/cn/hutool/hutool-all/5.7.15/
Example Codec coding
1.Base62 Encoding and decoding-Base62
Description:
The Base62 encoding consists of 10 digits, 26 uppercase letters, and 26 lowercase letters, and is mostly used in security fields and short URL generation.
Use:
String a = "A very long string 66";
// 17vKU8W4JMG8dQF8lk9VNnkdMOeWn4rJMva6F0XsLrrT53iKBnqo
String encode = Base62.encode(a);
// return to a
String decodeStr = Base62.decodeStr(encode);
2.Base64 Encoding and decoding-Base64
Description:
Base64 encoding is to use 64 (2 to the sixth power) ASCII characters to represent 256 (2 to the eighth power) ASCII characters, that is, a three-digit binary array after encoding into four ASCII characters displayed, the length increased by 1/3 than the original.
Use:
String a = "A very long string";
//5Lym5a625piv5LiA5Liq6Z2e5bi46ZW/55qE5a2X56ym5Liy
String encode = Base64.encode(a);
// return to a
String decodeStr = Base64.decodeStr(encode);
3.Morse Code. -Morse
Description:
Morse code, also known as Morse Code, is an on-off signal code that expresses letters, numbers, and punctuation symbols in different sequences.
Morse code is defined by dot (.) dash (-) is made up of two symbols.
Use:
//coding:
final Morse morseCoder = new Morse();
String text = "Hello World!";
// ...././.-../.-../---/-...../.--/---/.-./.-../-../-.-.--/
morseCoder.encode(text);
//decode:
String text = "Hello, world!";
// -..----.--...../-.--..-.-----.-/--------....--../-..---....-.--./---.-.-.-..--../--------.......-/
String morse = morseCoder.encode(text);
morseCoder.decode(morse);
4.BCD Code -BCD
Description:
BCD codes (Binary-Coded Decimal) are also called binary-coded decimal codes or binary-coded decimal codes.
BCD code This form of encoding uses four bits to store a decimal digit, so that the conversion between binary and decimal can be carried out quickly.
Use:
String strForTest = "123456ABCDEF";
// turn BCD
byte[] bcd = BCD.strToBcd(strForTest);
// decode BCD
String str = BCD.bcdToStr(bcd);
5.Turn the n-bit cipher -Rot
Description:
RotN (rotate by N places) is a simple substitution cipher, a variant of the Caesar cipher developed in ancient Rome.
Use:
String str = "1f2e9df6131b480b9fdddc633cf24996";
// 4s5r2qs9464o713o2sqqqp966ps57229
String encode13 = Rot.encode13(str);
// decode
String decode13 = Rot.decode13(encode13);
6.Punycode come true-PunyCode.md
Description:
Punycode is a coding system based on the RFC 3492 standard, which is used to convert domain names from the Unicode encoding used in local languages to the encoding used in the DNS system.
Use:
String text = "Hutool encoder";
// Hutool-ux9js33tgln
String strPunyCode = PunyCode.encode(text);
// Hutool encoder
String decode = PunyCode.decode("Hutool-ux9js33tgln");
// Hutool encoder
decode = PunyCode.decode("xn--Hutool-ux9js33tgln");
More usage documents: click download