diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml
new file mode 100644
index 00000000..36de67a3
--- /dev/null
+++ b/.github/FUNDING.yml
@@ -0,0 +1,12 @@
+# These are supported funding model platforms
+
+github: houko
+patreon: #hupeng
+open_collective: SpringBootUnity
+ko_fi: #hupeng
+tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
+community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
+liberapay: # Replace with a single Liberapay username
+issuehunt: #houko/SpringBootUnity
+otechie: # Replace with a single Otechie username
+custom: #https:blog.xiaomo.info
diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml
new file mode 100644
index 00000000..1620e2e5
--- /dev/null
+++ b/.github/workflows/codeql-analysis.yml
@@ -0,0 +1,72 @@
+# For most projects, this workflow file will not need changing; you simply need
+# to commit it to your repository.
+#
+# You may wish to alter this file to override the set of languages analyzed,
+# or to provide custom queries or build logic.
+#
+# ******** NOTE ********
+# We have attempted to detect the languages in your repository. Please check
+# the `language` matrix defined below to confirm you have the correct set of
+# supported CodeQL languages.
+#
+name: "CodeQL"
+
+on:
+ push:
+ branches: [ "master" ]
+ pull_request:
+ # The branches below must be a subset of the branches above
+ branches: [ "master" ]
+ schedule:
+ - cron: '24 7 * * 0'
+
+jobs:
+ analyze:
+ name: Analyze
+ runs-on: ubuntu-latest
+ permissions:
+ actions: read
+ contents: read
+ security-events: write
+
+ strategy:
+ fail-fast: false
+ matrix:
+ language: [ 'java' ]
+ # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
+ # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
+
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@v3
+
+ # Initializes the CodeQL tools for scanning.
+ - name: Initialize CodeQL
+ uses: github/codeql-action/init@v2
+ with:
+ languages: ${{ matrix.language }}
+ # If you wish to specify custom queries, you can do so here or in a config file.
+ # By default, queries listed here will override any specified in a config file.
+ # Prefix the list here with "+" to use these queries and those in the config file.
+
+ # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
+ # queries: security-extended,security-and-quality
+
+
+ # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
+ # If this step fails, then you should remove it and run the build manually (see below)
+ - name: Autobuild
+ uses: github/codeql-action/autobuild@v2
+
+ # ℹ️ Command-line programs to run using the OS shell.
+ # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
+
+ # If the Autobuild fails above, remove it and uncomment the following three lines.
+ # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
+
+ # - run: |
+ # echo "Run, Build Application using script"
+ # ./location_of_script_within_repo/buildscript.sh
+
+ - name: Perform CodeQL Analysis
+ uses: github/codeql-action/analyze@v2
diff --git a/.travis.yml b/.travis.yml
index dff5f3a5..34d145f8 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1 +1,4 @@
language: java
+jdk:
+ - oraclejdk11
+dist: trusty
\ No newline at end of file
diff --git a/Rakefile b/Rakefile
deleted file mode 100644
index cebe92c4..00000000
--- a/Rakefile
+++ /dev/null
@@ -1,3 +0,0 @@
-require "rubygems"
-require "rake"
-end
\ No newline at end of file
diff --git a/README.md b/Readme.md
similarity index 79%
rename from README.md
rename to Readme.md
index a7b20c4b..6f137c59 100644
--- a/README.md
+++ b/Readme.md
@@ -1,23 +1,22 @@
-[](https://travis-ci.org/xiaomoinfo/SpringBootUnity)
-[](#backers) [](#sponsors) [](https://github.com/xiaomoinfo/SpringBootUnity/issues)
-[](https://raw.githubusercontent.com/xiaomoinfo/MysqlBlobToJsonTool/master/LICENSE)
+[](https://travis-ci.org/houko/SpringBootUnity)
+[](#backers) [](#sponsors) [](https://github.com/houko/SpringBootUnity/issues)
+[](https://raw.githubusercontent.com/houko/SpringBootUnity/master/LICENSE)
[]()
### 项目简介
-
+
### 环境
- `maven` latest
-- `jdk1.8`
-- `spring boot 1.5.8 release`(目前最新版)
-- 个人推荐`idea`来代替eclipse(希望不要被说成异教徒必须死)
-- mysql5.5+
+- `jdk11`
+- `spring boot 2.x release`
+- 个人推荐`idea`来代替eclipse
- git: 版本管理
- nginx: 反向代理服务器
### 注意事项
-- 本项目代码托管在[github](https://github.com/xiaomoinfo/SpringBootUnity)和[码云](http://git.oschina.net/hupeng/SpringBootUnity)两个地方,最新代码会先推送在github上,码云上会在github上更新完之后进行同步。
+- 本项目代码托管在[github](https://github.com/houko/SpringBootUnity)和[码云](http://git.oschina.net/hupeng_admin/SpringBootUnity)两个地方,最新代码会先推送在github上,码云上会在github上更新完之后进行同步。
- 本项目多数数据库都用到了`hibernate`,如果没有提供`sql`文件。则启动时会根据代码映射自动生成数据库表,请在启动前修改`application.properties`中的数据库连接信息
@@ -60,12 +59,19 @@ http://localhost:808/doc.html bootstrap-ui
- 2017-09-08 crawler模块(网络爬虫):修复本地文件目录不存在会报错的bug。处理方式为:不存在则自动创建
- 2017-11-02 开源协议从apache更换到MIT
- 2017-11-02 添加本地运行方式的说明
-- 2017-11-02 版本更新到2017.2
+- 2017-11-02 版本更新到2020.1
- 2017-11-02 spring boot版本更新到1.5.8
- 2017-11-03 添加kotlin环境配置
- 2017-11-03 按照阿里巴巴编程规范插件P3C优化代码
- 2017-11-03 合并`api`和`website`模块,访问`localhost:8080`会显示网站主页,访问`localhost:8080/api`会显示api管理界面
-- 2017-11-03 从java代码转移到kotlin上
+- 2018-04-09 将整个项目升级到spring boot2.0 release版本,api有较大变动
+- 2019-08-06 travis-ci指定jdk版本
+- 2020-10-09 升级版本到2020.2
+- 2020-10-09 升级jdk版本到11
+- 2020-10-09 升级mysql connector到8
+- 2020-10-09 升级spring boot到2.3.0
+- 2020-10-09 修复了升级后API的破坏性变动,修复了一些了编辑器警告
+
@@ -108,42 +114,20 @@ http://localhost:808/doc.html bootstrap-ui
- [在线Cron表达式生成器](http://cron.qqe2.com/ "在线Cron表达式生成器")
- [在线工具 - 程序员的工具箱](http://tool.lu/ "在线工具 - 程序员的工具箱")
+- [spring boot官方脚手架](https://start.spring.io/ "spring boot官方脚手架")
### 问题反馈
-1. 欢迎提[issue](https://github.com/xiaomoinfo/SpringBootUnity/issues)一起完善这个项目。
+1. 欢迎提[issue](https://github.com/houko/SpringBootUnity/issues)一起完善这个项目。
2. QQ: 83387856
4. 个人主站: https://xiaomo.info
-### 在线文档
-
-- [JDK7英文文档](http://tool.oschina.net/apidocs/apidoc?api=jdk_7u4 "JDK7英文文档")
-
-- [Spring4.x文档](http://spring.oschina.mopaas.com/ "Spring4.x文档")
-
-- [Mybatis3官网](http://www.mybatis.org/mybatis-3/zh/index.html "Mybatis3官网")
-
-- [Dubbo官网](http://dubbo.io/ "Dubbo官网")
-
-- [Nginx中文文档](http://tool.oschina.net/apidocs/apidoc?api=nginx-zh "Nginx中文文档")
-
-- [Freemarker在线手册](http://freemarker.foofun.cn/ "Freemarker在线中文手册")
-
-- [Velocity在线手册](http://velocity.apache.org/engine/devel/developer-guide.html "Velocity在线手册")
-
-- [Bootstrap在线手册](http://www.bootcss.com/ "Bootstrap在线手册")
-
-- [Git官网中文文档](https://git-scm.com/book/zh/v2 "Git官网中文文档")
-
-- [Thymeleaf](http://www.thymeleaf.org/doc/tutorials/3.0/thymeleafspring.html "Thymeleaf")
-
-
## [License](LICENSE "MIT")
MIT License
- Copyright (c) 2017 Peng Hu
+ Copyright (c) 2022 Peng Hu
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/SECURITY.md b/SECURITY.md
new file mode 100644
index 00000000..034e8480
--- /dev/null
+++ b/SECURITY.md
@@ -0,0 +1,21 @@
+# Security Policy
+
+## Supported Versions
+
+Use this section to tell people about which versions of your project are
+currently being supported with security updates.
+
+| Version | Supported |
+| ------- | ------------------ |
+| 5.1.x | :white_check_mark: |
+| 5.0.x | :x: |
+| 4.0.x | :white_check_mark: |
+| < 4.0 | :x: |
+
+## Reporting a Vulnerability
+
+Use this section to tell people how to report a vulnerability.
+
+Tell them where to go, how often they can expect to get an update on a
+reported vulnerability, what to expect if the vulnerability is accepted or
+declined, etc.
diff --git a/async/pom.xml b/async/pom.xml
index ae7c1344..60d54b74 100644
--- a/async/pom.xml
+++ b/async/pom.xml
@@ -5,7 +5,7 @@
xiaomo
info.xiaomo
- 2017.2
+ 2020.1
4.0.0
@@ -14,7 +14,7 @@
info.xiaomo
core
- 2017.2
+ 2020.1
diff --git a/async/src/main/java/info/xiaomo/anysc/AsyncMain.java b/async/src/main/java/info/xiaomo/anysc/AsyncMain.java
new file mode 100644
index 00000000..79e1fce0
--- /dev/null
+++ b/async/src/main/java/info/xiaomo/anysc/AsyncMain.java
@@ -0,0 +1,35 @@
+package info.xiaomo.anysc;
+
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.autoconfigure.domain.EntityScan;
+import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
+import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * 把今天最好的表现当作明天最新的起点..~
+ * いま 最高の表現 として 明日最新の始発..~
+ * Today the best performance as tomorrow newest starter!
+
+ *
+ * @author : xiaomo
+ * github: https://github.com/houko
+ * email: xiaomo@xiaomo.info
+ *
+ * Date: 2016/4/1 15:38
+ * Description: RabbitMq启动器
+ * Copyright(©) 2015 by xiaomo.
+ **/
+@Configuration
+@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
+@ComponentScan("info.xiaomo")
+@EntityScan("info.xiaomo.*.model")
+public class AsyncMain {
+ public static void main(String[] args) throws Exception {
+ SpringApplication.run(AsyncMain.class, args);
+ }
+
+}
diff --git a/async/src/main/java/info/xiaomo/anysc/AsyncMain.kt b/async/src/main/java/info/xiaomo/anysc/AsyncMain.kt
deleted file mode 100644
index 1e54d64b..00000000
--- a/async/src/main/java/info/xiaomo/anysc/AsyncMain.kt
+++ /dev/null
@@ -1,32 +0,0 @@
-package info.xiaomo.anysc
-
-
-import org.springframework.boot.SpringApplication
-import org.springframework.boot.autoconfigure.EnableAutoConfiguration
-import org.springframework.boot.autoconfigure.domain.EntityScan
-import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
-import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration
-import org.springframework.context.annotation.ComponentScan
-
-/**
- * 把今天最好的表现当作明天最新的起点..~
- * いま 最高の表現 として 明日最新の始発..~
- * Today the best performance as tomorrow newest starter!
- * Created by IntelliJ IDEA.
- *
- * @author : xiaomo
- * github: https://github.com/xiaomoinfo
- * email: xiaomo@xiaomo.info
- *
- * Date: 2016/4/1 15:38
- * Description: RabbitMq启动器
- * Copyright(©) 2015 by xiaomo.
- */
-@EnableAutoConfiguration(exclude = arrayOf(DataSourceAutoConfiguration::class, HibernateJpaAutoConfiguration::class))
-@ComponentScan("info.xiaomo")
-@EntityScan("info.xiaomo.*.model")
-class AsyncMain
-
-fun main(args: Array) {
- SpringApplication.run(AsyncMain::class.java, *args)
-}
diff --git a/async/src/main/java/info/xiaomo/anysc/controller/TestController.java b/async/src/main/java/info/xiaomo/anysc/controller/TestController.java
new file mode 100644
index 00000000..0817a3a8
--- /dev/null
+++ b/async/src/main/java/info/xiaomo/anysc/controller/TestController.java
@@ -0,0 +1,160 @@
+package info.xiaomo.anysc.controller;
+
+import info.xiaomo.anysc.task.AsyncTask;
+import info.xiaomo.core.base.BaseController;
+import info.xiaomo.core.base.Result;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+import java.util.concurrent.Future;
+
+/**
+ * 把今天最好的表现当作明天最新的起点..~
+ * いま 最高の表現 として 明日最新の始発..~
+ * Today the best performance as tomorrow newest starter!
+
+ *
+ * @author : xiaomo
+ * github: https://github.com/houko
+ * email: xiaomo@xiaomo.info
+ *
+ * Date: 2016/11/15 15:12
+ * Description: 用户实体类
+ * Copyright(©) 2015 by xiaomo.
+ **/
+
+@RestController
+@RequestMapping("/")
+public class TestController extends BaseController {
+
+ private final AsyncTask task;
+
+ @Autowired
+ public TestController(AsyncTask task) {
+ this.task = task;
+ }
+
+ @RequestMapping(value = "/", method = RequestMethod.GET)
+ public Result task() throws Exception {
+ long start = System.currentTimeMillis();
+
+ Future task1 = task.doTaskOne();
+ Future task2 = task.doTaskTwo();
+ Future task3 = task.doTaskThree();
+
+ while (true) {
+ if (task1.isDone() && task2.isDone() && task3.isDone()) {
+ // 三个任务都调用完成,退出循环等待
+ break;
+ }
+ Thread.sleep(1000);
+ }
+
+ long end = System.currentTimeMillis();
+
+ System.out.println("任务全部完成,总耗时:" + (end - start) + "毫秒");
+ return new Result<>(end - start);
+ }
+
+
+ /**
+ * 查找所有(不带分页)
+ *
+ * @return result
+ */
+ @Override
+ public Result findAll() {
+ return null;
+ }
+
+ /**
+ * 带分页
+ *
+ * @param start 起始页
+ * @param pageSize 页码数
+ * @return result
+ */
+ @Override
+ public Result findAll(@PathVariable int start, @PathVariable int pageSize) {
+ return null;
+ }
+
+ /**
+ * 根据id查看模型
+ *
+ * @param id id
+ * @return result
+ */
+ @Override
+ public Result findById(@PathVariable Long id) {
+ return null;
+ }
+
+ /**
+ * 根据名字查找模型
+ *
+ * @param name name
+ * @return result
+ */
+ @Override
+ public Result findByName(@PathVariable String name) {
+ return null;
+ }
+
+ /**
+ * 根据名字删除模型
+ *
+ * @param name name
+ * @return result
+ */
+ @Override
+ public Result delByName(@PathVariable String name) {
+ return null;
+ }
+
+ /**
+ * 根据id删除模型
+ *
+ * @param id id
+ * @return result
+ */
+ @Override
+ public Result delById(@PathVariable Long id) {
+ return null;
+ }
+
+ /**
+ * 添加模型
+ *
+ * @param model model
+ * @return result
+ */
+ @Override
+ public Result add(@RequestBody Object model) {
+ return null;
+ }
+
+ /**
+ * 更新
+ *
+ * @param model model
+ * @return result
+ */
+ @Override
+ public Result update(@RequestBody Object model) {
+ return null;
+ }
+
+ /**
+ * 批量删除
+ *
+ * @param ids ids
+ * @return result
+ */
+ @Override
+ public Result delByIds(@PathVariable List ids) {
+ return null;
+ }
+}
diff --git a/async/src/main/java/info/xiaomo/anysc/controller/TestController.kt b/async/src/main/java/info/xiaomo/anysc/controller/TestController.kt
deleted file mode 100644
index 424ca917..00000000
--- a/async/src/main/java/info/xiaomo/anysc/controller/TestController.kt
+++ /dev/null
@@ -1,54 +0,0 @@
-package info.xiaomo.anysc.controller
-
-import info.xiaomo.anysc.task.AsyncTask
-import info.xiaomo.core.base.Result
-import org.springframework.beans.factory.annotation.Autowired
-import org.springframework.web.bind.annotation.RequestMapping
-import org.springframework.web.bind.annotation.RequestMethod
-import org.springframework.web.bind.annotation.RestController
-
-/**
- * 把今天最好的表现当作明天最新的起点..~
- * いま 最高の表現 として 明日最新の始発..~
- * Today the best performance as tomorrow newest starter!
- * Created by IntelliJ IDEA.
- *
- * @author : xiaomo
- * github: https://github.com/xiaomoinfo
- * email: xiaomo@xiaomo.info
- *
- *
- * Date: 2016/11/15 15:12
- * Description: 用户实体类
- * Copyright(©) 2015 by xiaomo.
- */
-
-@RestController
-@RequestMapping("/")
-class TestController
-@Autowired constructor(private val task: AsyncTask) {
-
- @RequestMapping(value = "/", method = arrayOf(RequestMethod.GET))
- @Throws(Exception::class)
- fun task(): Result<*> {
- val start = System.currentTimeMillis()
-
- val task1 = task.doTaskOne()
- val task2 = task.doTaskTwo()
- val task3 = task.doTaskThree()
-
- while (true) {
- if (task1.isDone && task2.isDone && task3.isDone) {
- // 三个任务都调用完成,退出循环等待
- break
- }
- Thread.sleep(1000)
- }
-
- val end = System.currentTimeMillis()
-
- println("任务全部完成,总耗时:" + (end - start) + "毫秒")
- return Result(end - start)
- }
-
-}
diff --git a/async/src/main/java/info/xiaomo/anysc/task/AsyncTask.java b/async/src/main/java/info/xiaomo/anysc/task/AsyncTask.java
new file mode 100644
index 00000000..73ac1fc5
--- /dev/null
+++ b/async/src/main/java/info/xiaomo/anysc/task/AsyncTask.java
@@ -0,0 +1,48 @@
+package info.xiaomo.anysc.task;
+
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.scheduling.annotation.AsyncResult;
+import org.springframework.stereotype.Component;
+
+import java.util.Random;
+import java.util.concurrent.Future;
+
+/**
+ * @author : xiaomo
+ */
+@Component
+public class AsyncTask {
+
+ private static Random random = new Random();
+
+ @Async
+ public Future doTaskOne() throws Exception {
+ System.out.println("开始做任务一");
+ long start = System.currentTimeMillis();
+ Thread.sleep(random.nextInt(10000));
+ long end = System.currentTimeMillis();
+ System.out.println("完成任务一,耗时:" + (end - start) + "毫秒");
+ return new AsyncResult<>("任务一完成");
+ }
+
+ @Async
+ public Future doTaskTwo() throws Exception {
+ System.out.println("开始做任务二");
+ long start = System.currentTimeMillis();
+ Thread.sleep(random.nextInt(10000));
+ long end = System.currentTimeMillis();
+ System.out.println("完成任务二,耗时:" + (end - start) + "毫秒");
+ return new AsyncResult<>("任务二完成");
+ }
+
+ @Async
+ public Future doTaskThree() throws Exception {
+ System.out.println("开始做任务三");
+ long start = System.currentTimeMillis();
+ Thread.sleep(random.nextInt(10000));
+ long end = System.currentTimeMillis();
+ System.out.println("完成任务三,耗时:" + (end - start) + "毫秒");
+ return new AsyncResult<>("任务三完成");
+ }
+
+}
diff --git a/async/src/main/java/info/xiaomo/anysc/task/AsyncTask.kt b/async/src/main/java/info/xiaomo/anysc/task/AsyncTask.kt
deleted file mode 100644
index 8e9c094d..00000000
--- a/async/src/main/java/info/xiaomo/anysc/task/AsyncTask.kt
+++ /dev/null
@@ -1,53 +0,0 @@
-package info.xiaomo.anysc.task
-
-import org.springframework.scheduling.annotation.Async
-import org.springframework.scheduling.annotation.AsyncResult
-import org.springframework.stereotype.Component
-import java.util.*
-import java.util.concurrent.Future
-
-/**
- * @author : xiaomo
- */
-@Component
-open class AsyncTask {
-
- @Async
- @Throws(Exception::class)
- open fun doTaskOne(): Future {
- println("开始做任务一")
- val start = System.currentTimeMillis()
- Thread.sleep(random.nextInt(10000).toLong())
- val end = System.currentTimeMillis()
- println("完成任务一,耗时:" + (end - start) + "毫秒")
- return AsyncResult("任务一完成")
- }
-
- @Async
- @Throws(Exception::class)
- open fun doTaskTwo(): Future {
- println("开始做任务二")
- val start = System.currentTimeMillis()
- Thread.sleep(random.nextInt(10000).toLong())
- val end = System.currentTimeMillis()
- println("完成任务二,耗时:" + (end - start) + "毫秒")
- return AsyncResult("任务二完成")
- }
-
- @Async
- @Throws(Exception::class)
- open fun doTaskThree(): Future {
- println("开始做任务三")
- val start = System.currentTimeMillis()
- Thread.sleep(random.nextInt(10000).toLong())
- val end = System.currentTimeMillis()
- println("完成任务三,耗时:" + (end - start) + "毫秒")
- return AsyncResult("任务三完成")
- }
-
- companion object {
-
- private val random = Random()
- }
-
-}
diff --git a/async/src/main/resources/config/application.properties b/async/src/main/resources/config/application.properties
index 2bbf0e38..79ef9397 100644
--- a/async/src/main/resources/config/application.properties
+++ b/async/src/main/resources/config/application.properties
@@ -1,8 +1,9 @@
logging.config=classpath:config/logback-dev.xml
server.port=8080
-server.session.timeout=1800
+
server.max-http-header-size=20971520
# \u914D\u7F6E\u8FD9\u4E2A\u503C\u5C31\u53EF\u4EE5\u683C\u5F0F\u5316\u65F6\u95F4
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8
+spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
\ No newline at end of file
diff --git a/core/pom.xml b/core/pom.xml
index accd4fa0..8e3af9eb 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -5,7 +5,7 @@
info.xiaomo
xiaomo
- 2017.2
+ 2020.1
4.0.0
@@ -63,6 +63,10 @@
commons-fileupload
commons-fileupload
+
+ org.projectlombok
+ lombok
+
dom4j
dom4j
@@ -80,4 +84,18 @@
poi
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+ none
+
+
+
+
+
\ No newline at end of file
diff --git a/core/src/main/java/info/xiaomo/core/base/AuthOperate.kt b/core/src/main/java/info/xiaomo/core/base/AuthOperate.java
similarity index 52%
rename from core/src/main/java/info/xiaomo/core/base/AuthOperate.kt
rename to core/src/main/java/info/xiaomo/core/base/AuthOperate.java
index f0c8de57..76889389 100644
--- a/core/src/main/java/info/xiaomo/core/base/AuthOperate.kt
+++ b/core/src/main/java/info/xiaomo/core/base/AuthOperate.java
@@ -1,13 +1,14 @@
-package info.xiaomo.core.base
+package info.xiaomo.core.base;
-import org.springframework.web.bind.annotation.PathVariable
-import java.util.*
+import org.springframework.web.bind.annotation.PathVariable;
+
+import java.util.Date;
/**
- * @author : xiaomo (https://xiaomo.info) (https://github.com/xiaomoinfo)
+ * @author : xiaomo (https://xiaomo.info) (https://github.com/houko)
* @version : 2017/1/13 9:51
*/
-interface AuthOperate {
+public interface AuthOperate {
/**
@@ -17,7 +18,7 @@ interface AuthOperate {
* @param password 密码
* @return 结果
*/
- fun login(@PathVariable name: String, @PathVariable password: String): Result
+ Result login(@PathVariable String name, @PathVariable String password);
/**
@@ -27,7 +28,7 @@ fun login(@PathVariable name: String, @PathVariable password: String): Result
+ Result changePassword(@PathVariable String name, @PathVariable String password);
/**
* 注册
@@ -36,7 +37,7 @@ fun changePassword(@PathVariable name: String, @PathVariable password: String):
* @param password 密码
* @return 是否己发送验证码
*/
- fun register(@PathVariable name: String, @PathVariable password: String): Result
+ Result register(@PathVariable String name, @PathVariable String password);
/**
* 验证
@@ -45,6 +46,6 @@ fun register(@PathVariable name: String, @PathVariable password: String): Result
* @param time 发送时间
* @return 是否验证通过
*/
- fun validate(@PathVariable validCode: Int, @PathVariable time: Date): Result
+ Result validate(@PathVariable int validCode, @PathVariable Date time);
}
diff --git a/core/src/main/java/info/xiaomo/core/base/BaseController.java b/core/src/main/java/info/xiaomo/core/base/BaseController.java
new file mode 100644
index 00000000..b2f5d2c8
--- /dev/null
+++ b/core/src/main/java/info/xiaomo/core/base/BaseController.java
@@ -0,0 +1,96 @@
+package info.xiaomo.core.base;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.data.domain.Page;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+
+/**
+ * @author : xiaomo (https://xiaomo.info) (https://github.com/houko)
+ * @version : 2017/1/11 16:41
+ */
+@RestController
+public abstract class BaseController {
+
+ protected final Logger LOGGER = LoggerFactory.getLogger(getClass());
+
+ /**
+ * 查找所有(不带分页)
+ *
+ * @return result
+ */
+ public abstract Result> findAll();
+
+ /**
+ * 带分页
+ *
+ * @param start 起始页
+ * @param pageSize 页码数
+ * @return result
+ */
+ public abstract Result> findAll(@PathVariable int start, @PathVariable int pageSize);
+
+ /**
+ * 根据id查看模型
+ *
+ * @param id id
+ * @return result
+ */
+ public abstract Result findById(@PathVariable Long id);
+
+ /**
+ * 根据名字查找模型
+ *
+ * @param name name
+ * @return result
+ */
+ public abstract Result findByName(@PathVariable String name);
+
+ /**
+ * 根据名字删除模型
+ *
+ * @param name name
+ * @return result
+ */
+ public abstract Result delByName(@PathVariable String name);
+
+
+ /**
+ * 根据id删除模型
+ *
+ * @param id id
+ * @return result
+ */
+ public abstract Result delById(@PathVariable Long id);
+
+ /**
+ * 添加模型
+ *
+ * @param model model
+ * @return result
+ */
+ public abstract Result add(@RequestBody T model);
+
+
+ /**
+ * 更新
+ *
+ * @param model model
+ * @return result
+ */
+ public abstract Result update(@RequestBody T model);
+
+
+ /**
+ * 批量删除
+ *
+ * @param ids ids
+ * @return result
+ */
+ public abstract Result delByIds(@PathVariable List ids);
+
+}
\ No newline at end of file
diff --git a/core/src/main/java/info/xiaomo/core/base/BaseDao.java b/core/src/main/java/info/xiaomo/core/base/BaseDao.java
new file mode 100644
index 00000000..d9c6941a
--- /dev/null
+++ b/core/src/main/java/info/xiaomo/core/base/BaseDao.java
@@ -0,0 +1,28 @@
+package info.xiaomo.core.base;
+
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+
+/**
+ * @author : xiaomo (https://xiaomo.info) (https://github.com/houko)
+ * @version : 2017/1/13 11:23
+ */
+@Repository
+public interface BaseDao extends JpaRepository {
+
+ /**
+ * 根据名字查
+ *
+ * @param name
+ * @return
+ */
+ T findByName(String name);
+
+ /**
+ * 删除
+ *
+ * @param name
+ * @return
+ */
+ boolean deleteByName(String name);
+}
diff --git a/core/src/main/java/info/xiaomo/core/base/BaseDao.kt b/core/src/main/java/info/xiaomo/core/base/BaseDao.kt
deleted file mode 100644
index 09dc7351..00000000
--- a/core/src/main/java/info/xiaomo/core/base/BaseDao.kt
+++ /dev/null
@@ -1,34 +0,0 @@
-package info.xiaomo.core.base
-
-import org.springframework.data.jpa.repository.JpaRepository
-import org.springframework.stereotype.Repository
-
-/**
- * @author : xiaomo (https://xiaomo.info) (https://github.com/xiaomoinfo)
- * @version : 2017/1/13 11:23
- */
-@Repository
-interface BaseDao : JpaRepository {
-
- /**
- * 根据id查
- *
- * @param id
- * @return
- */
- fun findById(id: Long?): T
-
- /**
- * 根据名字查
- * @param name
- * @return
- */
- fun findByName(name: String): T
-
- /**
- * 删除
- * @param name
- * @return
- */
- fun deleteByName(name: String): Boolean
-}
diff --git a/core/src/main/java/info/xiaomo/core/base/BaseModel.java b/core/src/main/java/info/xiaomo/core/base/BaseModel.java
new file mode 100644
index 00000000..37d18bbe
--- /dev/null
+++ b/core/src/main/java/info/xiaomo/core/base/BaseModel.java
@@ -0,0 +1,40 @@
+package info.xiaomo.core.base;
+
+import lombok.Data;
+
+import javax.persistence.*;
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * 把今天最好的表现当作明天最新的起点..~
+ * いま 最高の表現 として 明日最新の始発..~
+ * Today the best performance as tomorrow newest starter!
+
+ *
+ * @author : xiaomo
+ * github: https://github.com/houko
+ * email: xiaomo@xiaomo.info
+ *
+ * Date: 2016/4/1 20:37
+ * Copyright(©) 2015 by xiaomo.
+ **/
+
+@MappedSuperclass
+@Data
+public abstract class BaseModel implements Serializable {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ @Column(name = "Id")
+ private Long id;
+
+ @Column(name = "Name")
+ private String name;
+
+ @Column(name = "CreateTime")
+ private Date createTime;
+
+ @Column(name = "UpdateTime")
+ private Date updateTime;
+}
diff --git a/core/src/main/java/info/xiaomo/core/base/BaseModel.kt b/core/src/main/java/info/xiaomo/core/base/BaseModel.kt
deleted file mode 100644
index be1c1035..00000000
--- a/core/src/main/java/info/xiaomo/core/base/BaseModel.kt
+++ /dev/null
@@ -1,49 +0,0 @@
-package info.xiaomo.core.base
-
-import java.io.Serializable
-import java.util.*
-import javax.persistence.*
-
-/**
- * 把今天最好的表现当作明天最新的起点..~
- * いま 最高の表現 として 明日最新の始発..~
- * Today the best performance as tomorrow newest starter!
- * Created by IntelliJ IDEA.
- *
- * @author : xiaomo
- * github: https://github.com/xiaomoinfo
- * email: xiaomo@xiaomo.info
- *
- * Date: 2016/4/1 20:37
- * Copyright(©) 2015 by xiaomo.
- */
-
-@MappedSuperclass
-abstract class BaseModel : Serializable {
-
- @Id
- @GeneratedValue(strategy = GenerationType.AUTO)
- @Column(name = "Id")
- var id: Long? = null
- set(id) {
- field = this.id
- }
-
- @Column(name = "modelName")
- var name: String? = null
- set(modelName) {
- field = this.name
- }
-
- @Column(name = "CreateTime")
- var createTime: Date? = null
- set(createTime) {
- field = this.createTime
- }
-
- @Column(name = "UpdateTime")
- var updateTime: Date? = null
- set(updateTime) {
- field = this.updateTime
- }
-}
diff --git a/core/src/main/java/info/xiaomo/core/base/BaseService.kt b/core/src/main/java/info/xiaomo/core/base/BaseService.java
similarity index 57%
rename from core/src/main/java/info/xiaomo/core/base/BaseService.kt
rename to core/src/main/java/info/xiaomo/core/base/BaseService.java
index d7fea503..4ff3a02f 100644
--- a/core/src/main/java/info/xiaomo/core/base/BaseService.kt
+++ b/core/src/main/java/info/xiaomo/core/base/BaseService.java
@@ -1,14 +1,16 @@
-package info.xiaomo.core.base
+package info.xiaomo.core.base;
-import org.springframework.data.domain.Page
-import org.springframework.stereotype.Service
+import org.springframework.data.domain.Page;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
/**
- * @author : xiaomo (https://xiaomo.info) (https://github.com/xiaomoinfo)
+ * @author : xiaomo (https://xiaomo.info) (https://github.com/houko)
* @version : 2017/1/11 16:42
*/
@Service
-interface BaseService {
+public interface BaseService {
/**
* 根据id查
@@ -16,7 +18,7 @@ interface BaseService {
* @param id
* @return
*/
- fun findById(id: Long?): T
+ T findById(Long id);
/**
* 根据名字查
@@ -24,14 +26,14 @@ fun findById(id: Long?): T
* @param name
* @return
*/
- fun findByName(name: String): T
+ T findByName(String name);
/**
* 查找所有
*
* @return
*/
- fun findAll(): List
+ List findAll();
/**
* 分页查询
@@ -40,7 +42,7 @@ fun findAll(): List
* @param pageSize
* @return
*/
- fun findAll(start: Int, pageSize: Int): Page
+ Page findAll(int start, int pageSize);
/**
* 根据id删除
@@ -48,7 +50,7 @@ fun findAll(start: Int, pageSize: Int): Page
* @param id
* @return
*/
- fun deleteById(id: Long?): Boolean
+ boolean deleteById(Long id);
/**
* 根据名字删除
@@ -56,7 +58,7 @@ fun deleteById(id: Long?): Boolean
* @param name
* @return
*/
- fun deleteByName(name: String): Boolean
+ boolean deleteByName(String name);
/**
* 增加
@@ -64,7 +66,7 @@ fun deleteByName(name: String): Boolean
* @param model
* @return
*/
- fun add(model: T): Boolean
+ boolean add(T model);
/**
* 更新
@@ -72,7 +74,7 @@ fun add(model: T): Boolean
* @param model
* @return
*/
- fun update(model: T): Boolean
+ boolean update(T model);
/**
* 批量删除
@@ -80,5 +82,5 @@ fun update(model: T): Boolean
* @param ids
* @return
*/
- fun deleteByIds(ids: List): Boolean
+ boolean deleteByIds(List ids);
}
diff --git a/core/src/main/java/info/xiaomo/core/base/Result.kt b/core/src/main/java/info/xiaomo/core/base/Result.java
similarity index 56%
rename from core/src/main/java/info/xiaomo/core/base/Result.kt
rename to core/src/main/java/info/xiaomo/core/base/Result.java
index a0b082c2..4ec1cb45 100644
--- a/core/src/main/java/info/xiaomo/core/base/Result.kt
+++ b/core/src/main/java/info/xiaomo/core/base/Result.java
@@ -1,35 +1,37 @@
-package info.xiaomo.core.base
+package info.xiaomo.core.base;
+
+import lombok.Data;
/**
* 把今天最好的表现当作明天最新的起点..~
* いま 最高の表現 として 明日最新の始発..~
* Today the best performance as tomorrow newest starter!
- * Created by IntelliJ IDEA.
+
*
* @author : xiaomo
- * github: https://github.com/xiaomoinfo
+ * github: https://github.com/houko
* email: xiaomo@xiaomo.info
- *
+ *
* Date: 2016/10/31 15:25
* Description: 返回结果
* Copyright(©) 2015 by xiaomo.
*/
+@Data
+public class Result {
-class Result {
-
- private var resultCode = 200
+ private int resultCode = 200;
- private var message = "SUCCESS"
+ private String message = "SUCCESS";
- private var data: T? = null
+ private T data;
/**
* 只返回错误码
*
* @param resultCode resultCode
*/
- constructor(resultCode: Int) {
- this.resultCode = resultCode
+ public Result(int resultCode) {
+ this.resultCode = resultCode;
}
/**
@@ -37,8 +39,8 @@ class Result {
*
* @param data data
*/
- constructor(data: T) {
- this.data = data
+ public Result(T data) {
+ this.data = data;
}
/**
@@ -47,9 +49,9 @@ class Result {
* @param resultCode resultCode
* @param message message
*/
- constructor(resultCode: Int, message: String) {
- this.resultCode = resultCode
- this.message = message
+ public Result(int resultCode, String message) {
+ this.resultCode = resultCode;
+ this.message = message;
}
@@ -60,9 +62,9 @@ class Result {
* @param message message
* @param data data
*/
- constructor(resultCode: Int, message: String, data: T) {
- this.resultCode = resultCode
- this.message = message
- this.data = data
+ public Result(int resultCode, String message, T data) {
+ this.resultCode = resultCode;
+ this.message = message;
+ this.data = data;
}
}
diff --git a/core/src/main/java/info/xiaomo/core/constant/CodeConst.kt b/core/src/main/java/info/xiaomo/core/constant/CodeConst.java
similarity index 52%
rename from core/src/main/java/info/xiaomo/core/constant/CodeConst.kt
rename to core/src/main/java/info/xiaomo/core/constant/CodeConst.java
index 29664e2e..9b411ca5 100644
--- a/core/src/main/java/info/xiaomo/core/constant/CodeConst.kt
+++ b/core/src/main/java/info/xiaomo/core/constant/CodeConst.java
@@ -1,21 +1,20 @@
-package info.xiaomo.core.constant
+package info.xiaomo.core.constant;
/**
* 把今天最好的表现当作明天最新的起点..~
* いま 最高の表現 として 明日最新の始発..~
* Today the best performance as tomorrow newest starter!
- * Created by IntelliJ IDEA.
+
*
* @author : xiaomo
- * github: https://github.com/xiaomoinfo
+ * github: https://github.com/houko
* email: xiaomo@xiaomo.info
- *
- *
+ *
* Date: 2016/10/29 10:59
* Description: 错误码
* Copyright(©) 2015 by xiaomo.
*/
-enum class CodeConst {
+public enum CodeConst {
/**
* success
*/
@@ -31,19 +30,35 @@ enum class CodeConst {
AUTH_FAILED(999, "用户名或密码错误");
- var resultCode: Int = 0
- var message: String? = null
+ private int resultCode;
+ private String message;
+
+ CodeConst(int resultCode) {
+ this.resultCode = resultCode;
+ }
+
+ CodeConst(String message) {
+ this.message = message;
+ }
+
+ CodeConst(int resultCode, String message) {
+ this.resultCode = resultCode;
+ this.message = message;
+ }
+
+ public int getResultCode() {
+ return resultCode;
+ }
- constructor(resultCode: Int) {
- this.resultCode = resultCode
+ public void setResultCode(int resultCode) {
+ this.resultCode = resultCode;
}
- constructor(message: String) {
- this.message = message
+ public String getMessage() {
+ return message;
}
- constructor(resultCode: Int, message: String) {
- this.resultCode = resultCode
- this.message = message
+ public void setMessage(String message) {
+ this.message = message;
}
}
diff --git a/core/src/main/java/info/xiaomo/core/constant/FileConst.kt b/core/src/main/java/info/xiaomo/core/constant/FileConst.java
similarity index 87%
rename from core/src/main/java/info/xiaomo/core/constant/FileConst.kt
rename to core/src/main/java/info/xiaomo/core/constant/FileConst.java
index 6d105013..c816674f 100644
--- a/core/src/main/java/info/xiaomo/core/constant/FileConst.kt
+++ b/core/src/main/java/info/xiaomo/core/constant/FileConst.java
@@ -1,16 +1,10 @@
-package info.xiaomo.core.constant
+package info.xiaomo.core.constant;
/**
* @author qq
*/
-enum class FileConst
-/**
- * Constructor.
- *
- * @param value
- */
-(value: String) {
+public enum FileConst {
/**
* JEPG.
*/
@@ -86,8 +80,7 @@ enum class FileConst
/**
* MS Word/Excel.
*/
- XLS_DOC("D0CF11E0"),
- XLSX_DOCX("504B030414000600080000002100"),
+ XLS_DOC("D0CF11E0"), XLSX_DOCX("504B030414000600080000002100"),
/**
* Visio
*/
@@ -223,11 +216,23 @@ enum class FileConst
* FLV.
*/
FLV("464C5601050000000900");
+ private String value = "";
- var value = ""
+ /**
+ * Constructor.
+ *
+ * @param value
+ */
+ FileConst(String value) {
+ this.value = value;
+ }
+
+ public String getValue() {
+ return value;
+ }
- init {
- this.value = value
+ public void setValue(String value) {
+ this.value = value;
}
}
\ No newline at end of file
diff --git a/core/src/main/java/info/xiaomo/core/constant/GenderConst.kt b/core/src/main/java/info/xiaomo/core/constant/GenderConst.java
similarity index 59%
rename from core/src/main/java/info/xiaomo/core/constant/GenderConst.kt
rename to core/src/main/java/info/xiaomo/core/constant/GenderConst.java
index 8c5b2415..05694372 100644
--- a/core/src/main/java/info/xiaomo/core/constant/GenderConst.kt
+++ b/core/src/main/java/info/xiaomo/core/constant/GenderConst.java
@@ -1,27 +1,25 @@
-package info.xiaomo.core.constant
+package info.xiaomo.core.constant;
/**
* 把今天最好的表现当作明天最新的起点..~
* いま 最高の表現 として 明日最新の始発..~
* Today the best performance as tomorrow newest starter!
- * Created by IntelliJ IDEA.
+
*
* @author : xiaomo
- * github: https://github.com/xiaomoinfo
+ * github: https://github.com/houko
* email: xiaomo@xiaomo.info
- *
+ *
* Date: 2016/1/12 16:37
* Description: 性别
* Copyright(©) 2015 by xiaomo.
- */
-interface GenderConst {
- companion object {
+ **/
+public interface GenderConst {
- val SECRET = 0
+ int SECRET = 0;
- val MAN = 1
+ int MAN = 1;
- val WOMAN = 2
- }
+ int WOMAN = 2;
}
diff --git a/core/src/main/java/info/xiaomo/core/constant/SymbolConst.java b/core/src/main/java/info/xiaomo/core/constant/SymbolConst.java
new file mode 100644
index 00000000..c4dbcfeb
--- /dev/null
+++ b/core/src/main/java/info/xiaomo/core/constant/SymbolConst.java
@@ -0,0 +1,22 @@
+package info.xiaomo.core.constant;
+
+/**
+ * @author : xiaomo
+ */
+public class SymbolConst {
+ public static final String JINHAO = "#";
+ public static final String AND = "&";
+ public static final String SHUXIAN = "\\|";
+ public static final String JINHAO_TWO = "##";
+ public static final String GANTANHAO = "!";
+ public static final String FENHAO = ";";
+ public static final String HENGXIAN = "-";
+ public static final String JINHAO__AND_GANTANHAO = "#!";
+ public static final String JINHAO_AND_BAIFENHAO = "#%";
+ public static final String DOUHAO = ",";
+ public static final String DIAN = ".";
+ public static final String ZHENGXIEXIAN = "/";
+ public static final String DENGHAO = "=";
+ public static final String SPACE = " ";
+ public static final String AT = "@";
+}
diff --git a/core/src/main/java/info/xiaomo/core/constant/SymbolConst.kt b/core/src/main/java/info/xiaomo/core/constant/SymbolConst.kt
deleted file mode 100644
index 18183ca3..00000000
--- a/core/src/main/java/info/xiaomo/core/constant/SymbolConst.kt
+++ /dev/null
@@ -1,22 +0,0 @@
-package info.xiaomo.core.constant
-
-/**
- * @author : xiaomo
- */
-object SymbolConst {
- val JINHAO = "#"
- val AND = "&"
- val SHUXIAN = "\\|"
- val JINHAO_TWO = "##"
- val GANTANHAO = "!"
- val FENHAO = ";"
- val HENGXIAN = "-"
- val JINHAO__AND_GANTANHAO = "#!"
- val JINHAO_AND_BAIFENHAO = "#%"
- val DOUHAO = ","
- val DIAN = "."
- val ZHENGXIEXIAN = "/"
- val DENGHAO = "="
- val SPACE = " "
- val AT = "@"
-}
diff --git a/core/src/main/java/info/xiaomo/core/exception/UserNotFoundException.kt b/core/src/main/java/info/xiaomo/core/exception/UserNotFoundException.java
similarity index 81%
rename from core/src/main/java/info/xiaomo/core/exception/UserNotFoundException.kt
rename to core/src/main/java/info/xiaomo/core/exception/UserNotFoundException.java
index 66c36015..ee06bc04 100644
--- a/core/src/main/java/info/xiaomo/core/exception/UserNotFoundException.kt
+++ b/core/src/main/java/info/xiaomo/core/exception/UserNotFoundException.java
@@ -1,4 +1,4 @@
-package info.xiaomo.core.exception
+package info.xiaomo.core.exception;
/**
* │\__╭╭╭╭╭__/│
@@ -12,14 +12,16 @@
* |╭---╮把今天最好的表现当作明天最新的起点..~
* いま 最高の表現 として 明日最新の始発..~
* Today the best performance as tomorrow newest starter!
- * Created by IntelliJ IDEA.
+
*
* @author : xiaomo
- * github: https://github.com/xiaomoinfo
+ * github: https://github.com/houko
* email: xiaomo@xiaomo.info
- *
+ *
* Date: 16/4/3 11:08
* Description: 找不到用户异常
* Copyright(©) 2015 by xiaomo.
*/
-class UserNotFoundException : Exception()
+public class UserNotFoundException extends Exception {
+
+}
diff --git a/core/src/main/java/info/xiaomo/core/field/LoginField.java b/core/src/main/java/info/xiaomo/core/field/LoginField.java
new file mode 100644
index 00000000..e6ea5173
--- /dev/null
+++ b/core/src/main/java/info/xiaomo/core/field/LoginField.java
@@ -0,0 +1,62 @@
+package info.xiaomo.core.field;
+
+/**
+ * 把今天最好的表现当作明天最新的起点..~
+ * いま 最高の表現 として 明日最新の始発..~
+ * Today the best performance as tomorrow newest starter!
+
+ *
+ * @author : xiaomo
+ * github: https://github.com/houko
+ * email: xiaomo@xiaomo.info(83387856)
+ * Date: 2016/1/8 13:16
+ * Description: QQ登录常量类
+ * Copyright(©) 2015 by xiaomo.
+ */
+public interface LoginField {
+
+ String Q_Q_OPEN_ID = "openid";
+ String Q_Q_NICKNAME = "nickname";
+ String Q_Q_PHOTOURL = "figureurl_qq_2";
+ String Q_Q_GENDER = "gender";
+ String SINA_NICK_NAME = "screen_name";
+ String SINA_OPEN_ID = "id";
+ String SINA_HEAD_PHOTO = "avatar_large";
+ String GITHUB_NICK_NAME = "name";
+ String GITHUB_OPEN_ID = "id";
+ String GITHUB_HEAD_PHOTO = "avatar_url";
+ String GITHUB_EMAIL = "email";
+ String BAIDU_NICK_NAME = "name";
+ String BAIDU_OPEN_ID = "id";
+ String BAIDU_HEAD_PHOTO = "avatar_url";
+ String BAIDU_GENDER = "";
+
+ String OSC_NICK_NAME = "name";
+ String OSC_OPEN_ID = "id";
+ String OSC_HEAD_PHOTO = "avatar";
+ String OSC_EMAIL = "email";
+ String OSC_GENDER = "gender";
+
+ String RENREN_NICK_NAME = "name";
+ String RENREN_OPEN_ID = "id";
+ String RENREN_HEAD_PHOTO = "url";
+ String RENREN_EMAIL = "email";
+ String RENREN_GENDER = "gender";
+ String RENREN_PHOTO = "avatar";
+
+ String ID = "id";
+ String PASSWORD = "password";
+ String EMAIL = "email";
+ String EMAILVERIFY = "emailVerify";
+ String SEX = "gender";
+ String BIRTHDAY = "birthday";
+ String STATUS = "status";
+ String LAST_LOGIN_TIME = "lastLoginTime";
+
+ String TYPE = "type";
+ String CONTRIBUTION = "contribution";
+ String AUTHORITY = "authority";
+ String UPDATETIME = "updateTime";
+ String CREATETIME = "createTime";
+ String INDEX = "/index.html";
+}
diff --git a/core/src/main/java/info/xiaomo/core/field/LoginField.kt b/core/src/main/java/info/xiaomo/core/field/LoginField.kt
deleted file mode 100644
index ce517346..00000000
--- a/core/src/main/java/info/xiaomo/core/field/LoginField.kt
+++ /dev/null
@@ -1,64 +0,0 @@
-package info.xiaomo.core.field
-
-/**
- * 把今天最好的表现当作明天最新的起点..~
- * いま 最高の表現 として 明日最新の始発..~
- * Today the best performance as tomorrow newest starter!
- * Created by IntelliJ IDEA.
- *
- * @author : xiaomo
- * github: https://github.com/xiaomoinfo
- * email: xiaomo@xiaomo.info(83387856)
- * Date: 2016/1/8 13:16
- * Description: QQ登录常量类
- * Copyright(©) 2015 by xiaomo.
- */
-interface LoginField {
- companion object {
-
- val Q_Q_OPEN_ID = "openid"
- val Q_Q_NICKNAME = "nickname"
- val Q_Q_PHOTOURL = "figureurl_qq_2"
- val Q_Q_GENDER = "gender"
- val SINA_NICK_NAME = "screen_name"
- val SINA_OPEN_ID = "id"
- val SINA_HEAD_PHOTO = "avatar_large"
- val GITHUB_NICK_NAME = "name"
- val GITHUB_OPEN_ID = "id"
- val GITHUB_HEAD_PHOTO = "avatar_url"
- val GITHUB_EMAIL = "email"
- val BAIDU_NICK_NAME = "name"
- val BAIDU_OPEN_ID = "id"
- val BAIDU_HEAD_PHOTO = "avatar_url"
- val BAIDU_GENDER = ""
-
- val OSC_NICK_NAME = "name"
- val OSC_OPEN_ID = "id"
- val OSC_HEAD_PHOTO = "avatar"
- val OSC_EMAIL = "email"
- val OSC_GENDER = "gender"
-
- val RENREN_NICK_NAME = "name"
- val RENREN_OPEN_ID = "id"
- val RENREN_HEAD_PHOTO = "url"
- val RENREN_EMAIL = "email"
- val RENREN_GENDER = "gender"
- val RENREN_PHOTO = "avatar"
-
- val ID = "id"
- val PASSWORD = "password"
- val EMAIL = "email"
- val EMAILVERIFY = "emailVerify"
- val SEX = "gender"
- val BIRTHDAY = "birthday"
- val STATUS = "status"
- val LAST_LOGIN_TIME = "lastLoginTime"
-
- val TYPE = "type"
- val CONTRIBUTION = "contribution"
- val AUTHORITY = "authority"
- val UPDATETIME = "updateTime"
- val CREATETIME = "createTime"
- val INDEX = "/index.html"
- }
-}
diff --git a/core/src/main/java/info/xiaomo/core/filter/CorsFilter.kt b/core/src/main/java/info/xiaomo/core/filter/CorsFilter.java
similarity index 51%
rename from core/src/main/java/info/xiaomo/core/filter/CorsFilter.kt
rename to core/src/main/java/info/xiaomo/core/filter/CorsFilter.java
index 976cad33..75ccacf3 100644
--- a/core/src/main/java/info/xiaomo/core/filter/CorsFilter.kt
+++ b/core/src/main/java/info/xiaomo/core/filter/CorsFilter.java
@@ -1,26 +1,27 @@
-package info.xiaomo.core.filter
+package info.xiaomo.core.filter;
-import org.springframework.stereotype.Component
-import java.io.IOException
-import javax.servlet.*
-import javax.servlet.http.HttpServletResponse
+import org.springframework.stereotype.Component;
+
+import javax.servlet.*;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
/**
* 把今天最好的表现当作明天最新的起点..~
* いま 最高の表現 として 明日最新の始発..~
* Today the best performance as tomorrow newest starter!
- * Created by IntelliJ IDEA.
+
*
* @author : xiaomo
- * github: https://github.com/xiaomoinfo
+ * github: https://github.com/houko
* email: xiaomo@xiaomo.info
- *
+ *
* Date: 2016/4/1516:25
* Description:
* Copyright(©) 2015 by xiaomo.
- */
+ **/
@Component
-class CorsFilter : Filter {
+public class CorsFilter implements Filter {
/**
@@ -29,8 +30,8 @@ class CorsFilter : Filter {
* @param filterConfig filterConfig
* @throws ServletException ServletException
*/
- @Throws(ServletException::class)
- override fun init(filterConfig: FilterConfig) {
+ @Override
+ public void init(FilterConfig filterConfig) throws ServletException {
}
@@ -43,19 +44,21 @@ override fun init(filterConfig: FilterConfig) {
* @throws IOException IOException
* @throws ServletException ServletException
*/
- @Throws(IOException::class, ServletException::class)
- override fun doFilter(req: ServletRequest, res: ServletResponse, chain: FilterChain) {
- val response = res as HttpServletResponse
- response.setHeader("Access-Control-Allow-Origin", "*")
- response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE")
- response.setHeader("Access-Control-Max-Age", "3600")
- response.setHeader("Access-Control-Allow-Headers", "Origin, Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers, If-Modified-Since")
- chain.doFilter(req, res)
+ @Override
+ public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
+ HttpServletResponse response = (HttpServletResponse) res;
+ response.setHeader("Access-Control-Allow-Origin", "*");
+ response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
+ response.setHeader("Access-Control-Max-Age", "3600");
+ response.setHeader("Access-Control-Allow-Headers", "Origin, Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers, If-Modified-Since");
+ chain.doFilter(req, res);
}
/**
* 销毁对象
*/
- override fun destroy() {}
+ @Override
+ public void destroy() {
+ }
}
diff --git a/core/src/main/java/info/xiaomo/core/filter/CustomDateSerializerFilter.java b/core/src/main/java/info/xiaomo/core/filter/CustomDateSerializerFilter.java
new file mode 100644
index 00000000..e46cfb8f
--- /dev/null
+++ b/core/src/main/java/info/xiaomo/core/filter/CustomDateSerializerFilter.java
@@ -0,0 +1,22 @@
+package info.xiaomo.core.filter;
+
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.databind.JsonSerializer;
+import com.fasterxml.jackson.databind.SerializerProvider;
+import info.xiaomo.core.untils.TimeUtil;
+
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * @author : xiaomo
+ */
+public class CustomDateSerializerFilter extends JsonSerializer {
+
+ @Override
+ public void serialize(Date value, JsonGenerator jsonGenerator, SerializerProvider provider) throws IOException {
+ SimpleDateFormat sdf = new SimpleDateFormat(TimeUtil.DEFAULT_FORMAT2);
+ jsonGenerator.writeString(sdf.format(value));
+ }
+}
\ No newline at end of file
diff --git a/core/src/main/java/info/xiaomo/core/filter/CustomDateSerializerFilter.kt b/core/src/main/java/info/xiaomo/core/filter/CustomDateSerializerFilter.kt
deleted file mode 100644
index 88be9299..00000000
--- a/core/src/main/java/info/xiaomo/core/filter/CustomDateSerializerFilter.kt
+++ /dev/null
@@ -1,21 +0,0 @@
-package info.xiaomo.core.filter
-
-import com.fasterxml.jackson.core.JsonGenerator
-import com.fasterxml.jackson.databind.JsonSerializer
-import com.fasterxml.jackson.databind.SerializerProvider
-import info.xiaomo.core.untils.TimeUtil
-import java.io.IOException
-import java.text.SimpleDateFormat
-import java.util.*
-
-/**
- * @author : xiaomo
- */
-class CustomDateSerializerFilter : JsonSerializer() {
-
- @Throws(IOException::class)
- override fun serialize(value: Date, jsonGenerator: JsonGenerator, provider: SerializerProvider) {
- val sdf = SimpleDateFormat(TimeUtil.DEFAULT_FORMAT2)
- jsonGenerator.writeString(sdf.format(value))
- }
-}
\ No newline at end of file
diff --git a/core/src/main/java/info/xiaomo/core/untils/AuthUtil.java b/core/src/main/java/info/xiaomo/core/untils/AuthUtil.java
new file mode 100644
index 00000000..670f0d70
--- /dev/null
+++ b/core/src/main/java/info/xiaomo/core/untils/AuthUtil.java
@@ -0,0 +1,25 @@
+package info.xiaomo.core.untils;
+
+import javax.servlet.http.HttpSession;
+
+/**
+ * 把今天最好的表现当作明天最新的起点..~
+ * いま 最高の表現 として 明日最新の始発..~
+ * Today the best performance as tomorrow newest starter!
+
+ *
+ * @author : xiaomo
+ * github: https://github.com/houko
+ * @email: xiaomo@xiaomo.info
+ *
+ * Date: 2016/11/31 9:50
+ * Copyright(©) 2015 by xiaomo.
+ **/
+
+public class AuthUtil {
+ public static boolean isAuthorized(HttpSession session) {
+ String currentUser = (String) session.getAttribute("currentUser");
+ return !(currentUser == null || currentUser.isEmpty());
+ }
+
+}
diff --git a/core/src/main/java/info/xiaomo/core/untils/AuthUtil.kt b/core/src/main/java/info/xiaomo/core/untils/AuthUtil.kt
deleted file mode 100644
index 57635071..00000000
--- a/core/src/main/java/info/xiaomo/core/untils/AuthUtil.kt
+++ /dev/null
@@ -1,25 +0,0 @@
-package info.xiaomo.core.untils
-
-import javax.servlet.http.HttpSession
-
-/**
- * 把今天最好的表现当作明天最新的起点..~
- * いま 最高の表現 として 明日最新の始発..~
- * Today the best performance as tomorrow newest starter!
- * Created by IntelliJ IDEA.
- *
- * @author : xiaomo
- * github: https://github.com/xiaomoinfo
- * @email: xiaomo@xiaomo.info
- *
- * Date: 2016/11/31 9:50
- * Copyright(©) 2015 by xiaomo.
- */
-
-object AuthUtil {
- fun isAuthorized(session: HttpSession): Boolean {
- val currentUser = session.getAttribute("currentUser") as String
- return !(currentUser.isEmpty())
- }
-
-}
diff --git a/core/src/main/java/info/xiaomo/core/untils/CastUtil.java b/core/src/main/java/info/xiaomo/core/untils/CastUtil.java
new file mode 100644
index 00000000..a3c19f4c
--- /dev/null
+++ b/core/src/main/java/info/xiaomo/core/untils/CastUtil.java
@@ -0,0 +1,352 @@
+package info.xiaomo.core.untils;
+
+import java.io.*;
+import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Iterator;
+
+/**
+ * 把今天最好的表现当作明天最新的起点..~
+ * いま 最高の表現 として 明日最新の始発..~
+ * Today the best performance as tomorrow newest starter!
+
+ *
+ * @author : xiaomo
+ * github: https://github.com/houko
+ * email: xiaomo@xiaomo.info
+ *
+ * Date: 2016/11/22 14:55
+ * Copyright(©) 2015 by xiaomo.
+ **/
+
+public class CastUtil {
+ protected static final ByteArrayOutputStream OUT = new ByteArrayOutputStream();
+ protected static ObjectOutputStream oos;
+
+ public CastUtil() {
+ }
+
+ public static int toInteger(Object str) {
+ return str == null ? 0 : str instanceof Number ? ((Number) str).intValue() : toInteger(str.toString());
+ }
+
+ public static double toDouble(Object number) {
+ if (number == null) {
+ return 0.0D;
+ } else if (number instanceof Number) {
+ return ((Number) number).doubleValue();
+ } else if (number instanceof String) {
+ String str = (String) number;
+ return isNumeric(str) > 0 ? Double.valueOf(str) : 0.0D;
+ } else {
+ return 0.0D;
+ }
+ }
+
+ public static long toLong(Object number) {
+ if (number == null) {
+ return 0L;
+ } else if (number instanceof Number) {
+ return ((Number) number).longValue();
+ } else if (number instanceof String) {
+ String str = (String) number;
+ int isNumber = isNumeric(str);
+ return isNumber == 1 ? Long.parseLong(str) : (isNumber == 2 ? Double.valueOf(str).longValue() : 0L);
+ } else {
+ return 0L;
+ }
+ }
+
+ public static int toInteger(String str) {
+ if (str == null) {
+ return 0;
+ } else {
+ str = str.trim();
+ if (str.length() == 0) {
+ return 0;
+ } else {
+ int i = isNumeric(str);
+ return i == 1 ? Integer.parseInt(str) : (i == 2 ? Double.valueOf(str).intValue() : 0);
+ }
+ }
+ }
+
+ public static int isNumeric(String str) {
+ if (str == null) {
+ return 0;
+ } else {
+ boolean isdouble = false;
+ boolean hasE = false;
+ int i = str.length();
+
+ while (true) {
+ while (true) {
+ char c;
+ do {
+ --i;
+ if (i < 0) {
+ if (isdouble) {
+ return 2;
+ }
+
+ return 1;
+ }
+
+ c = str.charAt(i);
+ } while (i == 0 && c == 45);
+
+ if (c == 46) {
+ if (isdouble) {
+ return 0;
+ }
+
+ isdouble = true;
+ } else if (c != 69 && c != 101) {
+ if (!Character.isDigit(str.charAt(i))) {
+ return 0;
+ }
+ } else {
+ if (hasE) {
+ return 0;
+ }
+
+ hasE = true;
+ }
+ }
+ }
+ }
+ }
+
+ public static HashMap copyMap(HashMap map) {
+ HashMap newmap = new HashMap<>(10);
+
+ for (Object key : map.keySet()) {
+ newmap.put(key, map.get(key));
+ }
+
+ return newmap;
+ }
+
+ public static void destroy(Hashtable map) {
+ for (Iterator it = map.keySet().iterator(); it.hasNext(); it.remove()) {
+ Object key = it.next();
+ Object value = map.get(key);
+ if (value instanceof HashMap) {
+ HashMap valueMap = (HashMap) value;
+ destroy(valueMap);
+ }
+ }
+
+ }
+
+ public static void destroy(HashMap map) {
+ for (Iterator keyit = map.keySet().iterator(); keyit.hasNext(); keyit.remove()) {
+ Object key = keyit.next();
+ Object value = map.get(key);
+ if (value instanceof HashMap) {
+ HashMap valueMap = (HashMap) value;
+ destroy(valueMap);
+ }
+ }
+
+ }
+
+ public static String objectToString(Object obj) {
+ if (obj.getClass().equals(String.class)) {
+ return obj.toString();
+ } else {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ try {
+ ObjectOutputStream e = new ObjectOutputStream(out);
+ e.writeObject(obj);
+ byte[] bytes = out.toByteArray();
+ return new String(bytes, StandardCharsets.ISO_8859_1);
+ } catch (IOException var4) {
+ var4.printStackTrace();
+ return null;
+ }
+ }
+ }
+
+ public static Object stringToObject(String string) {
+ try {
+ byte[] e = string.getBytes(StandardCharsets.ISO_8859_1);
+ ByteArrayInputStream in = new ByteArrayInputStream(e);
+ ObjectInputStream ois = new ObjectInputStream(in);
+ return ois.readObject();
+ } catch (IOException | ClassNotFoundException var4) {
+ var4.printStackTrace();
+ }
+
+ return null;
+ }
+
+ public static int bytesToInt(byte[] bytes) {
+ byte length = 4;
+ int intValue = 0;
+
+ for (int i = length - 1; i >= 0; --i) {
+ int offset = i * 8;
+ intValue |= (bytes[i] & 255) << offset;
+ }
+
+ return intValue;
+ }
+
+ public static Object bytesToObject(byte[] bytes) {
+ try {
+ ByteArrayInputStream e = new ByteArrayInputStream(bytes);
+ ObjectInputStream ois = new ObjectInputStream(e);
+ return ois.readObject();
+ } catch (IOException | ClassNotFoundException var3) {
+ var3.printStackTrace();
+ }
+
+ return null;
+ }
+
+ public static byte[] objectToBytes(Object obj) throws IOException {
+ OUT.reset();
+
+ byte[] var2;
+ try {
+ if (oos == null) {
+ oos = new ObjectOutputStream(OUT);
+ } else {
+ oos.reset();
+ }
+
+ oos.writeObject(obj);
+ var2 = OUT.toByteArray();
+ } finally {
+ OUT.close();
+ }
+
+ return var2;
+ }
+
+ public static byte[] stringToBytes(String str) {
+ StringBuffer sb = new StringBuffer(str);
+ char c = sb.charAt(0);
+ ByteBuffer buffer = ByteBuffer.allocate(sb.length() * 2);
+ int index = 0;
+
+ while (index < sb.length()) {
+ buffer.putChar(sb.charAt(index++));
+ }
+
+ return buffer.array();
+ }
+
+ public static String bytesToString(byte[] bytes) {
+ ByteBuffer buffer = ByteBuffer.wrap(bytes);
+ StringBuffer sb = new StringBuffer();
+
+ while (buffer.hasRemaining()) {
+ sb.append(buffer.getChar());
+ }
+
+ return sb.toString();
+ }
+
+ public static long combineInt2Long(int low, int high) {
+ return (long) low & 4294967295L | (long) high << 32 & -4294967296L;
+ }
+
+ public static int[] separateLong2int(Long val) {
+ return new int[]{(int) (4294967295L & val), (int) ((-4294967296L & val) >> 32)};
+ }
+
+ public static int getLongLowInt(Long val) {
+ return val == null ? 0 : (int) (4294967295L & val);
+ }
+
+ public static int getLongHighInt(Long val) {
+ return val == null ? 0 : (int) ((-4294967296L & val) >> 32);
+ }
+
+ public static boolean isIntInList(int i, int[] list) {
+ for (int aList : list) {
+ if (aList == i) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public static int[] stringToInts(String str, String regex) {
+ String[] arr = str.split(regex);
+ int length = arr.length;
+ int[] ret = new int[length];
+
+ for (int i = 0; i < length; ++i) {
+ ret[i] = toInteger(arr[i]);
+ }
+
+ return ret;
+ }
+
+ public static String bytesToHexString(byte[] src) {
+ StringBuilder stringBuilder = new StringBuilder();
+ if (src != null && src.length > 0) {
+ for (byte aSrc : src) {
+ int v = aSrc & 255;
+ String hv = Integer.toHexString(v);
+ if (hv.length() < 2) {
+ stringBuilder.append(0);
+ }
+
+ stringBuilder.append(hv);
+ }
+
+ return stringBuilder.toString();
+ } else {
+ return null;
+ }
+ }
+
+ public static byte[] hexStringToBytes(String hexString) {
+ if (hexString != null && !"".equals(hexString)) {
+ hexString = hexString.toUpperCase();
+ int length = hexString.length() / 2;
+ char[] hexChars = hexString.toCharArray();
+ byte[] d = new byte[length];
+
+ for (int i = 0; i < length; ++i) {
+ int pos = i * 2;
+ d[i] = (byte) (charToByte(hexChars[pos]) << 4 | charToByte(hexChars[pos + 1]));
+ }
+
+ return d;
+ } else {
+ return null;
+ }
+ }
+
+ public static double strToDouble(String str) {
+ if (str != null && !str.isEmpty()) {
+ int len = str.length();
+ int p = str.indexOf(37);
+ return p == len - 1 ? Double.valueOf(str.substring(0, len - 1)) / 100.0D : (p > -1 ? 0.0D : ("true".equals(str) ? 1.0D : toDouble(str)));
+ } else {
+ return 0.0D;
+ }
+ }
+
+ private static byte charToByte(char c) {
+ return (byte) "0123456789ABCDEF".indexOf(c);
+ }
+
+ public static String cacheString(int i) {
+ return String.valueOf(i);
+ }
+
+ public static void main(String[] args) {
+ System.out.println(toInteger("2.147483647E9"));
+ }
+
+}
diff --git a/core/src/main/java/info/xiaomo/core/untils/CastUtil.kt b/core/src/main/java/info/xiaomo/core/untils/CastUtil.kt
deleted file mode 100644
index d89a2a9e..00000000
--- a/core/src/main/java/info/xiaomo/core/untils/CastUtil.kt
+++ /dev/null
@@ -1,290 +0,0 @@
-package info.xiaomo.core.untils
-
-import java.io.*
-import java.nio.ByteBuffer
-import java.util.*
-
-/**
- * 把今天最好的表现当作明天最新的起点..~
- * いま 最高の表現 として 明日最新の始発..~
- * Today the best performance as tomorrow newest starter!
- * Created by IntelliJ IDEA.
- *
- * @author : xiaomo
- * github: https://github.com/xiaomoinfo
- * email: xiaomo@xiaomo.info
- *
- * Date: 2016/11/22 14:55
- * Copyright(©) 2015 by xiaomo.
- */
-
-class CastUtil {
- companion object {
- protected val OUT = ByteArrayOutputStream()
- protected var oos: ObjectOutputStream? = null
-
- fun toInteger(str: Any?): Int {
- return if (str == null) 0 else (str as? Number)?.toInt() ?: toInteger(str.toString())
- }
-
- fun toDouble(number: Any?): Double {
- if (number == null) {
- return 0.0
- } else if (number is Number) {
- return number.toDouble()
- } else if (number is String) {
- val str = number as String?
- return if (isNumeric(str) > 0) java.lang.Double.valueOf(str!!) else 0.0
- } else {
- return 0.0
- }
- }
-
- fun toLong(number: Any?): Long {
- if (number == null) {
- return 0L
- } else if (number is Number) {
- return number.toLong()
- } else if (number is String) {
- val str = number as String?
- val isNumber = isNumeric(str)
- return if (isNumber == 1) java.lang.Long.parseLong(str!!) else if (isNumber == 2) java.lang.Double.valueOf(str!!).toLong() else 0L
- } else {
- return 0L
- }
- }
-
- fun toInteger(str: String?): Int {
- var str = str
- if (str == null) {
- return 0
- } else {
- str = str.trim { it <= ' ' }
- if (str.length == 0) {
- return 0
- } else {
- val i = isNumeric(str)
- return if (i == 1) Integer.parseInt(str) else if (i == 2) java.lang.Double.valueOf(str).toInt() else 0
- }
- }
- }
-
- fun isNumeric(str: String?): Int {
- if (str == null) {
- return 0
- } else {
- var isdouble = false
- var hasE = false
- var i = str.length
-
- while (true) {
- while (true) {
- var c: Char
- do {
- --i
- if (i < 0) {
- return if (isdouble) {
- 2
- } else 1
-
- }
-
- c = str[i]
- } while (i == 0 && c.toInt() == 45)
-
- if (c.toInt() == 46) {
- if (isdouble) {
- return 0
- }
-
- isdouble = true
- } else if (c.toInt() != 69 && c.toInt() != 101) {
- if (!Character.isDigit(str[i])) {
- return 0
- }
- } else {
- if (hasE) {
- return 0
- }
-
- hasE = true
- }
- }
- }
- }
- }
-
- fun copyMap(map: HashMap<*, *>): HashMap<*, *> {
- val newmap = HashMap(10)
-
- for (key in map.keys) {
- newmap.put(key, map.get(key)!!)
- }
-
- return newmap
- }
-
- fun destroy(map: Hashtable<*, *>) {
- val it = map.keys.iterator()
- while (it.hasNext()) {
- val key = it.next()
- val value = map[key]
- if (value is HashMap<*, *>) {
- destroy(value)
- }
- it.remove()
- }
-
- }
-
- fun destroy(map: HashMap<*, *>) {
- val keyit = map.keys.iterator()
- while (keyit.hasNext()) {
- val key = keyit.next()
- val value = map[key]
- if (value is HashMap<*, *>) {
- destroy(value)
- }
- keyit.remove()
- }
-
- }
-
- fun objectToString(obj: Any): String? {
- if (obj.javaClass == String::class.java) {
- return obj.toString()
- } else {
- val out = ByteArrayOutputStream()
-
- try {
- val e = ObjectOutputStream(out)
- e.writeObject(obj)
- val bytes = out.toByteArray()
- return String(bytes)
- } catch (var4: IOException) {
- var4.printStackTrace()
- return null
- }
-
- }
- }
-
- fun stringToObject(string: String): Any? {
- try {
- val e = string.toByteArray(charset("ISO-8859-1"))
- val `in` = ByteArrayInputStream(e)
- val ois = ObjectInputStream(`in`)
- return ois.readObject()
- } catch (var4: IOException) {
- var4.printStackTrace()
- } catch (var4: ClassNotFoundException) {
- var4.printStackTrace()
- }
-
- return null
- }
-
- fun bytesToObject(bytes: ByteArray): Any? {
- try {
- val e = ByteArrayInputStream(bytes)
- val ois = ObjectInputStream(e)
- return ois.readObject()
- } catch (var3: IOException) {
- var3.printStackTrace()
- } catch (var3: ClassNotFoundException) {
- var3.printStackTrace()
- }
-
- return null
- }
-
- @Throws(IOException::class)
- fun objectToBytes(obj: Any): ByteArray {
- OUT.reset()
-
- val var2: ByteArray
- try {
- if (oos == null) {
- oos = ObjectOutputStream(OUT)
- } else {
- oos!!.reset()
- }
-
- oos!!.writeObject(obj)
- var2 = OUT.toByteArray()
- } finally {
- OUT.close()
- }
-
- return var2
- }
-
- fun stringToBytes(str: String): ByteArray {
- val sb = StringBuffer(str)
- val c = sb[0]
- val buffer = ByteBuffer.allocate(sb.length * 2)
- var index = 0
-
- while (index < sb.length) {
- buffer.putChar(sb[index++])
- }
-
- return buffer.array()
- }
-
- fun bytesToString(bytes: ByteArray): String {
- val buffer = ByteBuffer.wrap(bytes)
- val sb = StringBuffer()
-
- while (buffer.hasRemaining()) {
- sb.append(buffer.char)
- }
-
- return sb.toString()
- }
-
- fun combineInt2Long(low: Int, high: Int): Long {
- return low.toLong() and 4294967295L or (high.toLong() shl 32 and -4294967296L)
- }
-
- fun getLongLowInt(`val`: Long?): Int {
- return if (`val` == null) 0 else (4294967295L and `val`).toInt()
- }
-
- fun getLongHighInt(`val`: Long?): Int {
- return if (`val` == null) 0 else (-4294967296L and `val` shr 32).toInt()
- }
-
- fun isIntInList(i: Int, list: IntArray): Boolean {
- for (aList in list) {
- if (aList == i) {
- return true
- }
- }
-
- return false
- }
-
- fun stringToInts(str: String, regex: String): IntArray {
- val arr = str.split(regex.toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
- val length = arr.size
- val ret = IntArray(length)
-
- for (i in 0 until length) {
- ret[i] = toInteger(arr[i])
- }
-
- return ret
- }
-
- fun cacheString(i: Int): String {
- return i.toString()
- }
-
- @JvmStatic
- fun main(args: Array) {
- println(toInteger("2.147483647E9"))
- }
- }
-
-}
diff --git a/core/src/main/java/info/xiaomo/core/untils/CharUtil.java b/core/src/main/java/info/xiaomo/core/untils/CharUtil.java
new file mode 100644
index 00000000..17b3e973
--- /dev/null
+++ b/core/src/main/java/info/xiaomo/core/untils/CharUtil.java
@@ -0,0 +1,181 @@
+package info.xiaomo.core.untils;
+
+import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
+import java.util.Objects;
+
+/**
+ * Title:字符编码工具类
+ *
+ * @author : xiaomo
+ * @version 1.0
+ */
+public class CharUtil {
+
+ /**
+ * 转换编码 ISO-8859-1到GB2312
+ */
+ public static String iso2gb(String text) {
+ String result;
+ try {
+ result = new String(text.getBytes(StandardCharsets.ISO_8859_1), "GB2312");
+ } catch (UnsupportedEncodingException ex) {
+ result = ex.toString();
+ }
+ return result;
+ }
+
+ /**
+ * 转换编码 GB2312到ISO-8859-1
+ */
+ public static String gb2iso(String text) {
+ String result = "";
+ try {
+ result = new String(text.getBytes("GB2312"), StandardCharsets.ISO_8859_1);
+ } catch (UnsupportedEncodingException ex) {
+ ex.printStackTrace();
+ }
+ return result;
+ }
+
+ /**
+ * Utf8URL编码
+ */
+ public static String utf8urlencode(String text) {
+ StringBuilder result = new StringBuilder();
+ for (int i = 0; i < text.length(); i++) {
+
+ char c = text.charAt(i);
+ if (c <= 255) {
+ result.append(c);
+ } else {
+
+ byte[] b = new byte[0];
+ try {
+ b = Character.toString(c).getBytes(StandardCharsets.UTF_8);
+ } catch (Exception ignored) {
+ }
+
+ for (byte aB : b) {
+ int k = aB;
+ if (k < 0) {
+ k += 256;
+ }
+ result.append("%").append(Integer.toHexString(k).toUpperCase());
+ }
+
+ }
+ }
+ return result.toString();
+ }
+
+ /**
+ * Utf8URL解码
+ */
+ public static String utf8urldecode(String text) {
+ StringBuilder result = new StringBuilder();
+ int p;
+ if (text != null && text.length() > 0) {
+ text = text.toLowerCase();
+ p = text.indexOf("%e");
+ if (p == -1) {
+ return text;
+ }
+ while (p != -1) {
+ result.append(text, 0, p);
+ text = text.substring(p);
+ if (Objects.equals(text, "") || text.length() < 9) {
+ return result.toString();
+ }
+ result.append(codetoword(text.substring(0, 9)));
+ text = text.substring(9);
+ p = text.indexOf("%e");
+ }
+ }
+ return result + text;
+ }
+
+ /**
+ * utf8URL编码转字符
+ */
+ private static String codetoword(String text) {
+ String result;
+ if (utf8codecheck(text)) {
+ byte[] code = new byte[3];
+ code[0] = (byte) (Integer.parseInt(text.substring(1, 3), 16) - 256);
+ code[1] = (byte) (Integer.parseInt(text.substring(4, 6), 16) - 256);
+ code[2] = (byte) (Integer.parseInt(text.substring(7, 9), 16) - 256);
+ result = new String(code, StandardCharsets.UTF_8);
+ } else {
+ result = text;
+ }
+ return result;
+ }
+
+ /**
+ * 编码是否有效
+ */
+ private static boolean utf8codecheck(String text) {
+ String sign = "";
+ String prefix = "%e";
+ if (text.startsWith(prefix)) {
+ for (int p = 0; p != -1; ) {
+ p = text.indexOf("%", p);
+ if (p != -1) {
+ p++;
+ }
+ sign += p;
+ }
+ }
+ return "147-1".equals(sign);
+ }
+
+ /**
+ * 判断是否Utf8Url编码
+ */
+ public static boolean isUtf8Url(String text) {
+ text = text.toLowerCase();
+ int p = text.indexOf("%");
+ int nine = 9;
+ if (p != -1 && text.length() - p > nine) {
+ text = text.substring(p, p + nine);
+ }
+ return utf8codecheck(text);
+ }
+
+ /**
+ * 进行字符规格化(全角转半角,大写转小写处理)
+ *
+ * @return char
+ */
+ public static char regularize(char input) {
+ if (input == 12288) {
+ input = (char) 32;
+ } else if (input > 65280 && input < 65375) {
+ input = (char) (input - 65248);
+ } else {
+ char a = 'A';
+ char z = 'Z';
+ if (input >= a && input <= z) {
+ input += 32;
+ }
+ }
+ return input;
+ }
+
+ public static void main(String[] args) {
+ String url;
+ System.out.println(utf8urlencode("小莫"));
+ System.out.println(iso2gb("小莫"));
+ System.out.println(gb2iso("小莫"));
+ url = "http://www.google.com/search?hl=zh-CN&newwindow=1&q=%E4%B8%AD%E5%9B%BD%E5%A4%A7%E7%99%BE%E7%A7%91%E5%9C%A8%E7%BA%BF%E5%85%A8%E6%96%87%E6%A3%80%E7%B4%A2&btnG=%E6%90%9C%E7%B4%A2&lr=";
+ if (CharUtil.isUtf8Url(url)) {
+ System.out.println(CharUtil.utf8urldecode(url));
+ }
+ url = "http://www.baidu.com/baidu?word=%D6%D0%B9%FA%B4%F3%B0%D9%BF%C6%D4%DA%CF%DF%C8%AB%CE%C4%BC%EC%CB%F7&tn=myie2dg";
+ if (CharUtil.isUtf8Url(url)) {
+ System.out.println(CharUtil.utf8urldecode(url));
+ }
+ }
+
+}
diff --git a/core/src/main/java/info/xiaomo/core/untils/CharUtil.kt b/core/src/main/java/info/xiaomo/core/untils/CharUtil.kt
deleted file mode 100644
index a2070ab2..00000000
--- a/core/src/main/java/info/xiaomo/core/untils/CharUtil.kt
+++ /dev/null
@@ -1,191 +0,0 @@
-package info.xiaomo.core.untils
-
-import java.io.UnsupportedEncodingException
-
-/**
- *
- * Title:字符编码工具类
- *
- * @author : xiaomo
- * @version 1.0
- */
-object CharUtil {
-
- /**
- * 转换编码 ISO-8859-1到GB2312
- */
- fun iso2gb(text: String): String {
- var result: String
- try {
- result = String(text.toByteArray(charset("ISO-8859-1")))
- } catch (ex: UnsupportedEncodingException) {
- result = ex.toString()
- }
-
- return result
- }
-
- /**
- * 转换编码 GB2312到ISO-8859-1
- */
- fun gb2iso(text: String): String {
- var result = ""
- try {
- result = String(text.toByteArray(charset("GB2312")))
- } catch (ex: UnsupportedEncodingException) {
- ex.printStackTrace()
- }
-
- return result
- }
-
- /**
- * Utf8URL编码
- */
- fun utf8urlencode(text: String): String {
- val result = StringBuilder()
- for (i in 0 until text.length) {
-
- val c = text[i]
- if (c.toInt() <= 255) {
- result.append(c)
- } else {
-
- var b = ByteArray(0)
- try {
- b = Character.toString(c).toByteArray(charset("UTF-8"))
- } catch (ignored: Exception) {
- }
-
- for (aB in b) {
- var k = aB.toInt()
- if (k < 0) {
- k += 256
- }
- result.append("%").append(Integer.toHexString(k).toUpperCase())
- }
-
- }
- }
- return result.toString()
- }
-
- /**
- * Utf8URL解码
- */
- fun utf8urldecode(text: String?): String {
- var text = text
- var result = ""
- var p: Int
- if (text != null && text.length > 0) {
- text = text.toLowerCase()
- p = text.indexOf("%e")
- if (p == -1) {
- return text
- }
- while (p != -1) {
- result += text!!.substring(0, p)
- text = text.substring(p, text.length)
- if (text == "" || text.length < 9) {
- return result
- }
- result += codetoword(text.substring(0, 9))
- text = text.substring(9, text.length)
- p = text.indexOf("%e")
- }
- }
- return result + text!!
- }
-
- /**
- * utf8URL编码转字符
- */
- private fun codetoword(text: String): String? {
- var result: String?
- if (utf8codecheck(text)) {
- val code = ByteArray(3)
- code[0] = (Integer.parseInt(text.substring(1, 3), 16) - 256).toByte()
- code[1] = (Integer.parseInt(text.substring(4, 6), 16) - 256).toByte()
- code[2] = (Integer.parseInt(text.substring(7, 9), 16) - 256).toByte()
- try {
- result = String(code)
- } catch (ex: UnsupportedEncodingException) {
- result = null
- }
-
- } else {
- result = text
- }
- return result
- }
-
- /**
- * 编码是否有效
- */
- private fun utf8codecheck(text: String): Boolean {
- var sign = ""
- val prefix = "%e"
- if (text.startsWith(prefix)) {
- var p = 0
- while (p != -1) {
- p = text.indexOf("%", p)
- if (p != -1) {
- p++
- }
- sign += p
- }
- }
- return "147-1" == sign
- }
-
- /**
- * 判断是否Utf8Url编码
- */
- fun isUtf8Url(text: String): Boolean {
- var text = text
- text = text.toLowerCase()
- val p = text.indexOf("%")
- val nine = 9
- if (p != -1 && text.length - p > nine) {
- text = text.substring(p, p + nine)
- }
- return utf8codecheck(text)
- }
-
- /**
- * 进行字符规格化(全角转半角,大写转小写处理)
- *
- * @return char
- */
- fun regularize(input: Char): Char {
- var input = input
- if (input.toInt() == 12288) {
- input = 32.toChar()
- } else if (input.toInt() > 65280 && input.toInt() < 65375) {
- input = (input.toInt() - 65248).toChar()
- } else {
- val a = 'A'
- val z = 'Z'
- if (input >= a && input <= z) {
- input += 32.toChar().toInt()
- }
- }
- return input
- }
-
- @JvmStatic
- fun main(args: Array) {
- var url = "http://www.google.com/search?hl=zh-CN&newwindow=1&q=%E4%B8%AD%E5%9B%BD%E5%A4%A7%E7%99%BE%E7%A7%91%E5%9C%A8%E7%BA%BF%E5%85%A8%E6%96%87%E6%A3%80%E7%B4%A2&btnG=%E6%90%9C%E7%B4%A2&lr="
- println(utf8urlencode("小莫"))
- println(iso2gb("小莫"))
- println(gb2iso("小莫"))
- if (CharUtil.isUtf8Url(url)) {
- println(CharUtil.utf8urldecode(url))
- }
- url = "http://www.baidu.com/baidu?word=%D6%D0%B9%FA%B4%F3%B0%D9%BF%C6%D4%DA%CF%DF%C8%AB%CE%C4%BC%EC%CB%F7&tn=myie2dg"
- if (CharUtil.isUtf8Url(url)) {
- println(CharUtil.utf8urldecode(url))
- }
- }
-
-}
diff --git a/core/src/main/java/info/xiaomo/core/untils/DownUtil.java b/core/src/main/java/info/xiaomo/core/untils/DownUtil.java
new file mode 100644
index 00000000..3f6d64e0
--- /dev/null
+++ b/core/src/main/java/info/xiaomo/core/untils/DownUtil.java
@@ -0,0 +1,83 @@
+package info.xiaomo.core.untils;
+
+import lombok.extern.slf4j.Slf4j;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URL;
+import java.net.URLConnection;
+
+/**
+ * @author : xiaomo (https://xiaomo.info) (https://github.com/houko)
+ * @created : 2016/12/26 13:25
+ */
+@Slf4j
+public class DownUtil {
+
+ public static void download(String urlString) throws Exception {
+ File file = new File(urlString);
+ String filename = file.getName();
+ // 构造URL
+ URL url = new URL(urlString);
+ // 打开连接
+ URLConnection con = url.openConnection();
+ // 输入流
+ InputStream is = con.getInputStream();
+ // 1K的数据缓冲
+ byte[] bs = new byte[1024];
+ // 读取到的数据长度
+ int len;
+ // 输出的文件流
+ OutputStream os = new FileOutputStream(filename);
+ // 开始读取
+ while ((len = is.read(bs)) != -1) {
+ os.write(bs, 0, len);
+ }
+ // 完毕,关闭所有链接
+ os.close();
+ is.close();
+ }
+
+
+ /**
+ * 下载图片
+ *
+ * @param urlString url
+ * @param filePath 存储路径 D:\MIR\config\data\
+ */
+ public static void download(String urlString, String filePath) throws Exception {
+ File file = new File(urlString);
+ String filename = file.getName();
+ // 构造URL
+ URL url = new URL(urlString);
+ // 打开连接
+ URLConnection con = url.openConnection();
+ // 输入流
+ InputStream is = con.getInputStream();
+ // 1K的数据缓冲
+ byte[] bs = new byte[1024];
+ // 读取到的数据长度
+ int len;
+ // 输出的文件流
+
+ File output = new File(filePath);
+ if (!output.exists()) {
+ boolean res = output.mkdir();
+ if (res) {
+ log.debug("{} 目录创建成功", filePath);
+ }
+ }
+
+ OutputStream os = new FileOutputStream(filePath + filename);
+ // 开始读取
+ while ((len = is.read(bs)) != -1) {
+ os.write(bs, 0, len);
+ }
+ // 完毕,关闭所有链接
+ os.close();
+ is.close();
+ }
+
+}
diff --git a/core/src/main/java/info/xiaomo/core/untils/DownUtil.kt b/core/src/main/java/info/xiaomo/core/untils/DownUtil.kt
deleted file mode 100644
index 549042d3..00000000
--- a/core/src/main/java/info/xiaomo/core/untils/DownUtil.kt
+++ /dev/null
@@ -1,79 +0,0 @@
-package info.xiaomo.core.untils
-
-import java.io.File
-import java.io.FileOutputStream
-import java.net.URL
-
-/**
- * @author : xiaomo (https://xiaomo.info) (https://github.com/xiaomoinfo)
- * @created : 2016/12/26 13:25
- */
-object DownUtil {
-
- @Throws(Exception::class)
- fun download(urlString: String) {
- val file = File(urlString)
- val filename = file.name
- // 构造URL
- val url = URL(urlString)
- // 打开连接
- val con = url.openConnection()
- // 输入流
- val `is` = con.getInputStream()
- // 1K的数据缓冲
- val bs = ByteArray(1024)
- // 读取到的数据长度
- val len = 0
- // 输出的文件流
- val os = FileOutputStream(filename)
- // 开始读取
- while ((`is`.read(bs)) != -1) {
- os.write(bs, 0, len)
- }
- // 完毕,关闭所有链接
- os.close()
- `is`.close()
- }
-
-
- /**
- * 下载图片
- *
- * @param urlString url
- * @param filePath 存储路径 D:\MIR\config\data\
- */
- @Throws(Exception::class)
- fun download(urlString: String, filePath: String) {
- val file = File(urlString)
- val filename = file.name
- // 构造URL
- val url = URL(urlString)
- // 打开连接
- val con = url.openConnection()
- // 输入流
- val `is` = con.getInputStream()
- // 1K的数据缓冲
- val bs = ByteArray(1024)
- // 读取到的数据长度
- var len = 0
- // 输出的文件流
-
- val output = File(filePath)
- if (!output.exists()) {
- val res = output.mkdir()
- if (res) {
- println("目录创建成功" + filePath)
- }
- }
-
- val os = FileOutputStream(filePath + filename)
- // 开始读取
- while ((`is`.read(bs)) != -1) {
- os.write(bs, 0, len)
- }
- // 完毕,关闭所有链接
- os.close()
- `is`.close()
- }
-
-}
diff --git a/core/src/main/java/info/xiaomo/core/untils/ExcelUtil.java b/core/src/main/java/info/xiaomo/core/untils/ExcelUtil.java
new file mode 100644
index 00000000..9a1738e3
--- /dev/null
+++ b/core/src/main/java/info/xiaomo/core/untils/ExcelUtil.java
@@ -0,0 +1,163 @@
+package info.xiaomo.core.untils;
+
+import org.apache.poi.hssf.usermodel.*;
+import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+
+import java.io.*;
+import java.text.DecimalFormat;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @author : xiaomo
+ */
+public class ExcelUtil {
+//
+// public static void main(String[] args) throws Exception {
+// List> listData = getListData("E:\\thinkpage_cities.xls", 1);
+// List list = new ArrayList<>();
+// for (List listDatum : listData) {
+// CountryModel model = new CountryModel();
+// model.setCityName(listDatum.get(0));
+// model.setCityNameEN(listDatum.get(1));
+// list.add(model);
+// }
+// System.out.println(list);
+// }
+
+ public static List> getListData(String path, int ignoreRows) throws IOException {
+ File file = new File(path);
+ String[][] result = getData(file, ignoreRows);
+ List> lists = new ArrayList<>();
+ for (String[] aResult : result) {
+ List list = new ArrayList<>();
+ for (String anAResult : aResult) {
+ if (!"".equals(anAResult)) {
+ list.add(anAResult);
+ }
+ }
+ lists.add(list);
+ }
+ return lists;
+ }
+
+ /**
+ * 读取Excel的内容,第一维数组存储的是一行中格列的值,二维数组存储的是多少个行
+ *
+ * @param file 读取数据的源Excel
+ * @param ignoreRows 读取数据忽略的行数,比喻行头不需要读入 忽略的行数为1
+ * @return 读出的Excel中数据的内容
+ * @throws FileNotFoundException
+ * @throws IOException
+ */
+ private static String[][] getData(File file, int ignoreRows)
+ throws IOException {
+ List result = new ArrayList<>();
+ int rowSize = 0;
+ BufferedInputStream in = new BufferedInputStream(new FileInputStream(
+ file));
+ // 打开HSSFWorkbook
+ POIFSFileSystem fs = new POIFSFileSystem(in);
+ HSSFWorkbook wb = new HSSFWorkbook(fs);
+ HSSFCell cell;
+ for (int sheetIndex = 0; sheetIndex < wb.getNumberOfSheets(); sheetIndex++) {
+ HSSFSheet st = wb.getSheetAt(sheetIndex);
+ // 第一行为标题,不取
+ for (int rowIndex = ignoreRows; rowIndex <= st.getLastRowNum(); rowIndex++) {
+ HSSFRow row = st.getRow(rowIndex);
+ if (row == null) {
+ continue;
+ }
+ int tempRowSize = row.getLastCellNum() + 1;
+ if (tempRowSize > rowSize) {
+ rowSize = tempRowSize;
+ }
+ String[] values = new String[rowSize];
+ Arrays.fill(values, "");
+ boolean hasValue = false;
+ for (int columnIndex = 0; columnIndex <= row.getLastCellNum(); columnIndex++) {
+ String value = "";
+ cell = row.getCell(columnIndex);
+ if (cell != null) {
+ switch (cell.getCellType()) {
+ case HSSFCell.CELL_TYPE_STRING:
+ value = cell.getStringCellValue();
+ break;
+ case HSSFCell.CELL_TYPE_NUMERIC:
+ if (HSSFDateUtil.isCellDateFormatted(cell)) {
+ Date date = cell.getDateCellValue();
+ if (date != null) {
+ value = new SimpleDateFormat("yyyy-MM-dd")
+ .format(date);
+ } else {
+ value = "";
+ }
+ } else {
+ value = new DecimalFormat("0").format(cell
+ .getNumericCellValue());
+ }
+ break;
+ case HSSFCell.CELL_TYPE_FORMULA:
+ // 导入时如果为公式生成的数据则无值
+ if (!"".equals(cell.getStringCellValue())) {
+ value = cell.getStringCellValue();
+ } else {
+ value = cell.getNumericCellValue() + "";
+ }
+ break;
+ case HSSFCell.CELL_TYPE_BLANK:
+ break;
+ case HSSFCell.CELL_TYPE_ERROR:
+ value = "";
+ break;
+ case HSSFCell.CELL_TYPE_BOOLEAN:
+ value = (cell.getBooleanCellValue() ? "Y"
+ : "N");
+ break;
+ default:
+ value = "";
+ }
+ }
+ if (columnIndex == 0 && "".equals(value.trim())) {
+ break;
+ }
+ values[columnIndex] = rightTrim(value);
+ hasValue = true;
+ }
+
+ if (hasValue) {
+ result.add(values);
+ }
+ }
+ }
+ in.close();
+ String[][] returnArray = new String[result.size()][rowSize];
+ for (int i = 0; i < returnArray.length; i++) {
+ returnArray[i] = result.get(i);
+ }
+ return returnArray;
+ }
+
+ /**
+ * 去掉字符串右边的空格
+ *
+ * @param str 要处理的字符串
+ * @return 处理后的字符串
+ */
+ public static String rightTrim(String str) {
+ if (str == null) {
+ return "";
+ }
+ int length = str.length();
+ for (int i = length - 1; i >= 0; i--) {
+ if (str.charAt(i) != 0x20) {
+ break;
+ }
+ length--;
+ }
+ return str.substring(0, length);
+ }
+}
\ No newline at end of file
diff --git a/core/src/main/java/info/xiaomo/core/untils/FileUtil.java b/core/src/main/java/info/xiaomo/core/untils/FileUtil.java
new file mode 100644
index 00000000..d0297bf5
--- /dev/null
+++ b/core/src/main/java/info/xiaomo/core/untils/FileUtil.java
@@ -0,0 +1,844 @@
+package info.xiaomo.core.untils;
+
+import info.xiaomo.core.constant.FileConst;
+import info.xiaomo.core.constant.SymbolConst;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.*;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 此类中封装一些常用的文件操作。
+ * 所有方法都是静态方法,不需要生成此类的实例,
+ * 为避免生成此类的实例,构造方法被申明为private类型的。
+ *
+ * @author : xiaomo
+ * @since 1.0
+ */
+
+public class FileUtil {
+ /**
+ * Buffer size when reading from input stream.
+ *
+ * @since ostermillerutils 1.00.00
+ */
+ private final static int BUFFER_SIZE = 1024;
+
+
+ /**
+ * 私有构造方法,防止类的实例化,因为工具类不需要实例化。
+ */
+ private FileUtil() {
+
+ }
+
+ /**
+ * 修改文件的最后访问时间。
+ * 如果文件不存在则创建该文件。
+ * 目前这个方法的行为方式还不稳定,主要是方法有些信息输出,这些信息输出是否保留还在考虑中。
+ *
+ * @param file 需要修改最后访问时间的文件。
+ * @since 1.0
+ */
+ public static void touch(File file) {
+ long currentTime = System.currentTimeMillis();
+ if (!file.exists()) {
+ System.err.println("file not found:" + file.getName());
+ System.err.println("Create a new file:" + file.getName());
+ try {
+ if (file.createNewFile()) {
+ System.out.println("Succeeded!");
+ } else {
+ System.err.println("Create file failed!");
+ }
+ } catch (IOException e) {
+ System.err.println("Create file failed!");
+ e.printStackTrace();
+ }
+ }
+ boolean result = file.setLastModified(currentTime);
+ if (!result) {
+ System.err.println("touch failed: " + file.getName());
+ }
+ }
+
+ /**
+ * 修改文件的最后访问时间。
+ * 如果文件不存在则创建该文件。
+ * 目前这个方法的行为方式还不稳定,主要是方法有些信息输出,这些信息输出是否保留还在考虑中。
+ *
+ * @param fileName 需要修改最后访问时间的文件的文件名。
+ * @since 1.0
+ */
+ public static void touch(String fileName) {
+ File file = new File(fileName);
+ touch(file);
+ }
+
+ /**
+ * 修改文件的最后访问时间。
+ * 如果文件不存在则创建该文件。
+ * 目前这个方法的行为方式还不稳定,主要是方法有些信息输出,这些信息输出是否保留还在考虑中。
+ *
+ * @param files 需要修改最后访问时间的文件数组。
+ * @since 1.0
+ */
+ public static void touch(File[] files) {
+ for (File file : files) {
+ touch(file);
+ }
+ }
+
+ /**
+ * 修改文件的最后访问时间。
+ * 如果文件不存在则创建该文件。
+ * 目前这个方法的行为方式还不稳定,主要是方法有些信息输出,这些信息输出是否保留还在考虑中。
+ *
+ * @param fileNames 需要修改最后访问时间的文件名数组。
+ * @since 1.0
+ */
+ public static void touch(String[] fileNames) {
+ File[] files = new File[fileNames.length];
+ for (int i = 0; i < fileNames.length; i++) {
+ files[i] = new File(fileNames[i]);
+ }
+ touch(files);
+ }
+
+ /**
+ * 判断指定的文件是否存在。
+ *
+ * @param fileName 要判断的文件的文件名
+ * @return 存在时返回true,否则返回false。
+ * @since 1.0
+ */
+ public static boolean isFileExist(String fileName) {
+ return new File(fileName).isFile();
+ }
+
+ /**
+ * 创建指定的目录。
+ * 如果指定的目录的父目录不存在则创建其目录书上所有需要的父目录。
+ * 注意:可能会在返回false的时候创建部分父目录。
+ *
+ * @param file 要创建的目录
+ * @return 完全创建成功时返回true,否则返回false。
+ * @since 1.0
+ */
+ public static boolean makeDirectory(File file) {
+ File parent = file.getParentFile();
+ return parent != null && parent.mkdirs();
+ }
+
+ /**
+ * 创建指定的目录。
+ * 如果指定的目录的父目录不存在则创建其目录书上所有需要的父目录。
+ * 注意:可能会在返回false的时候创建部分父目录。
+ *
+ * @param fileName 要创建的目录的目录名
+ * @return 完全创建成功时返回true,否则返回false。
+ * @since 1.0
+ */
+ public static boolean makeDirectory(String fileName) {
+ File file = new File(fileName);
+ return makeDirectory(file);
+ }
+
+ /**
+ * 清空指定目录中的文件。
+ * 这个方法将尽可能删除所有的文件,但是只要有一个文件没有被删除都会返回false。
+ * 另外这个方法不会迭代删除,即不会删除子目录及其内容。
+ *
+ * @param directory 要清空的目录
+ * @return 目录下的所有文件都被成功删除时返回true,否则返回false.
+ * @since 1.0
+ */
+ public static boolean emptyDirectory(File directory) {
+ boolean result = true;
+ File[] entries = directory.listFiles();
+ for (File entry : entries != null ? entries : new File[0]) {
+ if (!entry.delete()) {
+ result = false;
+ }
+ }
+ return result;
+ }
+
+ /**
+ * 清空指定目录中的文件。
+ * 这个方法将尽可能删除所有的文件,但是只要有一个文件没有被删除都会返回false。
+ * 另外这个方法不会迭代删除,即不会删除子目录及其内容。
+ *
+ * @param directoryName 要清空的目录的目录名
+ * @return 目录下的所有文件都被成功删除时返回true,否则返回false。
+ * @since 1.0
+ */
+ public static boolean emptyDirectory(String directoryName) {
+ File dir = new File(directoryName);
+ return emptyDirectory(dir);
+ }
+
+ /**
+ * 删除指定目录及其中的所有内容。
+ *
+ * @param dirName 要删除的目录的目录名
+ * @return 删除成功时返回true,否则返回false。
+ * @since 1.0
+ */
+ public static boolean deleteDirectory(String dirName) {
+ return deleteDirectory(new File(dirName));
+ }
+
+ /**
+ * 删除指定目录及其中的所有内容。
+ *
+ * @param dir 要删除的目录
+ * @return 删除成功时返回true,否则返回false。
+ * @since 1.0
+ */
+ public static boolean deleteDirectory(File dir) {
+ if ((dir == null) || !dir.isDirectory()) {
+ throw new IllegalArgumentException("Argument " + dir +
+ " is not a directory. ");
+ }
+
+ File[] entries = dir.listFiles();
+ int sz = entries != null ? entries.length : 0;
+
+ for (File entry : entries != null ? entries : new File[0]) {
+ if (entry.isDirectory()) {
+ if (!deleteDirectory(entry)) {
+ return false;
+ }
+ } else {
+ if (!entry.delete()) {
+ return false;
+ }
+ }
+ }
+
+ return dir.delete();
+ }
+
+
+ /**
+ * 列出目录中的所有内容,包括其子目录中的内容。
+ *
+ * @param file 要列出的目录
+ * @param filter 过滤器
+ * @return 目录内容的文件数组。
+ * @since 1.0
+ */
+ public static File[] listAll(File file,
+ javax.swing.filechooser.FileFilter filter) {
+ List arrayList = new ArrayList<>();
+ File[] files;
+ if (!file.exists() || file.isFile()) {
+ return null;
+ }
+ list(arrayList, file, filter);
+ files = new File[arrayList.size()];
+ arrayList.toArray(files);
+ return files;
+ }
+
+
+ /**
+ * 返回文件的URL地址。
+ *
+ * @param file 文件
+ * @return 文件对应的的URL地址
+ * @throws MalformedURLException
+ * @since 1.0
+ * @deprecated 在实现的时候没有注意到File类本身带一个toURL方法将文件路径转换为URL。
+ * 请使用File.toURL方法。
+ */
+ public static URL getURL(File file) throws MalformedURLException {
+ String fileURL = "file:/" + file.getAbsolutePath();
+ return new URL(fileURL);
+ }
+
+ /**
+ * 从文件路径得到文件名。
+ *
+ * @param filePath 文件的路径,可以是相对路径也可以是绝对路径
+ * @return 对应的文件名
+ * @since 1.0
+ */
+ public static String getFileName(String filePath) {
+ File file = new File(filePath);
+ return file.getName();
+ }
+
+ /**
+ * 从文件名得到文件绝对路径。
+ *
+ * @param fileName 文件名
+ * @return 对应的文件路径
+ * @since 1.0
+ */
+ public static String getFilePath(String fileName) {
+ File file = new File(fileName);
+ return file.getAbsolutePath();
+ }
+
+ /**
+ * 将DOS/Windows格式的路径转换为UNIX/Linux格式的路径。
+ * 其实就是将路径中的"\"全部换为"/",因为在某些情况下我们转换为这种方式比较方便,
+ * 某中程度上说"/"比"\"更适合作为路径分隔符,而且DOS/Windows也将它当作路径分隔符。
+ *
+ * @param filePath 转换前的路径
+ * @return 转换后的路径
+ * @since 1.0
+ */
+ public static String toUNIXpath(String filePath) {
+ return filePath.replace('\\', '/');
+ }
+
+ /**
+ * 从文件名得到UNIX风格的文件绝对路径。
+ *
+ * @param fileName 文件名
+ * @return 对应的UNIX风格的文件路径
+ * @see #toUNIXpath(String filePath) toUNIXpath
+ * @since 1.0
+ */
+ public static String getUNIXfilePath(String fileName) {
+ File file = new File(fileName);
+ return toUNIXpath(file.getAbsolutePath());
+ }
+
+ /**
+ * 得到文件的类型。
+ * 实际上就是得到文件名中最后一个“.”后面的部分。
+ *
+ * @param fileName 文件名
+ * @return 文件名中的类型部分
+ * @since 1.0
+ */
+ public static String getFileType(String fileName) {
+ int point = fileName.lastIndexOf('.');
+ int length = fileName.length();
+ if (point == -1 || point == length - 1) {
+ return "";
+ } else {
+ return fileName.substring(point + 1, length);
+ }
+ }
+
+ /**
+ * 得到文件的类型。
+ * 实际上就是得到文件名中最后一个“.”后面的部分。
+ *
+ * @param file 文件
+ * @return 文件名中的类型部分
+ * @since 1.0
+ */
+ public static String getFileType(File file) {
+ return getFileType(file.getName());
+ }
+
+ /**
+ * 得到文件的名字部分。
+ * 实际上就是路径中的最后一个路径分隔符后的部分。
+ *
+ * @param fileName 文件名
+ * @return 文件名中的名字部分
+ * @since 1.0
+ */
+ public static String getNamePart(String fileName) {
+ int point = getPathLsatIndex(fileName);
+ int length = fileName.length();
+ if (point == -1) {
+ return fileName;
+ } else if (point == length - 1) {
+ int secondPoint = getPathLsatIndex(fileName, point - 1);
+ if (secondPoint == -1) {
+ if (length == 1) {
+ return fileName;
+ } else {
+ return fileName.substring(0, point);
+ }
+ } else {
+ return fileName.substring(secondPoint + 1, point);
+ }
+ } else {
+ return fileName.substring(point + 1);
+ }
+ }
+
+ /**
+ * 得到文件名中的父路径部分。
+ * 对两种路径分隔符都有效。
+ * 不存在时返回""。
+ * 如果文件名是以路径分隔符结尾的则不考虑该分隔符,例如"/path/"返回""。
+ *
+ * @param fileName 文件名
+ * @return 父路径,不存在或者已经是父目录时返回""
+ * @since 1.0
+ */
+ public static String getPathPart(String fileName) {
+ int point = getPathLsatIndex(fileName);
+ int length = fileName.length();
+ if (point == -1) {
+ return "";
+ } else if (point == length - 1) {
+ int secondPoint = getPathLsatIndex(fileName, point - 1);
+ if (secondPoint == -1) {
+ return "";
+ } else {
+ return fileName.substring(0, secondPoint);
+ }
+ } else {
+ return fileName.substring(0, point);
+ }
+ }
+
+ /**
+ * 得到路径分隔符在文件路径中首次出现的位置。
+ * 对于DOS或者UNIX风格的分隔符都可以。
+ *
+ * @param fileName 文件路径
+ * @return 路径分隔符在路径中首次出现的位置,没有出现时返回-1。
+ * @since 1.0
+ */
+ public static int getPathIndex(String fileName) {
+ int point = fileName.indexOf('/');
+ if (point == -1) {
+ point = fileName.indexOf('\\');
+ }
+ return point;
+ }
+
+ /**
+ * 得到路径分隔符在文件路径中指定位置后首次出现的位置。
+ * 对于DOS或者UNIX风格的分隔符都可以。
+ *
+ * @param fileName 文件路径
+ * @param fromIndex 开始查找的位置
+ * @return 路径分隔符在路径中指定位置后首次出现的位置,没有出现时返回-1。
+ * @since 1.0
+ */
+ public static int getPathIndex(String fileName, int fromIndex) {
+ int point = fileName.indexOf('/', fromIndex);
+ if (point == -1) {
+ point = fileName.indexOf('\\', fromIndex);
+ }
+ return point;
+ }
+
+ /**
+ * 得到路径分隔符在文件路径中最后出现的位置。
+ * 对于DOS或者UNIX风格的分隔符都可以。
+ *
+ * @param fileName 文件路径
+ * @return 路径分隔符在路径中最后出现的位置,没有出现时返回-1。
+ * @since 1.0
+ */
+ public static int getPathLsatIndex(String fileName) {
+ int point = fileName.lastIndexOf('/');
+ if (point == -1) {
+ point = fileName.lastIndexOf('\\');
+ }
+ return point;
+ }
+
+ /**
+ * 得到路径分隔符在文件路径中指定位置前最后出现的位置。
+ * 对于DOS或者UNIX风格的分隔符都可以。
+ *
+ * @param fileName 文件路径
+ * @param fromIndex 开始查找的位置
+ * @return 路径分隔符在路径中指定位置前最后出现的位置,没有出现时返回-1。
+ * @since 1.0
+ */
+ public static int getPathLsatIndex(String fileName, int fromIndex) {
+ int point = fileName.lastIndexOf('/', fromIndex);
+ if (point == -1) {
+ point = fileName.lastIndexOf('\\', fromIndex);
+ }
+ return point;
+ }
+
+ /**
+ * 将文件名中的类型部分去掉。
+ *
+ * @param filename 文件名
+ * @return 去掉类型部分的结果
+ * @since 1.0
+ */
+ public static String trimType(String filename) {
+ int index = filename.lastIndexOf(".");
+ if (index != -1) {
+ return filename.substring(0, index);
+ } else {
+ return filename;
+ }
+ }
+
+ /**
+ * 得到相对路径。
+ * 文件名不是目录名的子节点时返回文件名。
+ *
+ * @param pathName 目录名
+ * @param fileName 文件名
+ * @return 得到文件名相对于目录名的相对路径,目录下不存在该文件时返回文件名
+ * @since 1.0
+ */
+ public static String getSubpath(String pathName, String fileName) {
+ int index = fileName.indexOf(pathName);
+ if (index != -1) {
+ return fileName.substring(index + pathName.length() + 1);
+ } else {
+ return fileName;
+ }
+ }
+
+ /**
+ * 检查给定目录的存在性
+ * 保证指定的路径可用,如果指定的路径不存在,那么建立该路径,可以为多级路径
+ *
+ * @param path
+ * @return 真假值
+ * @since 1.0
+ */
+ public static boolean pathValidate(String path) {
+ String[] arraypath = path.split("/");
+ String tmppath = "";
+ for (String anArraypath : arraypath) {
+ tmppath += "/" + anArraypath;
+ File d = new File(tmppath.substring(1));
+ //检查Sub目录是否存在
+ if (!d.exists()) {
+ System.out.println(tmppath.substring(1));
+ if (!d.mkdir()) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ /**
+ * 根据内容生成文件
+ *
+ * @param path 要生成文件的绝对路径,
+ * @param modulecontent 文件的内容。
+ * @return 真假值
+ * @since 1.0
+ */
+ public static boolean genModuleTpl(String path, String modulecontent) throws IOException {
+
+ path = getUNIXfilePath(path);
+ String[] patharray = path.split("\\/");
+ String modulepath = "";
+ for (int i = 0; i < patharray.length - 1; i++) {
+ modulepath += "/" + patharray[i];
+ }
+ File d = new File(modulepath.substring(1));
+ if (!d.exists()) {
+ if (!pathValidate(modulepath.substring(1))) {
+ return false;
+ }
+ }
+ //建立FileWriter对象,并实例化fw
+ FileWriter fw = new FileWriter(path);
+ //将字符串写入文件
+ fw.write(modulecontent);
+ fw.close();
+ return true;
+ }
+
+ /**
+ * 获取图片文件的扩展名(发布系统专用)
+ *
+ * @param picPath 为图片名称加上前面的路径不包括扩展名
+ * @return 图片的扩展名
+ * @since 1.0
+ */
+ public static String getPicExtendName(String picPath) {
+ picPath = getUNIXfilePath(picPath);
+ String picExtend = "";
+ String gif = ".gif";
+ if (isFileExist(picPath + gif)) {
+ picExtend = gif;
+ }
+ String jpeg = ".jpeg";
+ if (isFileExist(picPath + jpeg)) {
+ picExtend = jpeg;
+ }
+ String jpg = ".jpg";
+ if (isFileExist(picPath + jpg)) {
+ picExtend = jpg;
+ }
+ String png = ".png";
+ if (isFileExist(picPath + png)) {
+ picExtend = png;
+ }
+ //返回图片扩展名
+ return picExtend;
+ }
+
+ public static boolean copyFile(File in, File out) throws Exception {
+ try {
+ FileInputStream fis = new FileInputStream(in);
+ FileOutputStream fos = new FileOutputStream(out);
+ byte[] buf = new byte[1024];
+ int i = 0;
+ while ((i = fis.read(buf)) != -1) {
+ fos.write(buf, 0, i);
+ }
+ fis.close();
+ fos.close();
+ return true;
+ } catch (IOException ie) {
+ ie.printStackTrace();
+ return false;
+ }
+ }
+
+ public static boolean copyFile(String infile, String outfile) throws Exception {
+ try {
+ File in = new File(infile);
+ File out = new File(outfile);
+ return copyFile(in, out);
+ } catch (IOException ie) {
+ ie.printStackTrace();
+ return false;
+ }
+
+ }
+
+ /**
+ * Copy the data from the input stream to the output stream.
+ *
+ * @param in data source
+ * @param out data destination
+ * @throws IOException in an input or output error occurs
+ * @since orientals 1.00.00
+ */
+ private static void copy(InputStream in, OutputStream out) throws IOException {
+ byte[] buffer = new byte[BUFFER_SIZE];
+ int read;
+ while ((read = in.read(buffer)) != -1) {
+ out.write(buffer, 0, read);
+ }
+ }
+
+ /**
+ * 将目录中的内容添加到列表。
+ *
+ * @param list 文件列表
+ * @param filter 过滤器
+ * @param file 目录
+ */
+ private static void list(List list, File file,
+ javax.swing.filechooser.FileFilter filter) {
+ if (filter.accept(file)) {
+ list.add(file);
+ if (file.isFile()) {
+ return;
+ }
+ }
+ if (file.isDirectory()) {
+ File[] files = file.listFiles();
+ for (File file1 : files != null ? files : new File[0]) {
+ list(list, file1, filter);
+ }
+ }
+
+ }
+
+
+ /**
+ * 文件上传
+ *
+ * @param file file
+ * @param email email
+ * @return fileUrl
+ */
+ public static String upload(MultipartFile file, String email) {
+ String savePath = "";
+ String filename = "";
+ if (file != null && !file.isEmpty()) {
+ // 获取图片的文件名
+ String fileName = file.getOriginalFilename();
+ // 重新定义图片名字
+ filename = FileUtil.getNewFileName(fileName, email);
+ //上传服务器上 新文件路径
+ String os = System.getProperty("os.name").toLowerCase();
+ try {
+ // 判断服务器上 文件夹是否存在
+ File newFile = new File(savePath);
+ if (!newFile.exists()) {
+ boolean result = newFile.mkdirs();
+ System.out.println(result);
+ }
+ savePath = savePath + filename;
+ FileOutputStream out = new FileOutputStream(savePath);
+ // 写入文件
+ out.write(file.getBytes());
+ out.flush();
+ out.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ return filename;
+ }
+
+
+ public static byte[] readStream(InputStream inStream) throws Exception {
+ ByteArrayOutputStream outsStream = new ByteArrayOutputStream();
+ byte[] buffer = new byte[1024];
+ int len = -1;
+ while ((len = inStream.read(buffer)) != -1) {
+ outsStream.write(buffer, 0, len);
+ }
+ outsStream.close();
+ inStream.close();
+ return outsStream.toByteArray();
+ }
+
+ public static byte[] readFileImage(File file) throws IOException {
+ BufferedInputStream bufferedInputStream = new BufferedInputStream(
+ new FileInputStream(file));
+ int len = bufferedInputStream.available();
+ byte[] bytes = new byte[len];
+ int r = bufferedInputStream.read(bytes);
+ if (len != r) {
+ bytes = null;
+ throw new IOException("读取文件不正确");
+ }
+ bufferedInputStream.close();
+ return bytes;
+ }
+
+ public static byte[] readFileImage(String filename) throws IOException {
+ BufferedInputStream bufferedInputStream = new BufferedInputStream(
+ new FileInputStream(filename));
+ int len = bufferedInputStream.available();
+ byte[] bytes = new byte[len];
+ int r = bufferedInputStream.read(bytes);
+ if (len != r) {
+ bytes = null;
+ throw new IOException("读取文件不正确");
+ }
+ bufferedInputStream.close();
+ return bytes;
+ }
+
+
+ /**
+ * 读取返回的信息
+ *
+ * @param in
+ * @return
+ */
+ private static String getData(InputStream in) {
+ String result = "";
+ StringBuilder sb = new StringBuilder();
+ BufferedReader br = new BufferedReader(new InputStreamReader(in));
+ String line = "";
+ try {
+ while ((line = br.readLine()) != null) {
+ // result = result + line;
+ sb.append(line);
+ }
+ br.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ try {
+ br.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ return sb.toString();
+ }
+
+
+ private static String bytesToHexString(byte[] src) {
+ StringBuilder stringBuilder = new StringBuilder();
+ if (src == null || src.length <= 0) {
+ return null;
+ }
+ for (byte aSrc : src) {
+ int v = aSrc & 0xFF;
+ String hv = Integer.toHexString(v);
+ if (hv.length() < 2) {
+ stringBuilder.append(0);
+ }
+ stringBuilder.append(hv);
+ }
+ return stringBuilder.toString();
+ }
+
+
+ /**
+ * 获取文件内容
+ *
+ * @param filePath
+ * @return
+ * @throws IOException
+ */
+ private static String getFile(String filePath) throws IOException {
+ byte[] b = new byte[28];
+ InputStream inputStream = null;
+ try {
+ inputStream = new FileInputStream(filePath);
+ inputStream.read(b, 0, 28);
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ if (inputStream != null) {
+ try {
+ inputStream.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ return bytesToHexString(b);
+ }
+
+ /**
+ * @param filePath filePath
+ * @return FileConst
+ * @throws IOException
+ */
+ public static FileConst getType(String filePath) throws IOException {
+ String fileHead = getFile(filePath);
+ if (fileHead == null || fileHead.length() == 0) {
+ return null;
+ }
+ fileHead = fileHead.toUpperCase();
+ FileConst[] fileConsts = FileConst.values();
+ for (FileConst type : fileConsts) {
+ if (fileHead.startsWith(type.getValue())) {
+ return type;
+ }
+ }
+ return null;
+ }
+
+ public static String getNewFileName(String fileName, String email) {
+ String fileType = FileUtil.getFileType(fileName);
+ String newName = email.split(SymbolConst.AT)[0];
+ return (TimeUtil.getDateNow(TimeUtil.DATE_FORMAT_STRING) + SymbolConst.HENGXIAN + newName + SymbolConst.DIAN + fileType).toLowerCase();
+ }
+
+ public static boolean isImage(String imageName) {
+ String fileType = FileUtil.getFileType(imageName);
+ return !("bmp".equals(fileType) || "BMP".equals(fileType)
+ || "jpg".equals(fileType) || "JPG".equals(fileType)
+ || "jpeg".equals(fileType) || "JPEG".equals(fileType)
+ || "git".equals(fileType) || "GIF".equals(fileType)
+ || "png".equals(fileType) || "PNG".equals(fileType));
+ }
+
+}
diff --git a/core/src/main/java/info/xiaomo/core/untils/FileUtil.kt b/core/src/main/java/info/xiaomo/core/untils/FileUtil.kt
deleted file mode 100644
index 2da2a513..00000000
--- a/core/src/main/java/info/xiaomo/core/untils/FileUtil.kt
+++ /dev/null
@@ -1,855 +0,0 @@
-package info.xiaomo.core.untils
-
-import info.xiaomo.core.constant.FileConst
-import info.xiaomo.core.constant.SymbolConst
-import org.springframework.web.multipart.MultipartFile
-import java.io.*
-import java.net.MalformedURLException
-import java.net.URL
-import java.util.*
-import kotlin.experimental.and
-
-/**
- * 此类中封装一些常用的文件操作。
- * 所有方法都是静态方法,不需要生成此类的实例,
- * 为避免生成此类的实例,构造方法被申明为private类型的。
- *
- * @author : xiaomo
- * @since 1.0
- */
-
-object FileUtil {
- /**
- * Buffer size when reading from input stream.
- *
- * @since ostermillerutils 1.00.00
- */
- private val BUFFER_SIZE = 1024
-
- /**
- * 修改文件的最后访问时间。
- * 如果文件不存在则创建该文件。
- * **目前这个方法的行为方式还不稳定,主要是方法有些信息输出,这些信息输出是否保留还在考虑中。**
- *
- * @param file 需要修改最后访问时间的文件。
- * @since 1.0
- */
- fun touch(file: File?) {
- val currentTime = System.currentTimeMillis()
- if (file != null) {
- if (!file.exists()) {
- System.err.println("file not found:" + file.name)
- System.err.println("Create a new file:" + file.name)
- try {
- if (file.createNewFile()) {
- println("Succeeded!")
- } else {
- System.err.println("Create file failed!")
- }
- } catch (e: IOException) {
- System.err.println("Create file failed!")
- e.printStackTrace()
- }
-
- }
- }
- val result = file!!.setLastModified(currentTime)
- if (!result) {
- System.err.println("touch failed: " + file.name)
- }
- }
-
- /**
- * 修改文件的最后访问时间。
- * 如果文件不存在则创建该文件。
- * **目前这个方法的行为方式还不稳定,主要是方法有些信息输出,这些信息输出是否保留还在考虑中。**
- *
- * @param fileName 需要修改最后访问时间的文件的文件名。
- * @since 1.0
- */
- fun touch(fileName: String) {
- val file = File(fileName)
- touch(file)
- }
-
- /**
- * 修改文件的最后访问时间。
- * 如果文件不存在则创建该文件。
- * **目前这个方法的行为方式还不稳定,主要是方法有些信息输出,这些信息输出是否保留还在考虑中。**
- *
- * @param files 需要修改最后访问时间的文件数组。
- * @since 1.0
- */
- fun touch(files: Array) {
- for (file in files) {
- touch(file)
- }
- }
-
- /**
- * 修改文件的最后访问时间。
- * 如果文件不存在则创建该文件。
- * **目前这个方法的行为方式还不稳定,主要是方法有些信息输出,这些信息输出是否保留还在考虑中。**
- *
- * @param fileNames 需要修改最后访问时间的文件名数组。
- * @since 1.0
- */
- @JvmStatic
- fun touch(fileNames: Array) {
- val files = arrayOfNulls(fileNames.size)
- for (i in fileNames.indices) {
- files[i] = File(fileNames[i])
- }
- touch(files)
- }
-
- /**
- * 判断指定的文件是否存在。
- *
- * @param fileName 要判断的文件的文件名
- * @return 存在时返回true,否则返回false。
- * @since 1.0
- */
- fun isFileExist(fileName: String): Boolean {
- return File(fileName).isFile
- }
-
- /**
- * 创建指定的目录。
- * 如果指定的目录的父目录不存在则创建其目录书上所有需要的父目录。
- * **注意:可能会在返回false的时候创建部分父目录。**
- *
- * @param file 要创建的目录
- * @return 完全创建成功时返回true,否则返回false。
- * @since 1.0
- */
- fun makeDirectory(file: File): Boolean {
- val parent = file.parentFile
- return parent != null && parent.mkdirs()
- }
-
- /**
- * 创建指定的目录。
- * 如果指定的目录的父目录不存在则创建其目录书上所有需要的父目录。
- * **注意:可能会在返回false的时候创建部分父目录。**
- *
- * @param fileName 要创建的目录的目录名
- * @return 完全创建成功时返回true,否则返回false。
- * @since 1.0
- */
- fun makeDirectory(fileName: String): Boolean {
- val file = File(fileName)
- return makeDirectory(file)
- }
-
- /**
- * 清空指定目录中的文件。
- * 这个方法将尽可能删除所有的文件,但是只要有一个文件没有被删除都会返回false。
- * 另外这个方法不会迭代删除,即不会删除子目录及其内容。
- *
- * @param directory 要清空的目录
- * @return 目录下的所有文件都被成功删除时返回true,否则返回false.
- * @since 1.0
- */
- fun emptyDirectory(directory: File): Boolean {
- var result = true
- val entries = directory.listFiles()
- for (entry in entries ?: arrayOfNulls(0)) {
- if (!entry.delete()) {
- result = false
- }
- }
- return result
- }
-
- /**
- * 清空指定目录中的文件。
- * 这个方法将尽可能删除所有的文件,但是只要有一个文件没有被删除都会返回false。
- * 另外这个方法不会迭代删除,即不会删除子目录及其内容。
- *
- * @param directoryName 要清空的目录的目录名
- * @return 目录下的所有文件都被成功删除时返回true,否则返回false。
- * @since 1.0
- */
- fun emptyDirectory(directoryName: String): Boolean {
- val dir = File(directoryName)
- return emptyDirectory(dir)
- }
-
- /**
- * 删除指定目录及其中的所有内容。
- *
- * @param dirName 要删除的目录的目录名
- * @return 删除成功时返回true,否则返回false。
- * @since 1.0
- */
- fun deleteDirectory(dirName: String): Boolean {
- return deleteDirectory(File(dirName))
- }
-
- /**
- * 删除指定目录及其中的所有内容。
- *
- * @param dir 要删除的目录
- * @return 删除成功时返回true,否则返回false。
- * @since 1.0
- */
- fun deleteDirectory(dir: File?): Boolean {
- if (dir == null || !dir.isDirectory) {
- throw IllegalArgumentException("Argument " + dir +
- " is not a directory. ")
- }
-
- val entries = dir.listFiles()
- val sz = entries?.size ?: 0
-
- for (entry in entries ?: arrayOfNulls(0)) {
- if (entry.isDirectory) {
- if (!deleteDirectory(entry)) {
- return false
- }
- } else {
- if (!entry.delete()) {
- return false
- }
- }
- }
-
- return dir.delete()
- }
-
-
- /**
- * 列出目录中的所有内容,包括其子目录中的内容。
- *
- * @param file 要列出的目录
- * @param filter 过滤器
- * @return 目录内容的文件数组。
- * @since 1.0
- */
- fun listAll(file: File,
- filter: javax.swing.filechooser.FileFilter): Array? {
- val arrayList = ArrayList()
- val files: Array
- if (!file.exists() || file.isFile) {
- return null
- }
- list(arrayList, file, filter)
- files = arrayOfNulls(arrayList.size)
- arrayList.toTypedArray()
- return files
- }
-
-
- /**
- * 返回文件的URL地址。
- *
- * @param file 文件
- * @return 文件对应的的URL地址
- * @throws MalformedURLException
- * @since 1.0
- */
- @Deprecated("在实现的时候没有注意到File类本身带一个toURL方法将文件路径转换为URL。\n" +
- " 请使用File.toURL方法。")
- @Throws(MalformedURLException::class)
- fun getURL(file: File): URL {
- val fileURL = "file:/" + file.absolutePath
- return URL(fileURL)
- }
-
- /**
- * 从文件路径得到文件名。
- *
- * @param filePath 文件的路径,可以是相对路径也可以是绝对路径
- * @return 对应的文件名
- * @since 1.0
- */
- fun getFileName(filePath: String): String {
- val file = File(filePath)
- return file.name
- }
-
- /**
- * 从文件名得到文件绝对路径。
- *
- * @param fileName 文件名
- * @return 对应的文件路径
- * @since 1.0
- */
- fun getFilePath(fileName: String): String {
- val file = File(fileName)
- return file.absolutePath
- }
-
- /**
- * 将DOS/Windows格式的路径转换为UNIX/Linux格式的路径。
- * 其实就是将路径中的"\"全部换为"/",因为在某些情况下我们转换为这种方式比较方便,
- * 某中程度上说"/"比"\"更适合作为路径分隔符,而且DOS/Windows也将它当作路径分隔符。
- *
- * @param filePath 转换前的路径
- * @return 转换后的路径
- * @since 1.0
- */
- fun toUNIXpath(filePath: String): String {
- return filePath.replace('\\', '/')
- }
-
- /**
- * 从文件名得到UNIX风格的文件绝对路径。
- *
- * @param fileName 文件名
- * @return 对应的UNIX风格的文件路径
- * @see .toUNIXpath
- * @since 1.0
- */
- fun getUNIXfilePath(fileName: String): String {
- val file = File(fileName)
- return toUNIXpath(file.absolutePath)
- }
-
- /**
- * 得到文件的类型。
- * 实际上就是得到文件名中最后一个“.”后面的部分。
- *
- * @param fileName 文件名
- * @return 文件名中的类型部分
- * @since 1.0
- */
- fun getFileType(fileName: String): String {
- val point = fileName.lastIndexOf('.')
- val length = fileName.length
- return if (point == -1 || point == length - 1) {
- ""
- } else {
- fileName.substring(point + 1, length)
- }
- }
-
- /**
- * 得到文件的类型。
- * 实际上就是得到文件名中最后一个“.”后面的部分。
- *
- * @param file 文件
- * @return 文件名中的类型部分
- * @since 1.0
- */
- fun getFileType(file: File): String {
- return getFileType(file.name)
- }
-
- /**
- * 得到文件的名字部分。
- * 实际上就是路径中的最后一个路径分隔符后的部分。
- *
- * @param fileName 文件名
- * @return 文件名中的名字部分
- * @since 1.0
- */
- fun getNamePart(fileName: String): String {
- val point = getPathLsatIndex(fileName)
- val length = fileName.length
- if (point == -1) {
- return fileName
- } else if (point == length - 1) {
- val secondPoint = getPathLsatIndex(fileName, point - 1)
- return if (secondPoint == -1) {
- if (length == 1) {
- fileName
- } else {
- fileName.substring(0, point)
- }
- } else {
- fileName.substring(secondPoint + 1, point)
- }
- } else {
- return fileName.substring(point + 1)
- }
- }
-
- /**
- * 得到文件名中的父路径部分。
- * 对两种路径分隔符都有效。
- * 不存在时返回""。
- * 如果文件名是以路径分隔符结尾的则不考虑该分隔符,例如"/path/"返回""。
- *
- * @param fileName 文件名
- * @return 父路径,不存在或者已经是父目录时返回""
- * @since 1.0
- */
- fun getPathPart(fileName: String): String {
- val point = getPathLsatIndex(fileName)
- val length = fileName.length
- if (point == -1) {
- return ""
- } else if (point == length - 1) {
- val secondPoint = getPathLsatIndex(fileName, point - 1)
- return if (secondPoint == -1) {
- ""
- } else {
- fileName.substring(0, secondPoint)
- }
- } else {
- return fileName.substring(0, point)
- }
- }
-
- /**
- * 得到路径分隔符在文件路径中首次出现的位置。
- * 对于DOS或者UNIX风格的分隔符都可以。
- *
- * @param fileName 文件路径
- * @return 路径分隔符在路径中首次出现的位置,没有出现时返回-1。
- * @since 1.0
- */
- fun getPathIndex(fileName: String): Int {
- var point = fileName.indexOf('/')
- if (point == -1) {
- point = fileName.indexOf('\\')
- }
- return point
- }
-
- /**
- * 得到路径分隔符在文件路径中指定位置后首次出现的位置。
- * 对于DOS或者UNIX风格的分隔符都可以。
- *
- * @param fileName 文件路径
- * @param fromIndex 开始查找的位置
- * @return 路径分隔符在路径中指定位置后首次出现的位置,没有出现时返回-1。
- * @since 1.0
- */
- fun getPathIndex(fileName: String, fromIndex: Int): Int {
- var point = fileName.indexOf('/', fromIndex)
- if (point == -1) {
- point = fileName.indexOf('\\', fromIndex)
- }
- return point
- }
-
- /**
- * 得到路径分隔符在文件路径中最后出现的位置。
- * 对于DOS或者UNIX风格的分隔符都可以。
- *
- * @param fileName 文件路径
- * @return 路径分隔符在路径中最后出现的位置,没有出现时返回-1。
- * @since 1.0
- */
- fun getPathLsatIndex(fileName: String): Int {
- var point = fileName.lastIndexOf('/')
- if (point == -1) {
- point = fileName.lastIndexOf('\\')
- }
- return point
- }
-
- /**
- * 得到路径分隔符在文件路径中指定位置前最后出现的位置。
- * 对于DOS或者UNIX风格的分隔符都可以。
- *
- * @param fileName 文件路径
- * @param fromIndex 开始查找的位置
- * @return 路径分隔符在路径中指定位置前最后出现的位置,没有出现时返回-1。
- * @since 1.0
- */
- fun getPathLsatIndex(fileName: String, fromIndex: Int): Int {
- var point = fileName.lastIndexOf('/', fromIndex)
- if (point == -1) {
- point = fileName.lastIndexOf('\\', fromIndex)
- }
- return point
- }
-
- /**
- * 将文件名中的类型部分去掉。
- *
- * @param filename 文件名
- * @return 去掉类型部分的结果
- * @since 1.0
- */
- fun trimType(filename: String): String {
- val index = filename.lastIndexOf(".")
- return if (index != -1) {
- filename.substring(0, index)
- } else {
- filename
- }
- }
-
- /**
- * 得到相对路径。
- * 文件名不是目录名的子节点时返回文件名。
- *
- * @param pathName 目录名
- * @param fileName 文件名
- * @return 得到文件名相对于目录名的相对路径,目录下不存在该文件时返回文件名
- * @since 1.0
- */
- fun getSubpath(pathName: String, fileName: String): String {
- val index = fileName.indexOf(pathName)
- return if (index != -1) {
- fileName.substring(index + pathName.length + 1)
- } else {
- fileName
- }
- }
-
- /**
- * 检查给定目录的存在性
- * 保证指定的路径可用,如果指定的路径不存在,那么建立该路径,可以为多级路径
- *
- * @param path
- * @return 真假值
- * @since 1.0
- */
- fun pathValidate(path: String): Boolean {
- val arraypath = path.split("/".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
- var tmppath = ""
- for (anArraypath in arraypath) {
- tmppath += "/" + anArraypath
- val d = File(tmppath.substring(1))
- //检查Sub目录是否存在
- if (!d.exists()) {
- println(tmppath.substring(1))
- if (!d.mkdir()) {
- return false
- }
- }
- }
- return true
- }
-
- /**
- * 根据内容生成文件
- *
- * @param path 要生成文件的绝对路径,
- * @param modulecontent 文件的内容。
- * @return 真假值
- * @since 1.0
- */
- @Throws(IOException::class)
- fun genModuleTpl(path: String, modulecontent: String): Boolean {
- var path = path
-
- path = getUNIXfilePath(path)
- val patharray = path.split("\\/".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
- var modulepath = ""
- for (i in 0 until patharray.size - 1) {
- modulepath += "/" + patharray[i]
- }
- val d = File(modulepath.substring(1))
- if (!d.exists()) {
- if (!pathValidate(modulepath.substring(1))) {
- return false
- }
- }
- //建立FileWriter对象,并实例化fw
- val fw = FileWriter(path)
- //将字符串写入文件
- fw.write(modulecontent)
- fw.close()
- return true
- }
-
- /**
- * 获取图片文件的扩展名(发布系统专用)
- *
- * @param picPath 为图片名称加上前面的路径不包括扩展名
- * @return 图片的扩展名
- * @since 1.0
- */
- fun getPicExtendName(picPath: String): String {
- var picPath = picPath
- picPath = getUNIXfilePath(picPath)
- var picExtend = ""
- val gif = ".gif"
- if (isFileExist(picPath + gif)) {
- picExtend = gif
- }
- val jpeg = ".jpeg"
- if (isFileExist(picPath + jpeg)) {
- picExtend = jpeg
- }
- val jpg = ".jpg"
- if (isFileExist(picPath + jpg)) {
- picExtend = jpg
- }
- val png = ".png"
- if (isFileExist(picPath + png)) {
- picExtend = png
- }
- //返回图片扩展名
- return picExtend
- }
-
- @Throws(Exception::class)
- fun copyFile(`in`: File, out: File): Boolean {
- try {
- val fis = FileInputStream(`in`)
- val fos = FileOutputStream(out)
- val buf = ByteArray(1024)
- var i = 0
- while ((fis.read(buf)) != -1) {
- fos.write(buf, 0, i)
- }
- fis.close()
- fos.close()
- return true
- } catch (ie: IOException) {
- ie.printStackTrace()
- return false
- }
-
- }
-
- @Throws(Exception::class)
- fun copyFile(infile: String, outfile: String): Boolean {
- try {
- val `in` = File(infile)
- val out = File(outfile)
- return copyFile(`in`, out)
- } catch (ie: IOException) {
- ie.printStackTrace()
- return false
- }
-
- }
-
- /**
- * Copy the data from the input stream to the output stream.
- *
- * @param in data source
- * @param out data destination
- * @throws IOException in an input or output error occurs
- * @since orientals 1.00.00
- */
- @Throws(IOException::class)
- private fun copy(`in`: InputStream, out: OutputStream) {
- val buffer = ByteArray(BUFFER_SIZE)
- val read = 0
- while ((`in`.read(buffer)) != -1) {
- out.write(buffer, 0, read)
- }
- }
-
- /**
- * 将目录中的内容添加到列表。
- *
- * @param list 文件列表
- * @param filter 过滤器
- * @param file 目录
- */
- private fun list(list: MutableList, file: File,
- filter: javax.swing.filechooser.FileFilter) {
- if (filter.accept(file)) {
- list.add(file)
- if (file.isFile) {
- return
- }
- }
- if (file.isDirectory) {
- val files = file.listFiles()
- for (file1 in files ?: arrayOfNulls(0)) {
- list(list, file1, filter)
- }
- }
-
- }
-
-
- /**
- * 文件上传
- *
- * @param file file
- * @param email email
- * @return fileUrl
- */
- fun upload(file: MultipartFile?, email: String): String {
- var savePath = ""
- var filename = ""
- if (file != null && !file.isEmpty) {
- // 获取图片的文件名
- val fileName = file.originalFilename
- // 重新定义图片名字
- filename = FileUtil.getNewFileName(fileName, email)
- //上传服务器上 新文件路径
- val os = System.getProperty("os.name").toLowerCase()
- try {
- // 判断服务器上 文件夹是否存在
- val newFile = File(savePath)
- if (!newFile.exists()) {
- val result = newFile.mkdirs()
- println(result)
- }
- savePath = savePath + filename
- val out = FileOutputStream(savePath)
- // 写入文件
- out.write(file.bytes)
- out.flush()
- out.close()
- } catch (e: Exception) {
- e.printStackTrace()
- }
-
- }
- return filename
- }
-
-
- @Throws(Exception::class)
- fun readStream(inStream: InputStream): ByteArray {
- val outsStream = ByteArrayOutputStream()
- val buffer = ByteArray(1024)
- var len = -1
- while ((inStream.read(buffer)) != -1) {
- outsStream.write(buffer, 0, len)
- }
- outsStream.close()
- inStream.close()
- return outsStream.toByteArray()
- }
-
- @Throws(IOException::class)
- fun readFileImage(file: File): ByteArray {
- val bufferedInputStream = BufferedInputStream(
- FileInputStream(file))
- val len = bufferedInputStream.available()
- var bytes: ByteArray? = ByteArray(len)
- val r = bufferedInputStream.read(bytes!!)
- if (len != r) {
- bytes = null
- throw IOException("读取文件不正确")
- }
- bufferedInputStream.close()
- return bytes
- }
-
- @Throws(IOException::class)
- fun readFileImage(filename: String): ByteArray {
- val bufferedInputStream = BufferedInputStream(
- FileInputStream(filename))
- val len = bufferedInputStream.available()
- var bytes: ByteArray? = ByteArray(len)
- val r = bufferedInputStream.read(bytes!!)
- if (len != r) {
- bytes = null
- throw IOException("读取文件不正确")
- }
- bufferedInputStream.close()
- return bytes
- }
-
-
- /**
- * 读取返回的信息
- *
- * @param in
- * @return
- */
- private fun getData(`in`: InputStream): String {
- val result = ""
- val sb = StringBuilder()
- val br = BufferedReader(InputStreamReader(`in`))
- var line = ""
- try {
- while ((br.readLine()) != null) {
- // result = result + line;
- sb.append(line)
- }
- br.close()
- } catch (e: Exception) {
- e.printStackTrace()
- } finally {
- try {
- br.close()
- } catch (e: IOException) {
- e.printStackTrace()
- }
-
- }
- return sb.toString()
- }
-
-
- private fun bytesToHexString(src: ByteArray?): String? {
- val stringBuilder = StringBuilder()
- if (src == null || src.size <= 0) {
- return null
- }
- for (aSrc in src) {
- val v = aSrc and 0xFF.toByte()
- val hv = Integer.toHexString(v.toInt())
- if (hv.length < 2) {
- stringBuilder.append(0)
- }
- stringBuilder.append(hv)
- }
- return stringBuilder.toString()
- }
-
-
- /**
- * 获取文件内容
- *
- * @param filePath
- * @return
- * @throws IOException
- */
- @Throws(IOException::class)
- private fun getFile(filePath: String): String? {
- val b = ByteArray(28)
- var inputStream: InputStream? = null
- try {
- inputStream = FileInputStream(filePath)
- inputStream.read(b, 0, 28)
- } catch (e: IOException) {
- e.printStackTrace()
- } finally {
- if (inputStream != null) {
- try {
- inputStream.close()
- } catch (e: IOException) {
- e.printStackTrace()
- }
-
- }
- }
- return bytesToHexString(b)
- }
-
- /**
- * @param filePath filePath
- * @return FileConst
- * @throws IOException
- */
- @Throws(IOException::class)
- fun getType(filePath: String): FileConst? {
- var fileHead = getFile(filePath)
- if (fileHead == null || fileHead.length == 0) {
- return null
- }
- fileHead = fileHead.toUpperCase()
- val fileConsts = FileConst.values()
- for (type in fileConsts) {
- if (fileHead.startsWith(type.value)) {
- return type
- }
- }
- return null
- }
-
- fun getNewFileName(fileName: String, email: String): String {
- val fileType = FileUtil.getFileType(fileName)
- val newName = email.split(SymbolConst.AT.toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()[0]
- return (TimeUtil.getDateNow(TimeUtil.DATE_FORMAT_STRING) + SymbolConst.HENGXIAN + newName + SymbolConst.DIAN + fileType).toLowerCase()
- }
-
- fun isImage(imageName: String): Boolean {
- val fileType = FileUtil.getFileType(imageName)
- return !("bmp" == fileType || "BMP" == fileType
- || "jpg" == fileType || "JPG" == fileType
- || "jpeg" == fileType || "JPEG" == fileType
- || "git" == fileType || "GIF" == fileType
- || "png" == fileType || "PNG" == fileType)
- }
-
-}
diff --git a/core/src/main/java/info/xiaomo/core/untils/HtmlUtil.java b/core/src/main/java/info/xiaomo/core/untils/HtmlUtil.java
new file mode 100644
index 00000000..975e56ac
--- /dev/null
+++ b/core/src/main/java/info/xiaomo/core/untils/HtmlUtil.java
@@ -0,0 +1,170 @@
+package info.xiaomo.core.untils;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * 把今天最好的表现当作明天最新的起点..~
+ * いま 最高の表現 として 明日最新の始発..~
+ * Today the best performance as tomorrow newest starter!
+ *
+ *
+ * @author : xiaomo
+ * github: https://github.com/syoubaku
+ * email: xiaomo@xiamoo.info
+ * QQ_NO: 83387856
+ * Date: 17/5/11 17:57
+ * Description:
+ * Copyright(©) 2017 by xiaomo.
+ */
+public class HtmlUtil {
+
+
+ /**
+ * 是否包含有HTML标签
+ *
+ * @param str 字符串
+ * @return 是否包含html标签
+ */
+ public static boolean containsHTMLTag(String str) {
+ if (StringUtil.isBlank(str)) {
+ return false;
+ }
+
+ String pattern = "<\\s*(\\S+)(\\s[^>]*)?>[\\s\\S]*<\\s*/\\1\\s*>";
+ Pattern p = Pattern.compile(pattern);
+ Matcher m = p.matcher(str);
+ return m.find();
+ }
+
+ /**
+ * 用于将字符串中的特殊字符转换成Web页中可以安全显示的字符串
+ * 可对表单数据据进行处理对一些页面特殊字符进行处理如'<','>','"',''','&'
+ *
+ * @param strSrc 要进行替换操作的字符串
+ * @return 替换特殊字符后的字符串
+ * @since 1.0
+ */
+
+ public static String htmlEncode(String strSrc) {
+ if (strSrc == null) {
+ return "";
+ }
+ char[] arrCsrc = strSrc.toCharArray();
+ StringBuilder buf = new StringBuilder(arrCsrc.length);
+ char ch;
+ for (char anArrCSrc : arrCsrc) {
+ ch = anArrCSrc;
+
+ if (ch == '<') {
+ buf.append("<");
+ } else if (ch == '>') {
+ buf.append(">");
+ } else if (ch == '"') {
+ buf.append(""");
+ } else if (ch == '\'') {
+ buf.append("'");
+ } else if (ch == '&') {
+ buf.append("&");
+ } else {
+ buf.append(ch);
+ }
+ }
+
+ return buf.toString();
+ }
+
+ /**
+ * 用于将字符串中的特殊字符转换成Web页中可以安全显示的字符串
+ * 可对表单数据据进行处理对一些页面特殊字符进行处理如'<','>','"',''','&'
+ *
+ * @param strSrc 要进行替换操作的字符串
+ * @param quotes 为0时单引号和双引号都替换,为1时不替换单引号,为2时不替换双引号,为3时单引号和双引号都不替换
+ * @return 替换特殊字符后的字符串
+ * @since 1.0
+ */
+ public static String htmlEncode(String strSrc, int quotes) {
+
+ if (strSrc == null) {
+ return "";
+ }
+ if (quotes == 0) {
+ return htmlEncode(strSrc);
+ }
+
+ char[] arrCsrc = strSrc.toCharArray();
+ StringBuilder buf = new StringBuilder(arrCsrc.length);
+ char ch;
+
+ for (int i = 0; i < arrCsrc.length; i++) {
+ ch = arrCsrc[i];
+ if (ch == '<') {
+ buf.append("<");
+ } else if (ch == '>') {
+ buf.append(">");
+ } else if (ch == '"' && quotes == 1) {
+ buf.append(""");
+ } else if (ch == '\'' && quotes == 2) {
+ buf.append("'");
+ } else if (ch == '&') {
+ buf.append("&");
+ } else {
+ buf.append(ch);
+ }
+ }
+
+ return buf.toString();
+ }
+
+ /**
+ * 和htmlEncode正好相反
+ *
+ * @param strSrc 要进行转换的字符串
+ * @return 转换后的字符串
+ * @since 1.0
+ */
+ public static String htmlDecode(String strSrc) {
+ if (strSrc == null) {
+ return "";
+ }
+ strSrc = strSrc.replaceAll("<", "<");
+ strSrc = strSrc.replaceAll(">", ">");
+ strSrc = strSrc.replaceAll(""", "\"");
+ strSrc = strSrc.replaceAll("'", "'");
+ strSrc = strSrc.replaceAll("&", "&");
+ return strSrc;
+ }
+
+ /**
+ * 去除html tag
+ *
+ * @param htmlStr html
+ * @return string
+ */
+ public static String delHTMLTag(String htmlStr) {
+ //定义script的正则表达式
+ String regexScript = "