├── .gitignore
├── .idea
├── $PRODUCT_WORKSPACE_FILE$
├── .gitignore
├── .name
├── compiler.xml
├── encodings.xml
├── inspectionProfiles
│ └── Project_Default.xml
├── misc.xml
└── vcs.xml
├── .mvn
└── wrapper
│ ├── MavenWrapperDownloader.java
│ ├── maven-wrapper.jar
│ └── maven-wrapper.properties
├── .project
├── HELP.md
├── README.md
├── mvnw
├── mvnw.cmd
├── pom.xml
└── src
├── log4j.properties
├── main
├── java
│ └── com
│ │ └── tangerineSpecter
│ │ └── javaBaseUtils
│ │ ├── JavaBaseUtilsApplication.java
│ │ ├── common
│ │ ├── DocumentInfo.java
│ │ ├── annotation
│ │ │ ├── ClassInfo.java
│ │ │ └── MethodInfo.java
│ │ ├── config
│ │ │ └── SwaggerConfig.java
│ │ ├── exception
│ │ │ └── GlobalException.java
│ │ ├── filter
│ │ │ └── ManageLogAspect.java
│ │ ├── img
│ │ │ └── show_logo.gif
│ │ ├── servlet
│ │ │ ├── AppRunWrapper.java
│ │ │ └── InitProperties.java
│ │ ├── test
│ │ │ └── UtilTest.java
│ │ └── util
│ │ │ ├── AudioUtils.java
│ │ │ ├── Base64Utils.java
│ │ │ ├── BaseUtils.java
│ │ │ ├── CollUtils.java
│ │ │ ├── Constant.java
│ │ │ ├── DecipheringBaseUtils.java
│ │ │ ├── DecipheringUtils.java
│ │ │ ├── DirUtils.java
│ │ │ ├── EasyExcelUtils.java
│ │ │ ├── EncrypUtils.java
│ │ │ ├── ExcelUtils.java
│ │ │ ├── FileUtil.java
│ │ │ ├── HttpUtils.java
│ │ │ ├── IKTokenizerTool.java
│ │ │ ├── ImageUtils.java
│ │ │ ├── JsonUtils.java
│ │ │ ├── LoggerWordPool.java
│ │ │ ├── LollipopUtils.java
│ │ │ ├── NumChainCal.java
│ │ │ ├── NumberUtils.java
│ │ │ ├── PDFUtils.java
│ │ │ ├── QrCodeUtils.java
│ │ │ ├── RandomUtils.java
│ │ │ ├── RegExUtils.java
│ │ │ ├── StringUtils.java
│ │ │ ├── TimeUtils.java
│ │ │ ├── ZipUtils.java
│ │ │ ├── cache
│ │ │ ├── JedisMapTool.java
│ │ │ ├── JedisSetTool.java
│ │ │ └── JedisTool.java
│ │ │ └── enums
│ │ │ └── FileTypeEnum.java
│ │ └── controller
│ │ └── util
│ │ ├── EasyExcelController.java
│ │ ├── PoiExcelController.java
│ │ ├── StringController.java
│ │ ├── TimeController.java
│ │ └── ZipController.java
└── resources
│ └── application.properties
└── test
└── java
└── com
└── tangerineSpecter
└── javaBaseUtils
└── JavaBaseUtilsApplicationTests.java
/.gitignore:
--------------------------------------------------------------------------------
1 | ## .gitignore for Grails 1.2 and 1.3
2 |
3 | # .gitignore for maven
4 | target/
5 | *.releaseBackup
6 |
7 | # web application files
8 | #/web-app/WEB-INF
9 |
10 | # IDE support files
11 | /.classpath
12 | /.launch
13 | /.project
14 | /.settings
15 | /*.launch
16 | /*.tmproj
17 | /ivy*
18 | /eclipse
19 |
20 | # default HSQL database files for production mode
21 | /prodDb.*
22 |
23 | # general HSQL database files
24 | *Db.properties
25 | *Db.script
26 |
27 | # logs
28 | /stacktrace.log
29 | /test/reports
30 | /logs
31 | *.log
32 | *.log.*
33 |
34 | # project release file
35 | /*.war
36 |
37 | # plugin release file
38 | /*.zip
39 | /*.zip.sha1
40 |
41 | # older plugin install locations
42 | /plugins
43 | /web-app/plugins
44 | /web-app/WEB-INF/classes
45 |
46 | # "temporary" build files
47 | target/
48 | out/
49 | build/
50 |
51 | # other
52 | *.iws
53 |
54 | #.gitignore for java
55 | *.class
56 |
57 | # Package Files #
58 | *.jar
59 | *.war
60 | *.ear
61 |
62 | ## .gitignore for eclipse
63 |
64 | *.pydevproject
65 | .project
66 | .metadata
67 | bin/**
68 | tmp/**
69 | tmp/**/*
70 | *.tmp
71 | *.bak
72 | *.swp
73 | *~.nib
74 | local.properties
75 | .classpath
76 | .settings/
77 | .loadpath
78 |
79 | # External tool builders
80 | .externalToolBuilders/
81 |
82 | # Locally stored "Eclipse launch configurations"
83 | *.launch
84 |
85 | # CDT-specific
86 | .cproject
87 |
88 | # PDT-specific
89 | .buildpath
90 |
91 | ## .gitignore for intellij
92 |
93 | *.iml
94 | *.ipr
95 | *.iws
96 | .idea/
97 |
98 | ## .gitignore for linux
99 | .*
100 | !.gitignore
101 | *~
102 |
103 | ## .gitignore for windows
104 |
105 | # Windows image file caches
106 | Thumbs.db
107 | ehthumbs.db
108 |
109 | # Folder config file
110 | Desktop.ini
111 |
112 | # Recycle Bin used on file shares
113 | $RECYCLE.BIN/
114 |
115 | ## .gitignore for mac os x
116 |
117 | .DS_Store
118 | .AppleDouble
119 | .LSOverride
120 | Icon
121 |
122 |
123 | # Thumbnails
124 | ._*
125 |
126 | # Files that might appear on external disk
127 | .Spotlight-V100
128 | .Trashes
129 |
130 | ## hack for graddle wrapper
131 | !wrapper/*.jar
132 | !**/wrapper/*.jar
--------------------------------------------------------------------------------
/.idea/$PRODUCT_WORKSPACE_FILE$:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /workspace.xml
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | javaBaseUtils
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.mvn/wrapper/MavenWrapperDownloader.java:
--------------------------------------------------------------------------------
1 | /*
2 | Licensed to the Apache Software Foundation (ASF) under one
3 | or more contributor license agreements. See the NOTICE file
4 | distributed with this work for additional information
5 | regarding copyright ownership. The ASF licenses this file
6 | to you under the Apache License, Version 2.0 (the
7 | "License"); you may not use this file except in compliance
8 | with the License. You may obtain a copy of the License at
9 |
10 | https://www.apache.org/licenses/LICENSE-2.0
11 |
12 | Unless required by applicable law or agreed to in writing,
13 | software distributed under the License is distributed on an
14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | KIND, either express or implied. See the License for the
16 | specific language governing permissions and limitations
17 | under the License.
18 | */
19 |
20 | import java.io.File;
21 | import java.io.FileInputStream;
22 | import java.io.FileOutputStream;
23 | import java.io.IOException;
24 | import java.net.URL;
25 | import java.nio.channels.Channels;
26 | import java.nio.channels.ReadableByteChannel;
27 | import java.util.Properties;
28 |
29 | public class MavenWrapperDownloader {
30 |
31 | /**
32 | * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
33 | */
34 | private static final String DEFAULT_DOWNLOAD_URL =
35 | "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar";
36 |
37 | /**
38 | * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
39 | * use instead of the default one.
40 | */
41 | private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
42 | ".mvn/wrapper/maven-wrapper.properties";
43 |
44 | /**
45 | * Path where the maven-wrapper.jar will be saved to.
46 | */
47 | private static final String MAVEN_WRAPPER_JAR_PATH =
48 | ".mvn/wrapper/maven-wrapper.jar";
49 |
50 | /**
51 | * Name of the property which should be used to override the default download url for the wrapper.
52 | */
53 | private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
54 |
55 | public static void main(String args[]) {
56 | System.out.println("- Downloader started");
57 | File baseDirectory = new File(args[0]);
58 | System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
59 |
60 | // If the maven-wrapper.properties exists, read it and check if it contains a custom
61 | // wrapperUrl parameter.
62 | File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
63 | String url = DEFAULT_DOWNLOAD_URL;
64 | if(mavenWrapperPropertyFile.exists()) {
65 | FileInputStream mavenWrapperPropertyFileInputStream = null;
66 | try {
67 | mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
68 | Properties mavenWrapperProperties = new Properties();
69 | mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
70 | url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
71 | } catch (IOException e) {
72 | System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
73 | } finally {
74 | try {
75 | if(mavenWrapperPropertyFileInputStream != null) {
76 | mavenWrapperPropertyFileInputStream.close();
77 | }
78 | } catch (IOException e) {
79 | // Ignore ...
80 | }
81 | }
82 | }
83 | System.out.println("- Downloading from: : " + url);
84 |
85 | File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
86 | if(!outputFile.getParentFile().exists()) {
87 | if(!outputFile.getParentFile().mkdirs()) {
88 | System.out.println(
89 | "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'");
90 | }
91 | }
92 | System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
93 | try {
94 | downloadFileFromURL(url, outputFile);
95 | System.out.println("Done");
96 | System.exit(0);
97 | } catch (Throwable e) {
98 | System.out.println("- Error downloading");
99 | e.printStackTrace();
100 | System.exit(1);
101 | }
102 | }
103 |
104 | private static void downloadFileFromURL(String urlString, File destination) throws Exception {
105 | URL website = new URL(urlString);
106 | ReadableByteChannel rbc;
107 | rbc = Channels.newChannel(website.openStream());
108 | FileOutputStream fos = new FileOutputStream(destination);
109 | fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
110 | fos.close();
111 | rbc.close();
112 | }
113 |
114 | }
115 |
--------------------------------------------------------------------------------
/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TangerineSpecter/JavaBaseUtils/681ecd200def8b8a3b9aa5793d0959f785880db3/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip
2 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | BaseUtils
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/HELP.md:
--------------------------------------------------------------------------------
1 | # Getting Started
2 |
3 | ### Reference Documentation
4 | For further reference, please consider the following sections:
5 |
6 | * [Official Apache Maven documentation](https://maven.apache.org/guides/index.html)
7 |
8 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # JavaBaseUtils
2 |
3 | ## 简介
4 | 主要收集一些平时常用的Java开发工具类,内容在不断更新补充中...
5 |
6 |
7 | ### Java基本工具包:
8 | - 工具包地址:https://github.com/TangerineSpecter/JavaBaseUtils
9 |
10 | ### 版本号:
11 | - 项目版本:2.0.4
12 |
13 | - JDK版本:1.8
14 |
15 | ### 最后更新时间:
16 | > 2021-08-05
17 |
18 | ## 目录
19 |
20 | - [开始](#Getting_Menu)
21 | - [API](#Geting_Api)
22 | - [PDF工具类](#Geting_PdfUtils)
23 | - [字符串处理工具类](#Geting_StringUtils)
24 | - [数字处理工具类](#Geting_NumberUtils)
25 | - [加密工具类](#Geting_EncrypUtils)
26 | - [Excel处理工具类](#Geting_ExcelUtils)
27 | - [分词工具类](#Geting_IkTokenizerTool)
28 | - [文件工具类](#Geting_FileUtil)
29 | - [路径处理工具类](#Geting_DirUtils)
30 | - [时间处理工具类](#Geting_TimeUtils)
31 | - [图片处理工具类](#Geting_ImageUtils)
32 | - [随机工具类](#Geting_RandomUtils)
33 | - [正则表达式工具类](#Geting_RegExUtils)
34 | - [二维码生成工具类](#Geting_QrCodeUtils)
35 | - [压缩和解压工具类](#Geting_ZipUtils)
36 | - [Http工具类](#Geting_HttpUtils)
37 | ---
38 | ## PDF工具类 -> [PdfUtils](https://github.com/TangerineSpecter/JavaBaseUtils/blob/master/src/common/util/PdfUtils.java)
39 | 方法名 | 说明 | 参数 | 返回结果
40 | ------|------|-----|-----
41 | createPdf | 创建PDF | 无 | void(无)
42 | createPdf | 创建PDF | String(生成路径),List(文本内容) | void(无)
43 | ---
44 | ## 字符串处理工具类 -> [StringUtils](https://github.com/TangerineSpecter/JavaBaseUtils/blob/master/src/common/util/StringUtils.java)
45 | 方法名 | 说明 | 参数 | 返回结果
46 | ------|------|-----|-----
47 | isAllNumber | 判断所有字符串是否都为数字 | String\[](字符串集) | boolean(判断结果)
48 | isAnyEmpty | 判断多个字符串中是否有空值 | String\[](字符串参数集) | boolean(判断结果)
49 | getOrderNum | 订单号生成 | 无 | String(订单号)
50 | getLocalHostIp | 获取本机IP地址 | 无 | String(IP地址)
51 | randomString | 伪随机字符串 | int(字符串长度) | String(随机结果)
52 | subString | 截取字符串开头指定长度 | String(字符串内容),int(截取位置) | String(截取结果)
53 | isEmpty | 判断字符串是否为空 | String(字符串内容) | boolean(判断结果)
54 | isNumber | 判断是否为数字 | 无 | boolean(判断结果)
55 | ---
56 | ## 数字处理工具类 -> [NumberUtils](https://github.com/TangerineSpecter/JavaBaseUtils/blob/master/src/common/util/NumberUtils.java)
57 | 方法名 | 说明 | 参数 | 返回结果
58 | ------|------|-----|-----
59 | getFullPermutation | 从Array中拿出n个元素进行全排列 | char\[](字符数组),int(取出的元素个数) | void(无)
60 | getFullPermutation | 从Array中拿出n个元素进行全排列 | int\[](数字数组),int(需要取出的元素个数) | List(排列结果)
61 | listAll | 从m个元素中任取n个并对结果进行全排列 | List(装载排列结果list),int\[](数字数组),int(取出的元素个数) | void(无)
62 | listAll | 从m个元素中任取n个并对结果进行全排列 | List(装载排列结果list),char\[](字符数组),int(取出的元素个数) | void(无)
63 | ---
64 | ## 加密工具类 -> [EncrypUtils](https://github.com/TangerineSpecter/JavaBaseUtils/blob/master/src/common/util/EncrypUtils.java)
65 | 方法名 | 说明 | 参数 | 返回结果
66 | ------|------|-----|-----
67 | hash | 哈希加密算法 | String(需要加密的数据),String(加密算法名称) | String(加密数据)
68 | hash | 哈希加密算法 | byte\[](加密字节数组),String(加密算法名称) | String(加密数据)
69 | encodeHex | 将字节数组转换成十六进制字符串 | byte\[](字节数组) | String(十六进制字符串)
70 | ---
71 | ## Excel处理工具类 -> [ExcelUtils](https://github.com/TangerineSpecter/JavaBaseUtils/blob/master/src/common/util/ExcelUtils.java)
72 | 方法名 | 说明 | 参数 | 返回结果
73 | ------|------|-----|-----
74 | getExcel | 获取Excel数据 | String(Excel路径) | List(数据列表)
75 | createExcel | 创建Excel | String\[](表头),List(数据列表),boolean(新旧版本) | String(生成路径)
76 | ---
77 | ## 分词工具类 -> [IkTokenizerTool](https://github.com/TangerineSpecter/JavaBaseUtils/blob/master/src/common/util/IkTokenizerTool.java)
78 | 方法名 | 说明 | 参数 | 返回结果
79 | ------|------|-----|-----
80 | tokenizeKeyWord | 切分分词 | String(关键词),boolean(智能切分) | String(分词结果)
81 | tokenizeKeyWordList | 切分分词 | String(关键词),boolean(智能切分) | List(分词结果)
82 | ---
83 | ## 文件工具类 -> [FileUtil](https://github.com/TangerineSpecter/JavaBaseUtils/blob/master/src/common/util/FileUtil.java)
84 | 方法名 | 说明 | 参数 | 返回结果
85 | ------|------|-----|-----
86 | base64 | 将二进制压缩数据转成Base64编码 | byte\[](二进制压缩数据) | String(base64编码)
87 | base64 | 读取文件并压缩数据然后转Base64编码 | String(文件的绝对路径地址) | String(转码结果)
88 | decode | 把压缩过的base64串解码解压写入磁盘中 | String(压缩过的base64串),String(文件名),String(路径地址) | void(无)
89 | createFile | 创建文件 | String(生成路径),String(文件名),List(文本内容),FileTypeEnum(文件类型) | void(无)
90 | createFile | 创建文件 | String(生成路径),List(文本内容),FileTypeEnum(文件类型) | void(无)
91 | createFile | 创建文件 | List(文本内容),FileTypeEnum(文件类型) | void(无)
92 | getAllFileName | 获取路径下的所有文件名 | String(需要遍历的文件夹路径),boolean(是否切割后缀) | List(文件名集合)
93 | deleteFile | 删除文件 | String(文件路径),String(文件名) | void(无)
94 | deleteFile | 删除文件 | String(文件路径) | void(无)
95 | getAllFilePath | 获取路径下的所有文件/文件夹 | String(需要遍历的文件夹路径),boolean(是否将子文件夹的路径也添加到list集合中) | List(文件路径集合)
96 | writeFile | 二进制文件写入文件 | byte\[](二进制数据),String(文件名),String(路径地址) | void(无)
97 | deleteFileSuffix | 目录路径 | String(目录路径),FileTypeEnum(文件后缀) | void(无)
98 | deleteDirFile | 删除文件夹 | String(文件夹路径),boolean(是否删除文件夹内容) | void(无)
99 | moveFileDir | 转移文件目录 | String(文件名),String(旧路径),String(新路径),boolean(是否覆盖) | void(无)
100 | moveFuzzyFileDir | 转移文件目录(包含名字) | String(文件名),String(旧路径),String(新路径),boolean(是否覆盖) | void(无)
101 | createDir | 创建文件夹 | String(文件夹路径) | void(无)
102 | loadingFile | 读取文件内容 | String(文件路径) | String(文件内容)
103 | downloadFile2SavePath | 根据Url下载文件到指定目录 | List(下载地址集合),String(文件存放目录) | void(无)
104 | downloadFile2SavePath | 根据Url下载文件到指定目录 | String(下载地址),String(文件存放目录) | String(无)
105 | ---
106 | ## 路径处理工具类 -> [DirUtils](https://github.com/TangerineSpecter/JavaBaseUtils/blob/master/src/common/util/DirUtils.java)
107 | 方法名 | 说明 | 参数 | 返回结果
108 | ------|------|-----|-----
109 | getImgDir | 获取系统图片的存放路径 | String(UUID) | String(图片路径)
110 | getAudioDir | 获取系统音频的存放路径 | String(UUID) | String(音频路径)
111 | getVideoDir | 获取系统视频的存放路径 | String(UUID) | String(视频路径)
112 | ---
113 | ## 时间处理工具类 -> [TimeUtils](https://github.com/TangerineSpecter/JavaBaseUtils/blob/master/src/common/util/TimeUtils.java)
114 | 方法名 | 说明 | 参数 | 返回结果
115 | ------|------|-----|-----
116 | getCurrentYear | 获取当前年份 | 无 | String(年份)
117 | timeDifForYear | 时间差计算(年-月-日) | Long(开始时间戳),Long(结束时间戳) | String(返回时间格式:yy-MM-dd)
118 | timeFormatToDay | 将时间格式精确到天 | Date(时间) | String(转换结果)
119 | getCurrentTimes | 获取当前时间戳 | 无 | Long(时间戳)
120 | getDateMillion | 将指定格式转换成毫秒 | String(时间字符串),String(时间格式) | Long(时间戳)
121 | getDayBeginTimestamp | 获取当天开始时间戳 | 无 | Long(时间戳)
122 | getDayEndTimestamp | 获取当天结束时间戳 | 无 | Long(时间戳)
123 | getDisparityDay | 获取距离某个日期的天数 | String(时间字符串) | Integer(天数)
124 | getFinalDay | 获取某年某月最后一题 | int(年份),int(月份) | Integer(天数)
125 | getFinalDay | 获取某年某月最后一天 | Date(时间) | Date(时间)
126 | getStartDay | 获取某年某月第一天 | Date(时间) | Date(时间)
127 | getTimestramp | 获取特定时间时间戳 | int(年份),int(月份),int(日期),int(小时),int(分钟),int(秒) | Long(时间戳)
128 | getYesterdayBeginTimestamp | 获取昨天开始时间戳 | 无 | Long(时间戳)
129 | judgeLeapYear | 判断某一年是否闰年 | int(年份) | Boolean(判断结果)
130 | timeDifForDay | 时间差计算(时:分:秒) | Long(开始时间戳),Long(结束时间戳) | String(返回时间格式:HH:mm:ss)
131 | timeFormat | 将时间转换成指定格式 | Date(时间),String(时间格式) | String(转换结果)
132 | timeFormat | 将时间转换成指定格式 | Date(时间) | String(转换结果)
133 | getDate | 将指定的日期字符串转化为日期对象 | String(日期字符串),String(日期格式) | Date(转换结果)
134 | getSimpleFormat | 获取指定格式当前时间 | String(时间格式) | String(时间字符串)
135 | getWeekdays | 获取某天的星期 | String(时间字符串) | String(星期)
136 | ---
137 | ## 图片处理工具类 -> [ImageUtils](https://github.com/TangerineSpecter/JavaBaseUtils/blob/master/src/common/util/ImageUtils.java)
138 | 方法名 | 说明 | 参数 | 返回结果
139 | ------|------|-----|-----
140 | base64 | 读取文件压缩后转Base64编码 | String(图片的绝对路径地址) | String(Base64编码)
141 | downloadPicture | 将Url图片下载到本地 | List(url列表) | void(无)
142 | downloadPicture | 将Url图片下载到本地 | String(url地址),String(保存路径) | void(无)
143 | addWaterMark | 给图片加水印 | String(需要处理的图片路径),String(图片保存路径),int(水印x坐标),int(水印y坐标),String(水印内容),Font(水印字体),Color(水印字体颜色) | void(无)
144 | getWatermarkLength | 获取水印文字总长度 | String(水印文字),Graphics2D(Graphics2D类) | int(水印文字总长度)
145 | getWebImage | 获取网页所有图片并下载 | String(网页地址),String(网页编码),String(存放路径) | void(无)
146 | getHtmlResourceByUrl | 获取网页源代码 | String(网页地址),String(编码集) | String(源代码)
147 | getPicData | 获取图片的二进制数据 | String(图片的绝对路径地址) | byte[](二进制数据)
148 | ---
149 | ## 随机工具类 -> [RandomUtils](https://github.com/TangerineSpecter/JavaBaseUtils/blob/master/src/common/util/RandomUtils.java)
150 | 方法名 | 说明 | 参数 | 返回结果
151 | ------|------|-----|-----
152 | getEmail | 随机生成Email | int(最小长度),int(最大长度) | String(Email)
153 | getDate | 随机生成时间 | 无 | String(时间)
154 | getNum | 随机数 | int(起始数),int(结束数) | int(随机数字)
155 | getTel | 随机生成电话号码 | 无 | String(电话号码)
156 | getChineseName | 随机生成中文名字 | 无 | String(中文名)
157 | getProvince | 随机生成省份 | 无 | String(省份)
158 | createRandomName | 创建随机字符名字 | long(名字长度) | String(随机结果)
159 | ---
160 | ## 正则表达式工具类 -> [RegExUtils](https://github.com/TangerineSpecter/JavaBaseUtils/blob/master/src/common/util/RegExUtils.java)
161 | 方法名 | 说明 | 参数 | 返回结果
162 | ------|------|-----|-----
163 | checkEmail | 校验邮箱合法化 | String(邮箱地址) | boolean(校验结果)
164 | check2Point | 校验数字为小数后两位以内 | String(校验数字) | boolean(校验结果)
165 | checkPassword | 校验密码以字母开头 | String(密码) | boolean(校验结果)
166 | removeSpecialCharacter | 移除特殊字符 | String(字符串内容) | String(处理结果)
167 | filterHtml | 去除富文本中html相关字符 | String(富文本内容) | String(处理结果)
168 | ---
169 | ## 二维码生成工具类 -> [QrCodeUtils](https://github.com/TangerineSpecter/JavaBaseUtils/blob/master/src/common/util/QrCodeUtils.java)
170 | 方法名 | 说明 | 参数 | 返回结果
171 | ------|------|-----|-----
172 | createQrCode | 生成不带logo的默认参数二维码 | String(数据),int(宽度),int(高度) | BufferedImage(二维码图片)
173 | createQrCode | 生成不带logo的二维码 | String(数据),String(编码类型),Map(二维码属性),int(宽度),int(高度) | BufferedImage(二维码图片)
174 | createQrCodeWithLogo | 生成带logo的二维码 | String(数据),String(编码类型),Map(二维码属性),int(宽度),int(高度),File(logo文件路径) | BufferedImage(二维码图片)
175 | createQrCodeWithLogo | 生成带logo的默认参数二维码 | String(数据),int(宽度),int(高度),File(logo文件路径) | BufferedImage(二维码图片)
176 | ---
177 | ## 压缩和解压工具类 -> [ZipUtils](https://github.com/TangerineSpecter/JavaBaseUtils/blob/master/src/common/util/ZipUtils.java)
178 | 方法名 | 说明 | 参数 | 返回结果
179 | ------|------|-----|-----
180 | unZip | 解压数据 | byte\[](二进制数据) | byte[](解压结果)
181 | compress | 压缩文件 | String(源文件路径),String(压缩包名字) | void(无)
182 | gZip | 压缩数据 | byte\[](二进制数据) | byte[](压缩结果)
183 | ---
184 | ## Http工具类 -> [HttpUtils](https://github.com/TangerineSpecter/JavaBaseUtils/blob/master/src/common/util/HttpUtils.java)
185 | 方法名 | 说明 | 参数 | 返回结果
186 | ------|------|-----|-----
187 | ---
188 |
--------------------------------------------------------------------------------
/mvnw:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # ----------------------------------------------------------------------------
3 | # Licensed to the Apache Software Foundation (ASF) under one
4 | # or more contributor license agreements. See the NOTICE file
5 | # distributed with this work for additional information
6 | # regarding copyright ownership. The ASF licenses this file
7 | # to you under the Apache License, Version 2.0 (the
8 | # "License"); you may not use this file except in compliance
9 | # with the License. You may obtain a copy of the License at
10 | #
11 | # https://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing,
14 | # software distributed under the License is distributed on an
15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | # KIND, either express or implied. See the License for the
17 | # specific language governing permissions and limitations
18 | # under the License.
19 | # ----------------------------------------------------------------------------
20 |
21 | # ----------------------------------------------------------------------------
22 | # Maven2 Start Up Batch script
23 | #
24 | # Required ENV vars:
25 | # ------------------
26 | # JAVA_HOME - location of a JDK home dir
27 | #
28 | # Optional ENV vars
29 | # -----------------
30 | # M2_HOME - location of maven2's installed home dir
31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven
32 | # e.g. to debug Maven itself, use
33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files
35 | # ----------------------------------------------------------------------------
36 |
37 | if [ -z "$MAVEN_SKIP_RC" ] ; then
38 |
39 | if [ -f /etc/mavenrc ] ; then
40 | . /etc/mavenrc
41 | fi
42 |
43 | if [ -f "$HOME/.mavenrc" ] ; then
44 | . "$HOME/.mavenrc"
45 | fi
46 |
47 | fi
48 |
49 | # OS specific support. $var _must_ be set to either true or false.
50 | cygwin=false;
51 | darwin=false;
52 | mingw=false
53 | case "`uname`" in
54 | CYGWIN*) cygwin=true ;;
55 | MINGW*) mingw=true;;
56 | Darwin*) darwin=true
57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html
59 | if [ -z "$JAVA_HOME" ]; then
60 | if [ -x "/usr/libexec/java_home" ]; then
61 | export JAVA_HOME="`/usr/libexec/java_home`"
62 | else
63 | export JAVA_HOME="/Library/Java/Home"
64 | fi
65 | fi
66 | ;;
67 | esac
68 |
69 | if [ -z "$JAVA_HOME" ] ; then
70 | if [ -r /etc/gentoo-release ] ; then
71 | JAVA_HOME=`java-config --jre-home`
72 | fi
73 | fi
74 |
75 | if [ -z "$M2_HOME" ] ; then
76 | ## resolve links - $0 may be a link to maven's home
77 | PRG="$0"
78 |
79 | # need this for relative symlinks
80 | while [ -h "$PRG" ] ; do
81 | ls=`ls -ld "$PRG"`
82 | link=`expr "$ls" : '.*-> \(.*\)$'`
83 | if expr "$link" : '/.*' > /dev/null; then
84 | PRG="$link"
85 | else
86 | PRG="`dirname "$PRG"`/$link"
87 | fi
88 | done
89 |
90 | saveddir=`pwd`
91 |
92 | M2_HOME=`dirname "$PRG"`/..
93 |
94 | # make it fully qualified
95 | M2_HOME=`cd "$M2_HOME" && pwd`
96 |
97 | cd "$saveddir"
98 | # echo Using m2 at $M2_HOME
99 | fi
100 |
101 | # For Cygwin, ensure paths are in UNIX format before anything is touched
102 | if $cygwin ; then
103 | [ -n "$M2_HOME" ] &&
104 | M2_HOME=`cygpath --unix "$M2_HOME"`
105 | [ -n "$JAVA_HOME" ] &&
106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
107 | [ -n "$CLASSPATH" ] &&
108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
109 | fi
110 |
111 | # For Mingw, ensure paths are in UNIX format before anything is touched
112 | if $mingw ; then
113 | [ -n "$M2_HOME" ] &&
114 | M2_HOME="`(cd "$M2_HOME"; pwd)`"
115 | [ -n "$JAVA_HOME" ] &&
116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
117 | # TODO classpath?
118 | fi
119 |
120 | if [ -z "$JAVA_HOME" ]; then
121 | javaExecutable="`which javac`"
122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
123 | # readlink(1) is not available as standard on Solaris 10.
124 | readLink=`which readlink`
125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
126 | if $darwin ; then
127 | javaHome="`dirname \"$javaExecutable\"`"
128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
129 | else
130 | javaExecutable="`readlink -f \"$javaExecutable\"`"
131 | fi
132 | javaHome="`dirname \"$javaExecutable\"`"
133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'`
134 | JAVA_HOME="$javaHome"
135 | export JAVA_HOME
136 | fi
137 | fi
138 | fi
139 |
140 | if [ -z "$JAVACMD" ] ; then
141 | if [ -n "$JAVA_HOME" ] ; then
142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
143 | # IBM's JDK on AIX uses strange locations for the executables
144 | JAVACMD="$JAVA_HOME/jre/sh/java"
145 | else
146 | JAVACMD="$JAVA_HOME/bin/java"
147 | fi
148 | else
149 | JAVACMD="`which java`"
150 | fi
151 | fi
152 |
153 | if [ ! -x "$JAVACMD" ] ; then
154 | echo "Error: JAVA_HOME is not defined correctly." >&2
155 | echo " We cannot execute $JAVACMD" >&2
156 | exit 1
157 | fi
158 |
159 | if [ -z "$JAVA_HOME" ] ; then
160 | echo "Warning: JAVA_HOME environment variable is not set."
161 | fi
162 |
163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
164 |
165 | # traverses directory structure from process work directory to filesystem root
166 | # first directory with .mvn subdirectory is considered project base directory
167 | find_maven_basedir() {
168 |
169 | if [ -z "$1" ]
170 | then
171 | echo "Path not specified to find_maven_basedir"
172 | return 1
173 | fi
174 |
175 | basedir="$1"
176 | wdir="$1"
177 | while [ "$wdir" != '/' ] ; do
178 | if [ -d "$wdir"/.mvn ] ; then
179 | basedir=$wdir
180 | break
181 | fi
182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc)
183 | if [ -d "${wdir}" ]; then
184 | wdir=`cd "$wdir/.."; pwd`
185 | fi
186 | # end of workaround
187 | done
188 | echo "${basedir}"
189 | }
190 |
191 | # concatenates all lines of a file
192 | concat_lines() {
193 | if [ -f "$1" ]; then
194 | echo "$(tr -s '\n' ' ' < "$1")"
195 | fi
196 | }
197 |
198 | BASE_DIR=`find_maven_basedir "$(pwd)"`
199 | if [ -z "$BASE_DIR" ]; then
200 | exit 1;
201 | fi
202 |
203 | ##########################################################################################
204 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
205 | # This allows using the maven wrapper in projects that prohibit checking in binary data.
206 | ##########################################################################################
207 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then
208 | if [ "$MVNW_VERBOSE" = true ]; then
209 | echo "Found .mvn/wrapper/maven-wrapper.jar"
210 | fi
211 | else
212 | if [ "$MVNW_VERBOSE" = true ]; then
213 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
214 | fi
215 | jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"
216 | while IFS="=" read key value; do
217 | case "$key" in (wrapperUrl) jarUrl="$value"; break ;;
218 | esac
219 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties"
220 | if [ "$MVNW_VERBOSE" = true ]; then
221 | echo "Downloading from: $jarUrl"
222 | fi
223 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
224 |
225 | if command -v wget > /dev/null; then
226 | if [ "$MVNW_VERBOSE" = true ]; then
227 | echo "Found wget ... using wget"
228 | fi
229 | wget "$jarUrl" -O "$wrapperJarPath"
230 | elif command -v curl > /dev/null; then
231 | if [ "$MVNW_VERBOSE" = true ]; then
232 | echo "Found curl ... using curl"
233 | fi
234 | curl -o "$wrapperJarPath" "$jarUrl"
235 | else
236 | if [ "$MVNW_VERBOSE" = true ]; then
237 | echo "Falling back to using Java to download"
238 | fi
239 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
240 | if [ -e "$javaClass" ]; then
241 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
242 | if [ "$MVNW_VERBOSE" = true ]; then
243 | echo " - Compiling MavenWrapperDownloader.java ..."
244 | fi
245 | # Compiling the Java class
246 | ("$JAVA_HOME/bin/javac" "$javaClass")
247 | fi
248 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
249 | # Running the downloader
250 | if [ "$MVNW_VERBOSE" = true ]; then
251 | echo " - Running MavenWrapperDownloader.java ..."
252 | fi
253 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR")
254 | fi
255 | fi
256 | fi
257 | fi
258 | ##########################################################################################
259 | # End of extension
260 | ##########################################################################################
261 |
262 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
263 | if [ "$MVNW_VERBOSE" = true ]; then
264 | echo $MAVEN_PROJECTBASEDIR
265 | fi
266 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
267 |
268 | # For Cygwin, switch paths to Windows format before running java
269 | if $cygwin; then
270 | [ -n "$M2_HOME" ] &&
271 | M2_HOME=`cygpath --path --windows "$M2_HOME"`
272 | [ -n "$JAVA_HOME" ] &&
273 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
274 | [ -n "$CLASSPATH" ] &&
275 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
276 | [ -n "$MAVEN_PROJECTBASEDIR" ] &&
277 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
278 | fi
279 |
280 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
281 |
282 | exec "$JAVACMD" \
283 | $MAVEN_OPTS \
284 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
285 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
286 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
287 |
--------------------------------------------------------------------------------
/mvnw.cmd:
--------------------------------------------------------------------------------
1 | @REM ----------------------------------------------------------------------------
2 | @REM Licensed to the Apache Software Foundation (ASF) under one
3 | @REM or more contributor license agreements. See the NOTICE file
4 | @REM distributed with this work for additional information
5 | @REM regarding copyright ownership. The ASF licenses this file
6 | @REM to you under the Apache License, Version 2.0 (the
7 | @REM "License"); you may not use this file except in compliance
8 | @REM with the License. You may obtain a copy of the License at
9 | @REM
10 | @REM https://www.apache.org/licenses/LICENSE-2.0
11 | @REM
12 | @REM Unless required by applicable law or agreed to in writing,
13 | @REM software distributed under the License is distributed on an
14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | @REM KIND, either express or implied. See the License for the
16 | @REM specific language governing permissions and limitations
17 | @REM under the License.
18 | @REM ----------------------------------------------------------------------------
19 |
20 | @REM ----------------------------------------------------------------------------
21 | @REM Maven2 Start Up Batch script
22 | @REM
23 | @REM Required ENV vars:
24 | @REM JAVA_HOME - location of a JDK home dir
25 | @REM
26 | @REM Optional ENV vars
27 | @REM M2_HOME - location of maven2's installed home dir
28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
31 | @REM e.g. to debug Maven itself, use
32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
34 | @REM ----------------------------------------------------------------------------
35 |
36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
37 | @echo off
38 | @REM set title of command window
39 | title %0
40 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
42 |
43 | @REM set %HOME% to equivalent of $HOME
44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
45 |
46 | @REM Execute a user defined script before this one
47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending
49 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
50 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
51 | :skipRcPre
52 |
53 | @setlocal
54 |
55 | set ERROR_CODE=0
56 |
57 | @REM To isolate internal variables from possible post scripts, we use another setlocal
58 | @setlocal
59 |
60 | @REM ==== START VALIDATION ====
61 | if not "%JAVA_HOME%" == "" goto OkJHome
62 |
63 | echo.
64 | echo Error: JAVA_HOME not found in your environment. >&2
65 | echo Please set the JAVA_HOME variable in your environment to match the >&2
66 | echo location of your Java installation. >&2
67 | echo.
68 | goto error
69 |
70 | :OkJHome
71 | if exist "%JAVA_HOME%\bin\java.exe" goto init
72 |
73 | echo.
74 | echo Error: JAVA_HOME is set to an invalid directory. >&2
75 | echo JAVA_HOME = "%JAVA_HOME%" >&2
76 | echo Please set the JAVA_HOME variable in your environment to match the >&2
77 | echo location of your Java installation. >&2
78 | echo.
79 | goto error
80 |
81 | @REM ==== END VALIDATION ====
82 |
83 | :init
84 |
85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
86 | @REM Fallback to current working directory if not found.
87 |
88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
90 |
91 | set EXEC_DIR=%CD%
92 | set WDIR=%EXEC_DIR%
93 | :findBaseDir
94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound
95 | cd ..
96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound
97 | set WDIR=%CD%
98 | goto findBaseDir
99 |
100 | :baseDirFound
101 | set MAVEN_PROJECTBASEDIR=%WDIR%
102 | cd "%EXEC_DIR%"
103 | goto endDetectBaseDir
104 |
105 | :baseDirNotFound
106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
107 | cd "%EXEC_DIR%"
108 |
109 | :endDetectBaseDir
110 |
111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
112 |
113 | @setlocal EnableExtensions EnableDelayedExpansion
114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
116 |
117 | :endReadAdditionalConfig
118 |
119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
122 |
123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"
124 | FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO (
125 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
126 | )
127 |
128 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
129 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data.
130 | if exist %WRAPPER_JAR% (
131 | echo Found %WRAPPER_JAR%
132 | ) else (
133 | echo Couldn't find %WRAPPER_JAR%, downloading it ...
134 | echo Downloading from: %DOWNLOAD_URL%
135 | powershell -Command "(New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"
136 | echo Finished downloading %WRAPPER_JAR%
137 | )
138 | @REM End of extension
139 |
140 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
141 | if ERRORLEVEL 1 goto error
142 | goto end
143 |
144 | :error
145 | set ERROR_CODE=1
146 |
147 | :end
148 | @endlocal & set ERROR_CODE=%ERROR_CODE%
149 |
150 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
151 | @REM check for post script, once with legacy .bat ending and once with .cmd ending
152 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
153 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
154 | :skipRcPost
155 |
156 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
157 | if "%MAVEN_BATCH_PAUSE%" == "on" pause
158 |
159 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
160 |
161 | exit /B %ERROR_CODE%
162 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.5.3
9 |
10 |
11 | com.tangerineSpecter
12 | javaBaseUtils
13 | 2.0.0
14 | JavaBaseUtils
15 | Java Tools
16 |
17 |
18 | 1.8
19 |
20 |
21 |
22 |
23 | org.springframework.boot
24 | spring-boot-starter
25 |
26 |
27 |
28 | org.springframework.boot
29 | spring-boot-starter-test
30 | test
31 |
32 |
33 | org.junit.vintage
34 | junit-vintage-engine
35 |
36 |
37 |
38 |
39 |
40 |
41 | org.projectlombok
42 | lombok
43 | 1.18.8
44 | provided
45 |
46 |
47 |
48 | org.aspectj
49 | aspectjweaver
50 | 1.9.4
51 |
52 |
53 |
54 | org.springframework.boot
55 | spring-boot-starter-web
56 |
57 |
58 |
59 | com.google.guava
60 | guava
61 | 30.0-jre
62 |
63 |
64 |
65 | com.alibaba
66 | easyexcel
67 | 2.2.10
68 |
69 |
70 |
71 | org.apache.poi
72 | poi
73 | 3.17
74 |
75 |
76 | org.apache.poi
77 | poi-ooxml
78 | 3.17
79 |
80 |
81 | org.apache.poi
82 | poi-ooxml-schemas
83 | 3.17
84 |
85 |
86 |
87 |
88 | org.apache.lucene
89 | lucene-core
90 | 8.2.0
91 |
92 |
93 |
94 | org.apache.lucene
95 | lucene-analyzers-smartcn
96 | 8.2.0
97 |
98 |
99 | org.apache.lucene
100 | lucene-analyzers-common
101 | 8.2.0
102 |
103 |
104 | org.apache.lucene
105 | lucene-analyzers
106 | 3.6.2
107 |
108 |
109 | org.apache.lucene
110 | lucene-queryparser
111 | 8.2.0
112 |
113 |
114 | com.janeluo
115 | ikanalyzer
116 | 2012_u6
117 |
118 |
119 |
120 | org.jsoup
121 | jsoup
122 | 1.11.3
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 | com.google.zxing
133 | core
134 | 3.3.3
135 |
136 |
137 | com.google.zxing
138 | javase
139 | 3.4.0
140 |
141 |
142 |
143 | com.alibaba
144 | fastjson
145 | 1.2.58
146 |
147 |
148 |
149 | redis.clients
150 | jedis
151 | 3.1.0
152 |
153 |
154 |
155 | commons-io
156 | commons-io
157 | 2.7
158 |
159 |
160 | commons-codec
161 | commons-codec
162 | 1.15
163 |
164 |
165 | org.apache.commons
166 | commons-lang3
167 | 3.12.0
168 |
169 |
170 | commons-collections
171 | commons-collections
172 | 3.2.2
173 |
174 |
175 |
176 | org.apache.httpcomponents
177 | httpclient
178 | 4.5.13
179 |
180 |
181 | org.apache.httpcomponents
182 | httpcore
183 | 4.4.11
184 |
185 |
186 |
187 | com.itextpdf
188 | itext7-core
189 | 7.1.16
190 |
191 |
192 |
193 | io.springfox
194 | springfox-swagger2
195 | 2.9.2
196 |
197 |
198 |
199 | io.springfox
200 | springfox-swagger-ui
201 | 2.9.2
202 |
203 |
204 |
205 | com.github.xiaoymin
206 | knife4j-spring-boot-starter
207 | 2.0.9
208 |
209 |
210 |
211 | cn.hutool
212 | hutool-all
213 | 5.7.7
214 |
215 |
216 |
217 |
218 |
219 |
220 | org.springframework.boot
221 | spring-boot-maven-plugin
222 |
223 |
224 |
225 |
226 |
227 |
228 | spring-milestones
229 | Spring Milestones
230 | https://repo.spring.io/milestone
231 |
232 |
233 |
234 |
235 | spring-milestones
236 | Spring Milestones
237 | https://repo.spring.io/milestone
238 |
239 |
240 |
241 |
242 |
--------------------------------------------------------------------------------
/src/log4j.properties:
--------------------------------------------------------------------------------
1 | ### 设置###
2 | log4j.rootLogger = INFO,stdout,E
3 |
4 | ### 输出信息到控制抬 ###
5 | log4j.appender.stdout = org.apache.log4j.ConsoleAppender
6 | log4j.appender.stdout.Target = System.out
7 | log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
8 | log4j.appender.stdout.layout.ConversionPattern = [%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} method:%l%n%m%n
9 |
10 | ### 输出DEBUG 级别以上的日志到=E://logs/error.log ###
11 | log4j.appender.D = org.apache.log4j.DailyRollingFileAppender
12 | log4j.appender.D.File = E://logs/log.log
13 | log4j.appender.D.Append = true
14 | log4j.appender.D.Threshold = DEBUG
15 | log4j.appender.D.layout = org.apache.log4j.PatternLayout
16 | log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
17 |
18 | ### 输出ERROR 级别以上的日志到=E://logs/error.log ###
19 | log4j.appender.E = org.apache.log4j.DailyRollingFileAppender
20 | log4j.appender.E.File =E://logs/error.log
21 | log4j.appender.E.Append = true
22 | log4j.appender.E.Threshold = ERROR
23 | log4j.appender.E.layout = org.apache.log4j.PatternLayout
24 | log4j.appender.E.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
--------------------------------------------------------------------------------
/src/main/java/com/tangerineSpecter/javaBaseUtils/JavaBaseUtilsApplication.java:
--------------------------------------------------------------------------------
1 | package com.tangerinespecter.javabaseutils;
2 |
3 | import com.tangerinespecter.javabaseutils.common.servlet.AppRunWrapper;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | /**
7 | * 启动入口
8 | *
9 | * @author TangerineSpecter
10 | */
11 | @SpringBootApplication
12 | public class JavaBaseUtilsApplication {
13 |
14 | public static void main(String[] args) throws Exception {
15 | AppRunWrapper.run(JavaBaseUtilsApplication.class, args);
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/com/tangerineSpecter/javaBaseUtils/common/DocumentInfo.java:
--------------------------------------------------------------------------------
1 | package com.tangerinespecter.javabaseutils.common;
2 |
3 | import com.tangerinespecter.javabaseutils.common.annotation.ClassInfo;
4 | import com.tangerinespecter.javabaseutils.common.annotation.MethodInfo;
5 | import com.tangerinespecter.javabaseutils.common.util.Constant;
6 | import com.tangerinespecter.javabaseutils.common.util.FileUtil;
7 | import com.tangerinespecter.javabaseutils.common.util.enums.FileTypeEnum;
8 | import lombok.extern.slf4j.Slf4j;
9 |
10 | import java.lang.reflect.Method;
11 | import java.text.SimpleDateFormat;
12 | import java.util.*;
13 |
14 | /**
15 | * 文档信息生成
16 | *
17 | * @author TangerineSpecter
18 | */
19 | @Slf4j
20 | public class DocumentInfo {
21 |
22 | /**
23 | * 不需要生成文档的集合
24 | */
25 | private static final Set IGNORE_SET = new HashSet<>();
26 |
27 | /**
28 | * 文件名集合
29 | */
30 | private static List allFileName = new ArrayList<>();
31 |
32 | /**
33 | * 创建所有类的文档信息
34 | *
35 | * @throws Exception
36 | */
37 | public static void createDocInfo() throws Exception {
38 | List textInfo = new ArrayList<>();
39 | allFileName = FileUtil.getAllFileName(Constant.UTIL_ABSOLUTE_PATH, true);
40 | getDocHead(textInfo);
41 | for (String fileName : allFileName) {
42 | if (!IGNORE_SET.contains(fileName)) {
43 | createClassInfo(fileName, textInfo);
44 | }
45 | }
46 | FileUtil.deleteFile(System.getProperty("user.dir"), "README.md");
47 | FileUtil.createFile(System.getProperty("user.dir"), "README", textInfo, FileTypeEnum.MARKDOWN_FILE);
48 | }
49 |
50 | /**
51 | * 创建类文档信息
52 | *
53 | * @param className 类名
54 | * @throws Exception
55 | */
56 | public static void createClassInfo(String className, List textInfo) throws Exception {
57 | boolean flag = false;
58 | List allFilePath = FileUtil.getAllFilePath(Constant.UTIL_ABSOLUTE_PATH, false);
59 | for (String path : allFilePath) {
60 | if (path.contains(className)) {
61 | flag = true;
62 | break;
63 | }
64 | }
65 | if (flag) {
66 | Class> clazz = Class.forName(Constant.UTIL_QUALIFIED_HEAD + className);
67 | ClassInfo clazzAnno = clazz.getAnnotation(ClassInfo.class);
68 | if (clazzAnno == null) {
69 | return;
70 | }
71 | textInfo.add(String.format("## %s -> [%s](%s)", className, clazzAnno.Name(), className,
72 | Constant.GIT_HUB_BLOB_URL + className + ".java"));
73 | Method[] methods = clazz.getMethods();
74 | getDocUtilHead(textInfo);
75 | for (Method method : methods) {
76 | MethodInfo annotations = method.getAnnotation(MethodInfo.class);
77 | if (annotations != null) {
78 | textInfo.add(String.format("%s | %s | %s | %s(%s)", method.getName(), annotations.Name(),
79 | getParamInfo(method, annotations.paramInfo()), method.getReturnType().getSimpleName(),
80 | annotations.returnInfo()));
81 | }
82 | }
83 | textInfo.add("---");
84 | } else {
85 | log.info(String.format("【需要生成文档的类不存在】:{}", className));
86 | }
87 | }
88 |
89 | /**
90 | * 获取文档目录
91 | *
92 | * @throws Exception
93 | */
94 | private static void getDocHead(List textInfo) throws Exception {
95 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
96 | Calendar cal = Calendar.getInstance();
97 | textInfo.add("# JavaBaseUtils\r\n");
98 | textInfo.add("## 简介");
99 | textInfo.add(" 主要收集一些平时常用的Java开发工具类,内容在不断更新补充中...");
100 | textInfo.add("
\r\n");
101 | textInfo.add("### Java基本工具包:");
102 | textInfo.add("- 工具包地址:https://github.com/TangerineSpecter/JavaBaseUtils\r\n");
103 | textInfo.add("### 版本号:");
104 | textInfo.add("- 项目版本:" + Constant.VERSION + "\r\n");
105 | textInfo.add("- JDK版本:1.8\r\n");
106 | textInfo.add("### 最后更新时间:");
107 | textInfo.add("> " + sdf.format(cal.getTime()) + "\r\n");
108 | textInfo.add("## 目录 \r\n");
109 | textInfo.add("- [开始](#Getting_Menu)");
110 | textInfo.add("- [API](#Geting_Api)");
111 | for (String fileName : allFileName) {
112 | if (!IGNORE_SET.contains(fileName)) {
113 | Class> clazz = Class.forName(Constant.UTIL_QUALIFIED_HEAD + fileName);
114 | ClassInfo annotation = clazz.getAnnotation(ClassInfo.class);
115 | if (annotation == null) {
116 | continue;
117 | }
118 | textInfo.add(String.format(" - [%s](#Geting_%s)", annotation.Name(), fileName));
119 | }
120 | }
121 | textInfo.add("---");
122 | }
123 |
124 | /**
125 | * 获取文档类标题
126 | */
127 | private static void getDocUtilHead(List textInfo) {
128 | textInfo.add("方法名 | 说明 | 参数 | 返回结果\r\n------|------|-----|-----");
129 | }
130 |
131 | /**
132 | * 获取参数信息
133 | *
134 | * @return
135 | */
136 | private static String getParamInfo(Method method, String[] params) {
137 | StringBuilder paramInfo = new StringBuilder(Constant.NULL_KEY_STR);
138 | int index = Constant.Number.COMMON_NUMBER_ZERO;
139 | Class>[] paramTypes = method.getParameterTypes();
140 | if (params[index].equals(Constant.Chinese.NOTHING)) {
141 | return params[index];
142 | }
143 | for (Class> param : paramTypes) {
144 | try {
145 | paramInfo.append(param.getSimpleName()).append("(").append(params[index]).append("),");
146 | index++;
147 | } catch (Exception e) {
148 | log.info(String.format("--------------------------------------------------------\r\n"
149 | + "【文档生成信息有误】\r\n Method : {} \r\n"
150 | + "--------------------------------------------------------", method.getName()));
151 | System.exit(0);
152 | }
153 | }
154 | return paramInfo.substring(0, paramInfo.length() - 1).replace("[]", "\\[]");
155 | }
156 |
157 | static {
158 | IGNORE_SET.add("Constant");
159 | IGNORE_SET.add("AudioUtils");
160 | IGNORE_SET.add("Base64Utils");
161 | IGNORE_SET.add("DecipheringBaseUtils");
162 | IGNORE_SET.add("DecipheringUtils");
163 | IGNORE_SET.add("LollipopUtils");
164 | IGNORE_SET.add("FileTypeEnum");
165 | IGNORE_SET.add("BaseUtils");
166 | IGNORE_SET.add("LoggerWordPool");
167 | }
168 | }
169 |
--------------------------------------------------------------------------------
/src/main/java/com/tangerineSpecter/javaBaseUtils/common/annotation/ClassInfo.java:
--------------------------------------------------------------------------------
1 | package com.tangerinespecter.javabaseutils.common.annotation;
2 |
3 | import java.lang.annotation.Documented;
4 | import java.lang.annotation.ElementType;
5 | import java.lang.annotation.Retention;
6 | import java.lang.annotation.RetentionPolicy;
7 | import java.lang.annotation.Target;
8 |
9 | import com.tangerinespecter.javabaseutils.common.util.Constant;
10 |
11 | /**
12 | * 类注解
13 | *
14 | * @author TangerineSpecter
15 | */
16 | @Documented
17 | @Target(ElementType.TYPE)
18 | @Retention(RetentionPolicy.RUNTIME)
19 | public @interface ClassInfo {
20 |
21 | String Name() default Constant.Chinese.TOOL;
22 |
23 | String Author() default Constant.Chinese.ANONYMOUS;
24 |
25 | String Time() default Constant.NULL_KEY_STR;
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/com/tangerineSpecter/javaBaseUtils/common/annotation/MethodInfo.java:
--------------------------------------------------------------------------------
1 | package com.tangerinespecter.javabaseutils.common.annotation;
2 |
3 | import com.tangerinespecter.javabaseutils.common.util.Constant;
4 |
5 | import java.lang.annotation.*;
6 |
7 | /**
8 | * 方法注解
9 | *
10 | * @author TangerineSpecter
11 | */
12 | @Documented
13 | @Target(ElementType.METHOD)
14 | @Retention(RetentionPolicy.RUNTIME)
15 | public @interface MethodInfo {
16 |
17 | /**
18 | * 方法名
19 | */
20 | String Name() default Constant.Chinese.NOTHING;
21 |
22 | /**
23 | * 参数信息
24 | */
25 | String[] paramInfo() default Constant.Chinese.NOTHING;
26 |
27 | /**
28 | * 返回信息
29 | */
30 | String returnInfo() default Constant.Chinese.NOTHING;
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/com/tangerineSpecter/javaBaseUtils/common/config/SwaggerConfig.java:
--------------------------------------------------------------------------------
1 | package com.tangerinespecter.javabaseutils.common.config;
2 |
3 | import com.google.common.base.Predicates;
4 | import lombok.extern.slf4j.Slf4j;
5 | import org.springframework.beans.factory.annotation.Value;
6 | import org.springframework.context.annotation.Bean;
7 | import org.springframework.context.annotation.Configuration;
8 | import springfox.documentation.builders.ApiInfoBuilder;
9 | import springfox.documentation.builders.PathSelectors;
10 | import springfox.documentation.builders.RequestHandlerSelectors;
11 | import springfox.documentation.service.ApiInfo;
12 | import springfox.documentation.service.Contact;
13 | import springfox.documentation.spi.DocumentationType;
14 | import springfox.documentation.spring.web.plugins.Docket;
15 | import springfox.documentation.swagger2.annotations.EnableSwagger2;
16 |
17 | /**
18 | * Swagger配置类
19 | */
20 | @Slf4j
21 | @EnableSwagger2
22 | @Configuration
23 | public class SwaggerConfig {
24 |
25 | @Value("${server.port}")
26 | private Integer port;
27 |
28 | @Bean
29 | public Docket customDocket() {
30 | return new Docket(DocumentationType.SWAGGER_2)
31 | .apiInfo(apiInfo())
32 | //选择那些路径和api会生成document
33 | .select()
34 | //对所有api进行监控
35 | .apis(RequestHandlerSelectors.any())
36 | //错误路径不监控
37 | .paths(Predicates.not(PathSelectors.regex("/error.*")))
38 | .paths(Predicates.not(PathSelectors.regex("/hello.*")))
39 | .build();
40 | }
41 |
42 | /**
43 | * 配置Api相关信息
44 | */
45 | private ApiInfo apiInfo() {
46 | Contact contact = new Contact("丢失的橘子", "https://github.com/TangerineSpecter", "993033472@qq.com");
47 | return new ApiInfoBuilder()
48 | .title("Java工具包文档")
49 | .description("Java工具包接口演示文档")
50 | .contact(contact)
51 | .version("2.0.4")
52 | .build();
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/com/tangerineSpecter/javaBaseUtils/common/exception/GlobalException.java:
--------------------------------------------------------------------------------
1 | package com.tangerinespecter.javabaseutils.common.exception;
2 |
3 | import lombok.Getter;
4 | import lombok.Setter;
5 |
6 | /**
7 | * 全局异常
8 | *
9 | * @author TangerineSpecter
10 | */
11 | @Getter
12 | @Setter
13 | public class GlobalException extends RuntimeException {
14 |
15 | private Integer code = 500;
16 | private String message;
17 |
18 | public GlobalException(String message) {
19 | super(message);
20 | this.message = message;
21 | }
22 |
23 | public GlobalException(Throwable cause) {
24 | super(cause);
25 | }
26 |
27 | public GlobalException(String message, Throwable cause) {
28 | super(message, cause);
29 | this.message = message;
30 | }
31 |
32 | public GlobalException(Integer code, String message) {
33 | this.code = code;
34 | this.message = message;
35 | }
36 |
37 | public GlobalException(Integer code) {
38 | this.code = code;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/com/tangerineSpecter/javaBaseUtils/common/filter/ManageLogAspect.java:
--------------------------------------------------------------------------------
1 | package com.tangerinespecter.javabaseutils.common.filter;
2 |
3 | import com.alibaba.fastjson.JSON;
4 | import lombok.extern.slf4j.Slf4j;
5 | import org.aspectj.lang.JoinPoint;
6 | import org.aspectj.lang.annotation.Aspect;
7 | import org.aspectj.lang.annotation.Before;
8 | import org.aspectj.lang.annotation.Pointcut;
9 | import org.springframework.stereotype.Component;
10 | import org.springframework.web.context.request.RequestContextHolder;
11 | import org.springframework.web.context.request.ServletRequestAttributes;
12 |
13 | import javax.servlet.http.HttpServletRequest;
14 | import java.util.concurrent.Executor;
15 | import java.util.concurrent.Executors;
16 |
17 | @Slf4j
18 | @Aspect
19 | @Component
20 | public class ManageLogAspect {
21 |
22 | private static final Executor executor = Executors.newFixedThreadPool(20, r -> {
23 | Thread t = new Thread(r);
24 | t.setName("log-aspect-" + t.getId());
25 | /*打开守护线程*/
26 | t.setDaemon(true);
27 | return t;
28 | });
29 |
30 |
31 | @Pointcut("execution(* com.tangerinespecter.javabaseutils.controller..*.*(..))")
32 | public void controllerAopPointCut() {
33 | }
34 |
35 |
36 | @Before("controllerAopPointCut()")
37 | public void controllerReturnBefore(JoinPoint joinPoint) {
38 | ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
39 | HttpServletRequest request = attributes.getRequest();
40 | String token = request.getHeader("token");
41 | executor.execute(() -> logAccess(token, joinPoint.getArgs(), request.getRequestURI()));
42 | }
43 |
44 |
45 | private void logAccess(String token, Object[] args, String url) {
46 | try {
47 | String userStr = "【TangerineSpecter】";
48 | log.info("接口日志记录, 请求url: {}, 用户信息: {}, 请求参数: {}, token:{}", url, userStr, JSON.toJSONString(args), token);
49 | } catch (Exception e) {
50 | log.warn("记录用户访问信息出错", e);
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/com/tangerineSpecter/javaBaseUtils/common/img/show_logo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TangerineSpecter/JavaBaseUtils/681ecd200def8b8a3b9aa5793d0959f785880db3/src/main/java/com/tangerineSpecter/javaBaseUtils/common/img/show_logo.gif
--------------------------------------------------------------------------------
/src/main/java/com/tangerineSpecter/javaBaseUtils/common/servlet/AppRunWrapper.java:
--------------------------------------------------------------------------------
1 | package com.tangerinespecter.javabaseutils.common.servlet;
2 |
3 | import com.tangerinespecter.javabaseutils.common.DocumentInfo;
4 | import lombok.extern.slf4j.Slf4j;
5 | import org.springframework.boot.SpringApplication;
6 | import org.springframework.context.ApplicationContext;
7 | import org.springframework.context.ConfigurableApplicationContext;
8 | import org.springframework.core.env.Environment;
9 |
10 | @Slf4j
11 | public class AppRunWrapper {
12 |
13 | public static ApplicationContext run(Class clazz, String[] args) throws Exception {
14 | System.setProperty("appName", clazz.getSimpleName());
15 | ConfigurableApplicationContext application = SpringApplication.run(clazz, args);
16 | Environment env = application.getEnvironment();
17 |
18 | DocumentInfo.createDocInfo();
19 | log.info("\n☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆\n\t" +
20 | "Application '{}' is running! Access URLs:\n\t" +
21 | "欢迎使用橘子工具包,工具文档访问地址: \t\thttp://localhost:{}{}/doc.html\n" +
22 | "☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆",
23 | env.getProperty("spring.application.name", ""),
24 | env.getProperty("server.port", ""),
25 | env.getProperty("server.servlet.context-path", ""));
26 | return application;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/com/tangerineSpecter/javaBaseUtils/common/servlet/InitProperties.java:
--------------------------------------------------------------------------------
1 | package com.tangerinespecter.javabaseutils.common.servlet;
2 |
3 | import java.io.IOException;
4 | import java.io.InputStream;
5 | import java.util.Properties;
6 |
7 | /**
8 | * 初始化
9 | *
10 | * @author TangerineSpecter
11 | */
12 | public class InitProperties {
13 |
14 | public static void init() {
15 | try {
16 | Properties properties = new Properties();
17 | // 使用ClassLoader加载properties配置文件生成对应的输入流
18 | InputStream in = InitProperties.class.getClassLoader().getResourceAsStream("common.properties");
19 | // 使用properties对象加载输入流
20 | properties.load(in);
21 | //获取key对应的value值
22 | String value = properties.getProperty("version");
23 | System.out.println(value);
24 | } catch (IOException e) {
25 | e.printStackTrace();
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/com/tangerineSpecter/javaBaseUtils/common/test/UtilTest.java:
--------------------------------------------------------------------------------
1 | package com.tangerinespecter.javabaseutils.common.test;
2 |
3 | import com.tangerinespecter.javabaseutils.common.DocumentInfo;
4 | import com.tangerinespecter.javabaseutils.common.util.DecipheringUtils;
5 |
6 | /**
7 | * 测试
8 | *
9 | * @author TangerineSpecter
10 | */
11 | public class UtilTest {
12 |
13 | public static void main(String[] args) throws Exception {
14 | DocumentInfo.createDocInfo();
15 | // String a = DecipheringUtils.setRailFenceResult("THERE IS A CIPHER", 7);
16 | // System.out.println(a);
17 | // String b = DecipheringUtils.getRailFenceResult("TAHCEIRPEHIESR", 7);
18 | // System.out.println(b);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/java/com/tangerineSpecter/javaBaseUtils/common/util/AudioUtils.java:
--------------------------------------------------------------------------------
1 | package com.tangerinespecter.javabaseutils.common.util;
2 |
3 | import com.tangerinespecter.javabaseutils.common.annotation.ClassInfo;
4 |
5 | /**
6 | * 音频处理工具类
7 | *
8 | * @author TangerineSpecter
9 | *
10 | */
11 | @ClassInfo(Name = "音频处理工具类")
12 | public class AudioUtils {
13 |
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/com/tangerineSpecter/javaBaseUtils/common/util/Base64Utils.java:
--------------------------------------------------------------------------------
1 | package com.tangerinespecter.javabaseutils.common.util;
2 |
3 | import com.tangerinespecter.javabaseutils.common.annotation.ClassInfo;
4 |
5 | /**
6 | * Base64工具类
7 | *
8 | * @author TangerineSpecter
9 | *
10 | */
11 | @ClassInfo(Name = "Base64工具类")
12 | public class Base64Utils {
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/com/tangerineSpecter/javaBaseUtils/common/util/BaseUtils.java:
--------------------------------------------------------------------------------
1 | package com.tangerinespecter.javabaseutils.common.util;
2 |
3 | /**
4 | * 基础工具类
5 | *
6 | * @author TangerineSpecter
7 | *
8 | */
9 | public class BaseUtils extends LoggerWordPool {
10 |
11 | /**
12 | * 日志信息
13 | */
14 | public static String loggerMessage(String info, Object param) {
15 | return String.format(info, param);
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/com/tangerineSpecter/javaBaseUtils/common/util/Constant.java:
--------------------------------------------------------------------------------
1 | package com.tangerinespecter.javabaseutils.common.util;
2 |
3 | import com.tangerinespecter.javabaseutils.common.annotation.ClassInfo;
4 |
5 | /**
6 | * 参数常量类
7 | *
8 | * @author TangerineSpecter
9 | */
10 | @ClassInfo(Name = "参数常量类")
11 | public class Constant {
12 |
13 | /**
14 | * 版本号
15 | */
16 | public static final String VERSION = "2.0.4";
17 |
18 | /**
19 | * 文件默认存放地址
20 | */
21 | public static final String FILE_SAVE_PATH = "F:\\testFile\\";
22 | /**
23 | * 压缩文件存放地址
24 | */
25 | public static final String ZIP_SAVE_PATH = "F:\\testFile\\zip\\";
26 |
27 | /**
28 | * 空定义
29 | */
30 | public static final String NULL_KEY_STR = "";
31 |
32 | /**
33 | * 工具类全限定名头
34 | */
35 | public static final String UTIL_QUALIFIED_HEAD = "com.tangerinespecter.javabaseutils.common.util.";
36 |
37 | /**
38 | * 工具类绝对路径
39 | */
40 | public static final String UTIL_ABSOLUTE_PATH = System.getProperty("user.dir") + "/src/main/java/com/tangerinespecter/javabaseutils/common/util";
41 |
42 | /**
43 | * 日期常量
44 | */
45 | public static class Date {
46 | /**
47 | * 一月
48 | */
49 | public static final int MONTH_JANUARY = 1;
50 | /**
51 | * 二月
52 | */
53 | public static final int MONTH_FEBRUARY = 2;
54 | /**
55 | * 三月
56 | */
57 | public static final int MONTH_MARCH = 3;
58 | /**
59 | * 四月
60 | */
61 | public static final int MONTH_APRIL = 4;
62 | /**
63 | * 五月
64 | */
65 | public static final int MONTH_MAY = 5;
66 | /**
67 | * 六月
68 | */
69 | public static final int MONTH_JUNE = 6;
70 | /**
71 | * 七月
72 | */
73 | public static final int MONTH_JULY = 7;
74 | /**
75 | * 八月
76 | */
77 | public static final int MONTH_AUGUST = 8;
78 | /**
79 | * 九月
80 | */
81 | public static final int MONTH_SEPTEMBER = 9;
82 | /**
83 | * 十月
84 | */
85 | public static final int MONTH_OCTOBER = 10;
86 | /**
87 | * 十一月
88 | */
89 | public static final int MONTH_NOVEMBER = 11;
90 | /**
91 | * 十二月
92 | */
93 | public static final int MONTH_DECEMBER = 12;
94 | /**
95 | * 润二月
96 | */
97 | public static final int LEAP_YEAR_DAY = 29;
98 | /**
99 | * 一秒相对的毫秒数
100 | */
101 | public static final Long ONE_SECOND = 1000L;
102 | /**
103 | * 一分钟相对的毫秒数
104 | */
105 | public static final Long ONE_MINUTE = 60L * ONE_SECOND;
106 | /**
107 | * 一小时相对的毫秒数
108 | */
109 | public static final Long ONE_HOUR = 60L * ONE_MINUTE;
110 | /**
111 | * 一天相对的毫秒数
112 | */
113 | public static final Long ONE_DAY = 24L * ONE_HOUR;
114 | /**
115 | * 一分钟相对的秒数
116 | */
117 | public static final int ONE_MINUTE_OF_SECONDS = 60;
118 | /**
119 | * 一小时相对的秒数
120 | */
121 | public static final int ONE_HOUR_OF_SECONDS = 60 * ONE_MINUTE_OF_SECONDS;
122 | /**
123 | * 一天相对的秒数
124 | */
125 | public static final int ONE_DAY_OF_SECONDS = 24 * ONE_HOUR_OF_SECONDS;
126 | /**
127 | * 一个月相对的秒数
128 | */
129 | public static final int ONE_MONTH_OF_SECONDS = 30 * ONE_DAY_OF_SECONDS;
130 | /**
131 | * 一年相对的秒数
132 | */
133 | public static final int ONE_YEAR_OF_SECONDS = 12 * ONE_MONTH_OF_SECONDS;
134 | }
135 |
136 | /**
137 | * 基本常量
138 | */
139 | public static class Number {
140 | /**
141 | * 数字0
142 | */
143 | public static final Integer COMMON_NUMBER_ZERO = 0;
144 | /**
145 | * 数字1
146 | */
147 | public static final Integer COMMON_NUMBER_FIRST = 1;
148 | /**
149 | * 数字2
150 | */
151 | public static final Integer COMMON_NUMBER_SECOND = 2;
152 | /**
153 | * 数字3
154 | */
155 | public static final Integer COMMON_NUMBER_THIRD = 3;
156 |
157 | public static final Integer HALF_NUMBER = 2;
158 |
159 | }
160 |
161 | /**
162 | * 加密类型
163 | */
164 | public static class Deciphering {
165 | /**
166 | * 摩斯密码
167 | */
168 | public static final String MORSE_TYPE = "摩斯密码";
169 | /**
170 | * 栅栏密码
171 | */
172 | public static final String RAILFENCE_TYPE = "栅栏密码";
173 | /**
174 | * 手机九宫格
175 | */
176 | public static final String PHONE_TYPEWRITING_TYPE = "手机九宫格";
177 | /**
178 | * 键盘密码
179 | */
180 | public static final String KEYBOARD_TYPE = "键盘密码";
181 | /**
182 | * 培根密码
183 | */
184 | public static final String BACON_TYPE = "培根密码";
185 | /**
186 | * 倒序密码
187 | */
188 | public static final String REVERSE_ORDER_TYPE = "倒序密码";
189 |
190 | /**
191 | * 摩斯密码索引
192 | */
193 | public static final int INDEX_MORSE = 0;
194 | /**
195 | * 栅栏密码索引
196 | */
197 | public static final int INDEX_RAILFENCE = 1;
198 | /**
199 | * 手机九宫格索引
200 | */
201 | public static final int INDEX_PHONE_TYPEWRITING = 2;
202 | /**
203 | * 键盘密码索引
204 | */
205 | public static final int INDEX_KEYBOARD_TYPE = 3;
206 | /**
207 | * 培根密码索引
208 | */
209 | public static final int INDEX_BACON = 4;
210 | /**
211 | * 倒序密码索引
212 | */
213 | public static final int INDEX_REVERSE_ORDER = 5;
214 | }
215 |
216 | public static class Chinese {
217 | /**
218 | * 无字符串定义
219 | */
220 | public static final String NOTHING = "无";
221 |
222 | /**
223 | * 工具类
224 | */
225 | public static final String TOOL = "工具类";
226 |
227 | /**
228 | * 匿名
229 | */
230 | public static final String ANONYMOUS = "匿名";
231 | }
232 |
233 | /**
234 | * reids缓存相关配置
235 | **/
236 | public static class Redis {
237 | public static String REDIS_IP = "127.0.0.1";
238 | public static String REDIS_PASSWORD = null;
239 | public static int REDIS_MAX_ACTIVE = 100;
240 | public static int REDIS_MAX_IDLE = 50;
241 | public static int REDIS_MIN_IDLE = 20;
242 | public static int REDIS_MAX_WAIT_TIME = 2000;
243 | }
244 |
245 | /**
246 | * github-blob
247 | */
248 | public static String GIT_HUB_BLOB_URL = "https://github.com/TangerineSpecter/JavaBaseUtils/blob/master/src/common/util/";
249 |
250 | }
251 |
--------------------------------------------------------------------------------
/src/main/java/com/tangerineSpecter/javaBaseUtils/common/util/DecipheringBaseUtils.java:
--------------------------------------------------------------------------------
1 | package com.tangerinespecter.javabaseutils.common.util;
2 |
3 | import com.tangerinespecter.javabaseutils.common.annotation.ClassInfo;
4 | import lombok.extern.slf4j.Slf4j;
5 |
6 | import java.util.HashMap;
7 | import java.util.Map;
8 |
9 | /**
10 | * 解密工具基础类
11 | *
12 | * @author TangerineSpecter
13 | */
14 | @Slf4j
15 | @ClassInfo(Name = "解密工具基础类")
16 | public class DecipheringBaseUtils {
17 |
18 | /**
19 | * 日志输出信息开关
20 | */
21 | protected static Boolean ERROR_INFO = false;
22 | /**
23 | * 密码索引列表
24 | */
25 | protected static final int[] PASSWORD_INDEX = {0, 1, 2, 3, 4, 5};
26 | /**
27 | * 摩斯密码
28 | */
29 | protected static Map MORSE_CODE_MAP = new HashMap<>();
30 | /**
31 | * 键盘密码
32 | */
33 | protected static Map KEYBOARD_CODE_MAP = new HashMap<>();
34 | /**
35 | * 培根密码
36 | */
37 | protected static Map BACON_CODE_MAP = new HashMap<>();
38 | /**
39 | * 摩斯key
40 | */
41 | protected static final String[] MORSE_KEY = ".----,..---,...--,....-,.....,-....,--...,---..,----.,-----,.-,-...,-.-.,-..,.,..-.,--.,....,..,.---,-.-,.-..,--,-.,---,.--.,--.-,.-.,...,-,..-,...-,.--,-..-,-.--,--.."
42 | .split(",");
43 | /**
44 | * 摩斯value
45 | */
46 | protected static final String[] MORSE_VALUE = "1,2,3,4,5,6,7,8,9,0,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z"
47 | .split(",");
48 |
49 | /**
50 | * 手机九宫格
51 | */
52 | protected static final String[][] TYPEWRITING_BOX = {{" "}, {",", "。", "!", "?"}, {"A", "B", "C"},
53 | {"D", "E", "F"}, {"G", "H", "I"}, {"J", "K", "L"}, {"M", "N", "O"}, {"P", "Q", "R", "S"},
54 | {"T", "U", "V"}, {"W", "X", "Y", "Z"}};
55 |
56 | /**
57 | * 字母表
58 | */
59 | protected static final String[] ALPHABET = "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z".split(",");
60 |
61 | /**
62 | * 键盘字母表
63 | */
64 | protected static final String[] KEYBOARD_VALUE = "Q,W,E,R,T,Y,U,I,O,P,A,S,D,F,G,H,J,K,L,Z,X,C,V,B,N,M".split(",");
65 |
66 | /**
67 | * 培根密码表
68 | */
69 | protected static final String[] BACON_VALUE = "aaaaa,aaaab,aaaba,aaabb,aabaa,aabab,aabba,aabbb,abaaa,abaab,ababa,ababb,abbaa,abbab,abbba,abbbb,baaaa,baaab,baaba,baabb,babaa,babab,babba,babbb,bbaaa,bbaab"
70 | .split(",");
71 |
72 | static {
73 | MORSE_CODE_MAP = getMorseCode();
74 | KEYBOARD_CODE_MAP = getKeyboardCode();
75 | BACON_CODE_MAP = getBaconCode();
76 | }
77 |
78 | /**
79 | * 获取摩斯密码
80 | *
81 | * @return
82 | */
83 | private static Map getMorseCode() {
84 | Map morseMap = new HashMap<>(16);
85 | if (MORSE_KEY.length == MORSE_VALUE.length) {
86 | for (int index = 0; index < MORSE_KEY.length; index++) {
87 | morseMap.put(MORSE_KEY[index], MORSE_VALUE[index]);
88 | }
89 | } else {
90 | log.warn("摩斯密码key,value数量不对等!");
91 | }
92 | return morseMap;
93 | }
94 |
95 | /**
96 | * 获取键盘密码
97 | *
98 | * @return
99 | */
100 | private static Map getKeyboardCode() {
101 | Map keyboardMap = new HashMap<>(16);
102 | if (ALPHABET.length == KEYBOARD_VALUE.length) {
103 | for (int index = 0; index < ALPHABET.length; index++) {
104 | keyboardMap.put(ALPHABET[index], KEYBOARD_VALUE[index]);
105 | }
106 | } else {
107 | log.warn("键盘密码key,value数量不对等!");
108 | }
109 | return keyboardMap;
110 | }
111 |
112 | /**
113 | * 获取培根密码
114 | *
115 | * @return
116 | */
117 | private static Map getBaconCode() {
118 | Map baconMap = new HashMap<>(16);
119 | if (ALPHABET.length == BACON_VALUE.length) {
120 | for (int index = 0; index < ALPHABET.length; index++) {
121 | baconMap.put(ALPHABET[index], BACON_VALUE[index]);
122 | }
123 | } else {
124 | log.warn("培根密码key,value数量不对等!");
125 | }
126 | return baconMap;
127 | }
128 | }
129 |
--------------------------------------------------------------------------------
/src/main/java/com/tangerineSpecter/javaBaseUtils/common/util/DecipheringUtils.java:
--------------------------------------------------------------------------------
1 | package com.tangerinespecter.javabaseutils.common.util;
2 |
3 | import com.tangerinespecter.javabaseutils.common.annotation.ClassInfo;
4 | import com.tangerinespecter.javabaseutils.common.annotation.MethodInfo;
5 | import lombok.extern.slf4j.Slf4j;
6 |
7 | import java.util.ArrayList;
8 | import java.util.List;
9 |
10 | /**
11 | * 解密工具类
12 | *
13 | * @author TangerineSpecter
14 | */
15 | @Slf4j
16 | @ClassInfo(Name = "解密工具类")
17 | public class DecipheringUtils extends DecipheringBaseUtils {
18 |
19 | /**
20 | * 加密摩斯密码
21 | *
22 | * @param content 加密内容
23 | * @return
24 | */
25 | @MethodInfo(Name = "加密摩斯密码", paramInfo = {"加密内容"}, returnInfo = "摩斯加密结果")
26 | public static String setMorseResult(String content) {
27 | StringBuilder result = new StringBuilder(Constant.NULL_KEY_STR);
28 | content = content.replaceAll("\\s*", "").toUpperCase();
29 | for (int index = 0; index < content.length(); index++) {
30 | String value = content.substring(index, index + 1);
31 | for (String getKey : MORSE_CODE_MAP.keySet()) {
32 | if (MORSE_CODE_MAP.get(getKey).equals(value)) {
33 | result.append(getKey).append("/");
34 | }
35 | }
36 | }
37 | return result.substring(0, result.length() - 1);
38 | }
39 |
40 | /**
41 | * 解密摩斯密码
42 | *
43 | * @param morseCode 摩斯密码 用 "/"进行分隔
44 | * @return
45 | */
46 | @MethodInfo(Name = "解密摩斯密码", paramInfo = {"摩斯密码"}, returnInfo = "摩斯解密结果")
47 | public static String getMorseResult(String morseCode) {
48 | StringBuilder result = new StringBuilder(Constant.NULL_KEY_STR);
49 | String[] morseArray = morseCode.split("/");
50 | for (String morse : morseArray) {
51 | if (MORSE_CODE_MAP.get(morse) != null) {
52 | result.append(MORSE_CODE_MAP.get(morse));
53 | }
54 | }
55 | if (Constant.NULL_KEY_STR.equals(result.toString())) {
56 | if (ERROR_INFO) {
57 | log.info(getErrorMessage(morseCode, Constant.Deciphering.MORSE_TYPE));
58 | }
59 | }
60 | return result.toString();
61 | }
62 |
63 | /**
64 | * 栅栏密码解密
65 | *
66 | * @param railfence 栅栏密码
67 | * @param key 栅栏数
68 | * @return
69 | */
70 | @MethodInfo(Name = "栅栏密码解密", paramInfo = {"栅栏密码", "栅栏数"}, returnInfo = "栅栏解密结果")
71 | public static String getRailFenceResult(String railfence, int key) {
72 | StringBuilder result = new StringBuilder();
73 | // 剔除所有空格
74 | String code = railfence.replaceAll("\\s*", "");
75 | if (StringUtils.isEmpty(code)) {
76 | return result.toString();
77 | }
78 | //最小长度
79 | int minLength = 2;
80 | if (key < minLength) {
81 | return code;
82 | }
83 | int length = railfence.length() % key == 0 ? railfence.length() / key : railfence.length() / key + 1;
84 | List results = new ArrayList<>(length);
85 | for (int index = 0; index < length; index++) {
86 | results.add(new StringBuilder());
87 | }
88 | int index = 0;
89 | for (char c : code.toCharArray()) {
90 | results.get(index).append(c);
91 | if (index == length - 1) {
92 | index = 0;
93 | continue;
94 | }
95 | index++;
96 | }
97 | for (StringBuilder row : results) {
98 | result.append(row);
99 | }
100 | return result.toString();
101 | }
102 |
103 | /**
104 | * 栅栏密码加密
105 | *
106 | * @param railfence 栅栏密码
107 | * @param key 栅栏数
108 | * @return
109 | */
110 | @MethodInfo(Name = "栅栏密码加密", paramInfo = {"栅栏密码", "栅栏数"}, returnInfo = "栅栏加密结果")
111 | public static String setRailFenceResult(String railfence, int key) {
112 | StringBuilder result = new StringBuilder();
113 | // 剔除所有空格
114 | String code = railfence.replaceAll("\\s*", "");
115 | if (StringUtils.isEmpty(code)) {
116 | return result.toString();
117 | }
118 | List results = new ArrayList<>(key);
119 | //最小长度
120 | int minLength = 2;
121 | if (key < minLength) {
122 | return code;
123 | }
124 | for (int index = 0; index < key; index++) {
125 | results.add(new StringBuilder());
126 | }
127 | int index = 0;
128 | for (char c : code.toCharArray()) {
129 | results.get(index).append(c);
130 | if (index == key - 1) {
131 | index = 0;
132 | continue;
133 | }
134 | index++;
135 | }
136 | for (StringBuilder row : results) {
137 | result.append(row);
138 | }
139 | return result.toString();
140 | }
141 |
142 | /**
143 | * 字符串转unicode
144 | *
145 | * @param str
146 | * @return
147 | */
148 | @MethodInfo(Name = "字符串转unicode", paramInfo = {"字符串"}, returnInfo = "unicode结果")
149 | public static String string2Unicode(String str) {
150 | StringBuffer unicode = new StringBuffer();
151 | for (int i = 0; i < str.length(); i++) {
152 | // 取出每一个字符
153 | char c = str.charAt(i);
154 | // 转换为unicode
155 | unicode.append("\\u" + Integer.toHexString(c));
156 | }
157 | return unicode.toString();
158 | }
159 |
160 | /**
161 | * unicode转字符串
162 | *
163 | * @param str
164 | * @return
165 | */
166 | @MethodInfo(Name = "unicode转字符串", paramInfo = {"unicode字符串"}, returnInfo = "字符串结果")
167 | public static String unicode2String(String str) {
168 | int start = 0;
169 | int end;
170 | final StringBuffer buffer = new StringBuffer();
171 | while (start > -1) {
172 | end = str.indexOf("\\u", start + 2);
173 | String charStr;
174 | if (end == -1) {
175 | charStr = str.substring(start + 2);
176 | } else {
177 | charStr = str.substring(start + 2, end);
178 | }
179 | char letter = (char) Integer.parseInt(charStr, 16);
180 | buffer.append(letter);
181 | start = end;
182 | }
183 | return buffer.toString();
184 | }
185 |
186 | /**
187 | * 手机九宫格输入法解密
188 | *
189 | * @param content 内容
190 | * @return
191 | */
192 | @MethodInfo(Name = "手机九宫格输入法解密", paramInfo = "解密内容", returnInfo = "解密结果")
193 | public static String getPhoneTypewritingResult(String content) {
194 | StringBuilder result = new StringBuilder(Constant.NULL_KEY_STR);
195 | content = content.replaceAll("\\s*", "");
196 | boolean isNumber = content.matches("[0-9]+");
197 | if (isNumber && content.length() % Constant.Number.HALF_NUMBER == 0) {
198 | try {
199 | for (int index = 0; index < (content.length() / Constant.Number.HALF_NUMBER); index++) {
200 | String key = content.substring(index * 2, (index * 2) + 2);
201 | result.append(TYPEWRITING_BOX[Integer
202 | .parseInt(key.substring(0, 1))][(Integer.parseInt(key.substring(1, 2)) - 1)]);
203 | }
204 | } catch (Exception e) {
205 | if (ERROR_INFO) {
206 | log.info(getErrorMessage(content, Constant.Deciphering.PHONE_TYPEWRITING_TYPE));
207 | }
208 | return Constant.NULL_KEY_STR;
209 | }
210 | }
211 | if (ERROR_INFO) {
212 | log.info(getErrorMessage(content, Constant.Deciphering.PHONE_TYPEWRITING_TYPE));
213 | }
214 | return result.toString();
215 | }
216 |
217 | /**
218 | * 手机九宫格输入法加密
219 | *
220 | * @param content 内容
221 | * @return
222 | */
223 | @MethodInfo(Name = "手机九宫格输入法加密", paramInfo = "解密内容", returnInfo = "加密结果")
224 | public static String setPhoneTypewritingResult(String content) {
225 | StringBuilder result = new StringBuilder(Constant.NULL_KEY_STR);
226 | content = content.replaceAll("\\s*", "").toUpperCase();
227 | for (int i = 0; i < content.length(); i++) {
228 | for (int index = 0; index < TYPEWRITING_BOX.length; index++) {
229 | for (int count = 0; count < TYPEWRITING_BOX[index].length; count++) {
230 | if (TYPEWRITING_BOX[index][count].equals(content.substring(i, i + 1))) {
231 | result.append(index).append((count + 1));
232 | }
233 | }
234 | }
235 | }
236 | return result.toString();
237 | }
238 |
239 | /**
240 | * 加密键盘密码
241 | *
242 | * @param content 加密内容
243 | * @return
244 | */
245 | @MethodInfo(Name = "加密键盘密码", paramInfo = "加密内容", returnInfo = "加密结果")
246 | public static String setKeyboardResult(String content) {
247 | StringBuilder result = new StringBuilder(Constant.NULL_KEY_STR);
248 | content = content.replaceAll("\\s*", "").toUpperCase();
249 | String[] keyboardArray = content.split("");
250 | for (String keyboard : keyboardArray) {
251 | if (KEYBOARD_CODE_MAP.get(keyboard) != null) {
252 | result.append(KEYBOARD_CODE_MAP.get(keyboard));
253 | }
254 | }
255 | if (Constant.NULL_KEY_STR.equals(result.toString())) {
256 | if (ERROR_INFO) {
257 | log.info(getErrorMessage(content, Constant.Deciphering.KEYBOARD_TYPE));
258 | }
259 | }
260 | return result.toString();
261 | }
262 |
263 | /**
264 | * 解密键盘密码
265 | *
266 | * @param keyboardCode 键盘密码
267 | * @return
268 | */
269 | @MethodInfo(Name = "解密键盘密码", paramInfo = "键盘密码", returnInfo = "解密结果")
270 | public static String getKeyboardResult(String keyboardCode) {
271 | StringBuilder result = new StringBuilder(Constant.NULL_KEY_STR);
272 | keyboardCode = keyboardCode.replaceAll("\\s*", "").toUpperCase();
273 | for (int index = 0; index < keyboardCode.length(); index++) {
274 | String value = keyboardCode.substring(index, index + 1);
275 | for (String getKey : KEYBOARD_CODE_MAP.keySet()) {
276 | if (KEYBOARD_CODE_MAP.get(getKey).equals(value)) {
277 | result.append(getKey);
278 | }
279 | }
280 | }
281 | return result.toString();
282 | }
283 |
284 | /**
285 | * 加密培根密码
286 | *
287 | * @param content 加密内容
288 | * @return
289 | */
290 | @MethodInfo(Name = "加密培根密码", paramInfo = "加密内容", returnInfo = "加密结果")
291 | public static String setBaconResult(String content) {
292 | StringBuilder result = new StringBuilder(Constant.NULL_KEY_STR);
293 | content = content.replaceAll("\\s*", "").toUpperCase();
294 | String[] baconArray = content.split("");
295 | for (String bacon : baconArray) {
296 | if (BACON_CODE_MAP.get(bacon) != null) {
297 | result.append(BACON_CODE_MAP.get(bacon));
298 | }
299 | }
300 | if (Constant.NULL_KEY_STR.equals(result.toString())) {
301 | if (ERROR_INFO) {
302 | log.info(getErrorMessage(content, Constant.Deciphering.BACON_TYPE));
303 | }
304 | }
305 | return result.toString();
306 | }
307 |
308 | /**
309 | * 解密培根密码
310 | *
311 | * @param baconCode 培根密码
312 | * @return
313 | */
314 | @MethodInfo(Name = "解密培根密码", paramInfo = "培根密码", returnInfo = "解密结果")
315 | public static String getBaconResult(String baconCode) {
316 | StringBuilder result = new StringBuilder(Constant.NULL_KEY_STR);
317 | baconCode = baconCode.replaceAll("\\s*", "").toUpperCase();
318 | for (int index = 0; index < baconCode.length(); index++) {
319 | String value = baconCode.substring(index, index + 1);
320 | for (String getKey : BACON_CODE_MAP.keySet()) {
321 | if (BACON_CODE_MAP.get(getKey).equals(value)) {
322 | result.append(getKey);
323 | }
324 | }
325 | }
326 | return result.toString();
327 | }
328 |
329 | /**
330 | * 倒序排列
331 | *
332 | * @param content
333 | * @return
334 | */
335 | @MethodInfo(Name = "倒序排列", paramInfo = {"排列内容"}, returnInfo = "排列结果")
336 | public static String reverseOrder(String content) {
337 | return new StringBuffer(content.replaceAll("\\s*", "")).reverse().toString();
338 | }
339 |
340 | /**
341 | * 解密错误提示
342 | */
343 | private static String getErrorMessage(String content, String type) {
344 | return String.format("【错误提示】:[%s]不符合[%s]方式", content, type);
345 | }
346 | }
347 |
--------------------------------------------------------------------------------
/src/main/java/com/tangerineSpecter/javaBaseUtils/common/util/DirUtils.java:
--------------------------------------------------------------------------------
1 | package com.tangerinespecter.javabaseutils.common.util;
2 |
3 | import com.tangerinespecter.javabaseutils.common.annotation.ClassInfo;
4 | import com.tangerinespecter.javabaseutils.common.annotation.MethodInfo;
5 |
6 | import java.io.File;
7 | import java.util.Calendar;
8 |
9 | /**
10 | * 路径处理工具类
11 | *
12 | * @author TangerineSpecter
13 | */
14 | @ClassInfo(Name = "路径处理工具类")
15 | public class DirUtils {
16 |
17 | /**
18 | * 图片
19 | */
20 | private static final String IMG_DIR = "img";
21 | /**
22 | * 音频
23 | */
24 | private static final String AUDIO_DIR = "audio";
25 | /**
26 | * 视频
27 | */
28 | private static final String VIDEO_DIR = "video";
29 |
30 | /**
31 | * getImgDir 获取系统图片的存放路径
32 | *
33 | * @param uuid
34 | * @return 图片路径
35 | */
36 | @MethodInfo(Name = "获取系统图片的存放路径", paramInfo = {"UUID"}, returnInfo = "图片路径")
37 | public static String getImgDir(String uuid) {
38 | return getDir(IMG_DIR, uuid);
39 | }
40 |
41 | /**
42 | * getAudioDir 获取系统音频的存放路径
43 | *
44 | * @param uuid
45 | * @return 音频路径
46 | */
47 | @MethodInfo(Name = "获取系统音频的存放路径", paramInfo = {"UUID"}, returnInfo = "音频路径")
48 | public static String getAudioDir(String uuid) {
49 | return getDir(AUDIO_DIR, uuid);
50 | }
51 |
52 | /**
53 | * getVideoDir 获取系统视频的存放路径
54 | *
55 | * @param uuid
56 | * @return 视频路径
57 | */
58 | @MethodInfo(Name = "获取系统视频的存放路径", paramInfo = {"UUID"}, returnInfo = "视频路径")
59 | public static String getVideoDir(String uuid) {
60 | return getDir(VIDEO_DIR, uuid);
61 | }
62 |
63 | /**
64 | * 获取系统各类子目录
65 | *
66 | * @param subDir 路径头
67 | * @param uuid
68 | * @return
69 | */
70 | @MethodInfo(Name = "获取系统各类子目录", paramInfo = {"路径头", "UUID"}, returnInfo = "文件路径")
71 | private static String getDir(String subDir, String uuid) {
72 | StringBuffer path = new StringBuffer(Constant.FILE_SAVE_PATH);
73 | path.append("/").append(subDir).append("/").append(TimeUtils.timeFormatToDay(Calendar.getInstance().getTime()))
74 | .append("/").append(uuid).append("/");
75 | File file = new File(path.toString());
76 | if (!file.exists()) {
77 | file.mkdirs();
78 | }
79 | return path.toString();
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/src/main/java/com/tangerineSpecter/javaBaseUtils/common/util/EasyExcelUtils.java:
--------------------------------------------------------------------------------
1 | package com.tangerinespecter.javabaseutils.common.util;
2 |
3 | import com.alibaba.excel.EasyExcel;
4 | import com.alibaba.excel.read.builder.ExcelReaderBuilder;
5 | import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
6 | import com.tangerinespecter.javabaseutils.common.test.pojo.ExcelTestHead;
7 | import org.springframework.web.multipart.MultipartFile;
8 |
9 | import javax.servlet.http.HttpServletResponse;
10 | import java.io.File;
11 | import java.io.FileInputStream;
12 | import java.io.IOException;
13 | import java.io.InputStream;
14 | import java.net.URLEncoder;
15 | import java.util.ArrayList;
16 | import java.util.List;
17 |
18 | /**
19 | * EasyExcel处理工具类
20 | *
21 | * @author TangerineSpecter
22 | */
23 | public class EasyExcelUtils {
24 |
25 | /**
26 | * 简单读取
27 | *
28 | * @param file excel文件
29 | */
30 | public static void simpleRead(MultipartFile file) throws IOException {
31 | ExcelReaderBuilder read = EasyExcel.read(file.getInputStream());
32 | List> list = new ArrayList<>();
33 | read.head(list);
34 | read.doReadAll();
35 | for (List strings : list) {
36 | System.out.println(strings);
37 | }
38 | }
39 |
40 | /**
41 | * 将列表以 Excel 响应给前端
42 | *
43 | * @param response 响应
44 | * @param filename 文件名
45 | * @param sheetName Excel sheet 名
46 | * @param head Excel head 头
47 | * @param data 数据列表哦
48 | * @param 泛型,保证 head 和 data 类型的一致性
49 | * @throws IOException 写入失败的情况
50 | */
51 | public static void write(HttpServletResponse response, String filename, String sheetName,
52 | Class head, List data) throws IOException {
53 | // 输出 Excel
54 | EasyExcel.write(response.getOutputStream(), head)
55 | // 不要自动关闭,交给 Servlet 自己处理
56 | .autoCloseStream(false)
57 | // 基于 column 长度,自动适配。最大 255 宽度
58 | .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
59 | .sheet(sheetName).doWrite(data);
60 | // 设置 header 和 contentType。写在最后的原因是,避免报错时,响应 contentType 已经被修改了
61 | response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(filename, "UTF-8"));
62 | response.setContentType("application/vnd.ms-excel;charset=UTF-8");
63 | }
64 |
65 | public static List read(MultipartFile file, Class head) throws IOException {
66 | return EasyExcel.read(file.getInputStream(), head, null)
67 | // 不要自动关闭,交给 Servlet 自己处理
68 | .autoCloseStream(false)
69 | .doReadAllSync();
70 | }
71 |
72 | public static List read(InputStream inputStream, Class head) throws IOException {
73 | return EasyExcel.read(inputStream, head, null)
74 | // 不要自动关闭,交给 Servlet 自己处理
75 | .autoCloseStream(false)
76 | .doReadAllSync();
77 | }
78 |
79 | public static void main(String[] args) throws IOException {
80 | String filePath = "/Users/zhouliangjun/Downloads/生产环境机构及员工信息-0729.xlsx";
81 | File file = new File(filePath);
82 | if (file.isFile()) {
83 | System.out.println("这是一个文件");
84 | }
85 | List read = read(new FileInputStream(file), ExcelTestHead.class);
86 | System.out.println(read);
87 | // ExcelReaderBuilder read = EasyExcel.read(file);
88 | // ExcelReaderSheetBuilder sheet = read.sheet();
89 | // List