fix comment

This commit is contained in:
Looly
2019-10-09 09:30:22 +08:00
parent a418b5922b
commit b1674a933f
14 changed files with 278 additions and 228 deletions

View File

@@ -30,6 +30,7 @@ public final class ProxyUtil {
* 使用切面代理对象 * 使用切面代理对象
* *
* @param <T> 被代理对象类型 * @param <T> 被代理对象类型
* @param target 被代理对象
* @param aspect 切面对象 * @param aspect 切面对象
* @return 代理对象 * @return 代理对象
*/ */

View File

@@ -18,6 +18,7 @@ public abstract class ProxyFactory implements Serializable{
/** /**
* 创建代理 * 创建代理
* *
* @param <T> 代理对象类型
* @param target 被代理对象 * @param target 被代理对象
* @param aspect 切面实现 * @param aspect 切面实现
* @return 代理对象 * @return 代理对象

View File

@@ -516,6 +516,7 @@ public abstract class AbstractDb implements Serializable {
* *
* @param <T> Bean类型 * @param <T> Bean类型
* @param where 条件实体类(包含表名) * @param where 条件实体类(包含表名)
* @param beanClass 返回的对象类型
* @return 数据对象列表 * @return 数据对象列表
* @throws SQLException SQL执行异常 * @throws SQLException SQL执行异常
* @since 3.2.2 * @since 3.2.2

View File

@@ -142,6 +142,7 @@ public abstract class DSFactory implements Closeable, Serializable{
* 此方法通过“试错”方式查找引入项目的连接池库,按照优先级寻找,一旦寻找到则创建对应的数据源工厂<br> * 此方法通过“试错”方式查找引入项目的连接池库,按照优先级寻找,一旦寻找到则创建对应的数据源工厂<br>
* 连接池优先级Hikari &gt; Druid &gt; Tomcat &gt; Dbcp &gt; C3p0 &gt; Hutool Pooled * 连接池优先级Hikari &gt; Druid &gt; Tomcat &gt; Dbcp &gt; C3p0 &gt; Hutool Pooled
* *
* @param setting 数据库配置项
* @return 日志实现类 * @return 日志实现类
*/ */
public static DSFactory create(Setting setting) { public static DSFactory create(Setting setting) {
@@ -155,6 +156,7 @@ public abstract class DSFactory implements Closeable, Serializable{
* 此方法通过“试错”方式查找引入项目的连接池库,按照优先级寻找,一旦寻找到则创建对应的数据源工厂<br> * 此方法通过“试错”方式查找引入项目的连接池库,按照优先级寻找,一旦寻找到则创建对应的数据源工厂<br>
* 连接池优先级Hikari &gt; Druid &gt; Tomcat &gt; Dbcp &gt; C3p0 &gt; Hutool Pooled * 连接池优先级Hikari &gt; Druid &gt; Tomcat &gt; Dbcp &gt; C3p0 &gt; Hutool Pooled
* *
* @param setting 数据库配置项
* @return 日志实现类 * @return 日志实现类
* @since 4.1.3 * @since 4.1.3
*/ */

View File

@@ -126,7 +126,8 @@ public class EmojiUtil {
* <p> * <p>
* 例如:<code>👦🏿</code> 转换为 <code>:boy|type_6:</code> * 例如:<code>👦🏿</code> 转换为 <code>:boy|type_6:</code>
* *
* @param str 包含Emoji Unicode字符的字符串 * @param str 包含Emoji Unicode字符的字符串
* @param fitzpatrickAction {@link FitzpatrickAction}
* @return 替换后的字符串 * @return 替换后的字符串
*/ */
public static String toAlias(String str, FitzpatrickAction fitzpatrickAction) { public static String toAlias(String str, FitzpatrickAction fitzpatrickAction) {

View File

@@ -35,25 +35,45 @@ import cn.hutool.core.util.StrUtil;
*/ */
public class Mail { public class Mail {
/** 邮箱帐户信息以及一些客户端配置信息 */ /**
* 邮箱帐户信息以及一些客户端配置信息
*/
private MailAccount mailAccount; private MailAccount mailAccount;
/** 收件人列表 */ /**
* 收件人列表
*/
private String[] tos; private String[] tos;
/** 抄送人列表carbon copy */ /**
* 抄送人列表carbon copy
*/
private String[] ccs; private String[] ccs;
/** 密送人列表blind carbon copy */ /**
* 密送人列表blind carbon copy
*/
private String[] bccs; private String[] bccs;
/** 回复地址(reply-to) */ /**
* 回复地址(reply-to)
*/
private String[] reply; private String[] reply;
/** 标题 */ /**
* 标题
*/
private String title; private String title;
/** 内容 */ /**
* 内容
*/
private String content; private String content;
/** 是否为HTML */ /**
* 是否为HTML
*/
private boolean isHtml; private boolean isHtml;
/** 正文、附件和图片的混合部分 */ /**
* 正文、附件和图片的混合部分
*/
private Multipart multipart = new MimeMultipart(); private Multipart multipart = new MimeMultipart();
/** 是否使用全局会话默认为false */ /**
* 是否使用全局会话默认为false
*/
private boolean useGlobalSession = false; private boolean useGlobalSession = false;
/** /**
@@ -76,6 +96,7 @@ public class Mail {
} }
// --------------------------------------------------------------- Constructor start // --------------------------------------------------------------- Constructor start
/** /**
* 构造,使用全局邮件帐户 * 构造,使用全局邮件帐户
*/ */
@@ -95,6 +116,7 @@ public class Mail {
// --------------------------------------------------------------- Constructor end // --------------------------------------------------------------- Constructor end
// --------------------------------------------------------------- Getters and Setters start // --------------------------------------------------------------- Getters and Setters start
/** /**
* 设置收件人 * 设置收件人
* *
@@ -191,7 +213,7 @@ public class Mail {
* 设置正文 * 设置正文
* *
* @param content 正文内容 * @param content 正文内容
* @param isHtml 是否为HTML * @param isHtml 是否为HTML
* @return this * @return this
*/ */
public Mail setContent(String content, boolean isHtml) { public Mail setContent(String content, boolean isHtml) {
@@ -236,7 +258,7 @@ public class Mail {
nameEncoded = InternalMailUtil.encodeText(attachment.getName(), charset); nameEncoded = InternalMailUtil.encodeText(attachment.getName(), charset);
// 普通附件文件名 // 普通附件文件名
bodyPart.setFileName(nameEncoded); bodyPart.setFileName(nameEncoded);
if(StrUtil.startWith(attachment.getContentType(), "image/")) { if (StrUtil.startWith(attachment.getContentType(), "image/")) {
// 图片附件,用于正文中引用图片 // 图片附件,用于正文中引用图片
bodyPart.setContentID(nameEncoded); bodyPart.setContentID(nameEncoded);
} }
@@ -252,8 +274,9 @@ public class Mail {
/** /**
* 增加图片,图片的键对应到邮件模板中的占位字符串,图片类型默认为"image/jpeg" * 增加图片,图片的键对应到邮件模板中的占位字符串,图片类型默认为"image/jpeg"
* *
* @param cid 图片与占位符占位符格式为cid:${cid} * @param cid 图片与占位符占位符格式为cid:${cid}
* @param imageStream 图片文件 * @param imageStream 图片文件
* @return this
* @since 4.6.3 * @since 4.6.3
*/ */
public Mail addImage(String cid, InputStream imageStream) { public Mail addImage(String cid, InputStream imageStream) {
@@ -263,9 +286,10 @@ public class Mail {
/** /**
* 增加图片,图片的键对应到邮件模板中的占位字符串 * 增加图片,图片的键对应到邮件模板中的占位字符串
* *
* @param cid 图片与占位符占位符格式为cid:${cid} * @param cid 图片与占位符占位符格式为cid:${cid}
* @param imageStream 图片流,不关闭 * @param imageStream 图片流,不关闭
* @param contentType 图片类型null赋值默认的"image/jpeg" * @param contentType 图片类型null赋值默认的"image/jpeg"
* @return this
* @since 4.6.3 * @since 4.6.3
*/ */
public Mail addImage(String cid, InputStream imageStream, String contentType) { public Mail addImage(String cid, InputStream imageStream, String contentType) {
@@ -282,13 +306,14 @@ public class Mail {
/** /**
* 增加图片,图片的键对应到邮件模板中的占位字符串 * 增加图片,图片的键对应到邮件模板中的占位字符串
* *
* @param cid 图片与占位符占位符格式为cid:${cid} * @param cid 图片与占位符占位符格式为cid:${cid}
* @param imageFile 图片文件 * @param imageFile 图片文件
* @return this
* @since 4.6.3 * @since 4.6.3
*/ */
public Mail addImage(String cid, File imageFile) { public Mail addImage(String cid, File imageFile) {
InputStream in = null; InputStream in = null;
try{ try {
in = FileUtil.getInputStream(imageFile); in = FileUtil.getInputStream(imageFile);
return addImage(cid, in, FileTypeMap.getDefaultFileTypeMap().getContentType(imageFile)); return addImage(cid, in, FileTypeMap.getDefaultFileTypeMap().getContentType(imageFile));
} finally { } finally {
@@ -336,6 +361,7 @@ public class Mail {
} }
// --------------------------------------------------------------- Private method start // --------------------------------------------------------------- Private method start
/** /**
* 执行发送 * 执行发送
* *

View File

@@ -247,7 +247,7 @@ public class MailAccount implements Serializable {
* *
* <pre> * <pre>
* 1. user@xxx.xx * 1. user@xxx.xx
* 2. name <user@xxx.xx> * 2. name &lt;user@xxx.xx&gt;
* </pre> * </pre>
* *
* @param from 发送方遵循RFC-822标准 * @param from 发送方遵循RFC-822标准
@@ -272,6 +272,7 @@ public class MailAccount implements Serializable {
* 设置是否打开调试模式,调试模式会显示与邮件服务器通信过程,默认不开启 * 设置是否打开调试模式,调试模式会显示与邮件服务器通信过程,默认不开启
* *
* @param debug 是否打开调试模式,调试模式会显示与邮件服务器通信过程,默认不开启 * @param debug 是否打开调试模式,调试模式会显示与邮件服务器通信过程,默认不开启
* @return this
* @since 4.0.2 * @since 4.0.2
*/ */
public MailAccount setDebug(boolean debug) { public MailAccount setDebug(boolean debug) {

View File

@@ -71,7 +71,7 @@ public class ServletUtil {
* @return Map * @return Map
*/ */
public static Map<String, String> getParamMap(ServletRequest request) { public static Map<String, String> getParamMap(ServletRequest request) {
Map<String, String> params = new HashMap<String, String>(); Map<String, String> params = new HashMap<>();
for (Map.Entry<String, String[]> entry : getParams(request).entrySet()) { for (Map.Entry<String, String[]> entry : getParams(request).entrySet()) {
params.put(entry.getKey(), ArrayUtil.join(entry.getValue(), StrUtil.COMMA)); params.put(entry.getKey(), ArrayUtil.join(entry.getValue(), StrUtil.COMMA));
} }
@@ -186,7 +186,6 @@ public class ServletUtil {
* 3、Proxy-Client-IP * 3、Proxy-Client-IP
* 4、WL-Proxy-Client-IP * 4、WL-Proxy-Client-IP
* </pre> * </pre>
* </p>
* *
* <p> * <p>
* otherHeaderNames参数用于自定义检测的Header<br> * otherHeaderNames参数用于自定义检测的Header<br>
@@ -278,7 +277,7 @@ public class ServletUtil {
final Map<String, String> headerMap = new HashMap<>(); final Map<String, String> headerMap = new HashMap<>();
final Enumeration<String> names = request.getHeaderNames(); final Enumeration<String> names = request.getHeaderNames();
String name = null; String name;
while (names.hasMoreElements()) { while (names.hasMoreElements()) {
name = names.nextElement(); name = names.nextElement();
headerMap.put(name, request.getHeader(name)); headerMap.put(name, request.getHeader(name));
@@ -297,7 +296,7 @@ public class ServletUtil {
*/ */
public static String getHeaderIgnoreCase(HttpServletRequest request, String nameIgnoreCase) { public static String getHeaderIgnoreCase(HttpServletRequest request, String nameIgnoreCase) {
final Enumeration<String> names = request.getHeaderNames(); final Enumeration<String> names = request.getHeaderNames();
String name = null; String name;
while (names.hasMoreElements()) { while (names.hasMoreElements()) {
name = names.nextElement(); name = names.nextElement();
if (name != null && name.equalsIgnoreCase(nameIgnoreCase)) { if (name != null && name.equalsIgnoreCase(nameIgnoreCase)) {
@@ -347,9 +346,7 @@ public class ServletUtil {
String userAgent = getHeaderIgnoreCase(request, "User-Agent"); String userAgent = getHeaderIgnoreCase(request, "User-Agent");
if (StrUtil.isNotBlank(userAgent)) { if (StrUtil.isNotBlank(userAgent)) {
userAgent = userAgent.toUpperCase(); userAgent = userAgent.toUpperCase();
if (userAgent.contains("MSIE") || userAgent.contains("TRIDENT")) { return userAgent.contains("MSIE") || userAgent.contains("TRIDENT");
return true;
}
} }
return false; return false;
} }
@@ -389,11 +386,7 @@ public class ServletUtil {
if (StrUtil.isBlank(contentType)) { if (StrUtil.isBlank(contentType)) {
return false; return false;
} }
if (contentType.toLowerCase().startsWith("multipart/")) { return contentType.toLowerCase().startsWith("multipart/");
return true;
}
return false;
} }
// --------------------------------------------------------- Header end // --------------------------------------------------------- Header end
@@ -417,7 +410,7 @@ public class ServletUtil {
* @return Cookie map * @return Cookie map
*/ */
public static Map<String, Cookie> readCookieMap(HttpServletRequest httpServletRequest) { public static Map<String, Cookie> readCookieMap(HttpServletRequest httpServletRequest) {
Map<String, Cookie> cookieMap = new HashMap<String, Cookie>(); Map<String, Cookie> cookieMap = new HashMap<>();
Cookie[] cookies = httpServletRequest.getCookies(); Cookie[] cookies = httpServletRequest.getCookies();
if (null == cookies) { if (null == cookies) {
return null; return null;

View File

@@ -22,7 +22,7 @@ public class MultipartRequestInputStream extends BufferedInputStream {
* 读取byte字节流在末尾抛出异常 * 读取byte字节流在末尾抛出异常
* *
* @return byte * @return byte
* @throws IOException * @throws IOException 读取异常
*/ */
public byte readByte() throws IOException { public byte readByte() throws IOException {
int i = super.read(); int i = super.read();
@@ -53,7 +53,7 @@ public class MultipartRequestInputStream extends BufferedInputStream {
* 输入流中读取边界 * 输入流中读取边界
* *
* @return 边界 * @return 边界
* @throws IOException * @throws IOException 读取异常
*/ */
public byte[] readBoundary() throws IOException { public byte[] readBoundary() throws IOException {
ByteArrayOutputStream boundaryOutput = new ByteArrayOutputStream(1024); ByteArrayOutputStream boundaryOutput = new ByteArrayOutputStream(1024);
@@ -91,7 +91,7 @@ public class MultipartRequestInputStream extends BufferedInputStream {
* *
* @param encoding 字符集 * @param encoding 字符集
* @return 头部信息, 如果达到末尾则返回null * @return 头部信息, 如果达到末尾则返回null
* @throws IOException * @throws IOException 读取异常
*/ */
public UploadFileHeader readDataHeader(String encoding) throws IOException { public UploadFileHeader readDataHeader(String encoding) throws IOException {
String dataHeader = readDataHeaderString(encoding); String dataHeader = readDataHeaderString(encoding);
@@ -136,7 +136,7 @@ public class MultipartRequestInputStream extends BufferedInputStream {
* *
* @param out 输出流 * @param out 输出流
* @return 复制的字节数 * @return 复制的字节数
* @throws IOException * @throws IOException 读取异常
*/ */
public int copy(OutputStream out) throws IOException { public int copy(OutputStream out) throws IOException {
int count = 0; int count = 0;
@@ -157,7 +157,7 @@ public class MultipartRequestInputStream extends BufferedInputStream {
* @param out 输出流 * @param out 输出流
* @param limit 最大字节数 * @param limit 最大字节数
* @return 复制的字节数 * @return 复制的字节数
* @throws IOException * @throws IOException 读取异常
*/ */
public int copy(OutputStream out, int limit) throws IOException { public int copy(OutputStream out, int limit) throws IOException {
int count = 0; int count = 0;
@@ -195,7 +195,7 @@ public class MultipartRequestInputStream extends BufferedInputStream {
/** /**
* @param b byte * @param b byte
* @return 是否为边界的标志 * @return 是否为边界的标志
* @throws IOException * @throws IOException 读取异常
*/ */
public boolean isBoundary(byte b) throws IOException { public boolean isBoundary(byte b) throws IOException {
int boundaryLen = boundary.length; int boundaryLen = boundary.length;

View File

@@ -81,6 +81,7 @@ public class UploadFile {
* 将上传的文件写入目标文件<br> * 将上传的文件写入目标文件<br>
* 写入后原临时文件会被删除 * 写入后原临时文件会被删除
* *
* @param destination 目标文件
* @return 目标文件 * @return 目标文件
*/ */
public File write(File destination) throws IOException { public File write(File destination) throws IOException {
@@ -151,7 +152,7 @@ public class UploadFile {
// ---------------------------------------------------------------- properties // ---------------------------------------------------------------- properties
/** /**
* @return 上传文件的大小,< 0 表示未上传 * @return 上传文件的大小,&gt; 0 表示未上传
*/ */
public int size() { public int size() {
return size; return size;
@@ -176,6 +177,7 @@ public class UploadFile {
* 处理上传表单流,提取出文件 * 处理上传表单流,提取出文件
* *
* @param input 上传表单的流 * @param input 上传表单的流
* @return 是否成功
* @throws IOException IO异常 * @throws IOException IO异常
*/ */
protected boolean processStream(MultipartRequestInputStream input) throws IOException { protected boolean processStream(MultipartRequestInputStream input) throws IOException {

View File

@@ -32,27 +32,35 @@ public class UploadFileHeader {
/** /**
* Returns <code>true</code> if uploaded data are correctly marked as a file. This is true if header contains string 'filename'. * Returns <code>true</code> if uploaded data are correctly marked as a file. This is true if header contains string 'filename'.
*
* @return 是否为文件
*/ */
public boolean isFile() { public boolean isFile() {
return isFile; return isFile;
} }
/** /**
* Returns form field name. * 返回表单字段名
*
* @return 表单字段名
*/ */
public String getFormFieldName() { public String getFormFieldName() {
return formFieldName; return formFieldName;
} }
/** /**
* Returns complete file name as specified at client side. * 返回表单中的文件名,来自客户端传入
*
* @return 表单文件名
*/ */
public String getFormFileName() { public String getFormFileName() {
return formFileName; return formFileName;
} }
/** /**
* Returns file name (base name and extension, without full path data). * 获取文件名,不包括路径
*
* @return 文件名
*/ */
public String getFileName() { public String getFileName() {
return fileName; return fileName;
@@ -62,6 +70,7 @@ public class UploadFileHeader {
* Returns uploaded content type. It is usually in the following form:<br> * Returns uploaded content type. It is usually in the following form:<br>
* mime_type/mime_subtype. * mime_type/mime_subtype.
* *
* @return content type
* @see #getMimeType() * @see #getMimeType()
* @see #getMimeSubtype() * @see #getMimeSubtype()
*/ */
@@ -71,6 +80,8 @@ public class UploadFileHeader {
/** /**
* Returns file types MIME. * Returns file types MIME.
*
* @return types MIME
*/ */
public String getMimeType() { public String getMimeType() {
return mimeType; return mimeType;
@@ -78,6 +89,8 @@ public class UploadFileHeader {
/** /**
* Returns file sub type MIME. * Returns file sub type MIME.
*
* @return sub type MIME
*/ */
public String getMimeSubtype() { public String getMimeSubtype() {
return mimeSubtype; return mimeSubtype;
@@ -85,6 +98,8 @@ public class UploadFileHeader {
/** /**
* Returns content disposition. Usually it is 'form-data'. * Returns content disposition. Usually it is 'form-data'.
*
* @return content disposition
*/ */
public String getContentDisposition() { public String getContentDisposition() {
return contentDisposition; return contentDisposition;
@@ -96,7 +111,7 @@ public class UploadFileHeader {
* 获得头信息字符串字符串中指定的值 * 获得头信息字符串字符串中指定的值
* *
* @param dataHeader 头信息 * @param dataHeader 头信息
* @param fieldName 字段名 * @param fieldName 字段名
* @return 字段值 * @return 字段值
*/ */
private String getDataFieldValue(String dataHeader, String fieldName) { private String getDataFieldValue(String dataHeader, String fieldName) {
@@ -154,7 +169,8 @@ public class UploadFileHeader {
/** /**
* 处理头字符串,使之转化为字段 * 处理头字符串,使之转化为字段
* @param dataHeader *
* @param dataHeader 头字符串
*/ */
private void processHeaderString(String dataHeader) { private void processHeaderString(String dataHeader) {
isFile = dataHeader.indexOf("filename") > 0; isFile = dataHeader.indexOf("filename") > 0;

View File

@@ -56,8 +56,8 @@ public class JSONConverter implements Converter<JSON> {
/** /**
* JSON递归转换<br> * JSON递归转换<br>
* 首先尝试JDK类型转换如果失败尝试JSON转Bean * 首先尝试JDK类型转换如果失败尝试JSON转Bean
* @param <T>
* *
* @param <T> 转换后的对象类型
* @param targetType 目标类型 * @param targetType 目标类型
* @param value 值 * @param value 值
* @param ignoreError 是否忽略转换错误 * @param ignoreError 是否忽略转换错误

View File

@@ -33,11 +33,11 @@ import cn.hutool.json.serialize.JSONSerializer;
* JSON工具类 * JSON工具类
* *
* @author Looly * @author Looly
*
*/ */
public final class JSONUtil { public final class JSONUtil {
// -------------------------------------------------------------------- Pause start // -------------------------------------------------------------------- Pause start
/** /**
* 创建JSONObject * 创建JSONObject
* *
@@ -80,7 +80,7 @@ public final class JSONUtil {
/** /**
* JSON字符串转JSONObject对象 * JSON字符串转JSONObject对象
* *
* @param obj Bean对象或者Map * @param obj Bean对象或者Map
* @param ignoreNullValue 是否忽略空值如果source为JSON字符串不忽略空值 * @param ignoreNullValue 是否忽略空值如果source为JSON字符串不忽略空值
* @return JSONObject * @return JSONObject
* @since 3.0.9 * @since 3.0.9
@@ -92,9 +92,9 @@ public final class JSONUtil {
/** /**
* JSON字符串转JSONObject对象 * JSON字符串转JSONObject对象
* *
* @param obj Bean对象或者Map * @param obj Bean对象或者Map
* @param ignoreNullValue 是否忽略空值如果source为JSON字符串不忽略空值 * @param ignoreNullValue 是否忽略空值如果source为JSON字符串不忽略空值
* @param isOrder 是否有序 * @param isOrder 是否有序
* @return JSONObject * @return JSONObject
* @since 4.2.2 * @since 4.2.2
*/ */
@@ -127,7 +127,7 @@ public final class JSONUtil {
* JSON字符串转JSONArray * JSON字符串转JSONArray
* *
* @param arrayOrCollection 数组或集合对象 * @param arrayOrCollection 数组或集合对象
* @param ignoreNullValue 是否忽略空值 * @param ignoreNullValue 是否忽略空值
* @return JSONArray * @return JSONArray
* @since 3.2.3 * @since 3.2.3
*/ */
@@ -209,10 +209,11 @@ public final class JSONUtil {
// -------------------------------------------------------------------- Pause end // -------------------------------------------------------------------- Pause end
// -------------------------------------------------------------------- Read start // -------------------------------------------------------------------- Read start
/** /**
* 读取JSON * 读取JSON
* *
* @param file JSON文件 * @param file JSON文件
* @param charset 编码 * @param charset 编码
* @return JSON包括JSONObject和JSONArray * @return JSON包括JSONObject和JSONArray
* @throws IORuntimeException IO异常 * @throws IORuntimeException IO异常
@@ -224,7 +225,7 @@ public final class JSONUtil {
/** /**
* 读取JSONObject * 读取JSONObject
* *
* @param file JSON文件 * @param file JSON文件
* @param charset 编码 * @param charset 编码
* @return JSONObject * @return JSONObject
* @throws IORuntimeException IO异常 * @throws IORuntimeException IO异常
@@ -236,7 +237,7 @@ public final class JSONUtil {
/** /**
* 读取JSONArray * 读取JSONArray
* *
* @param file JSON文件 * @param file JSON文件
* @param charset 编码 * @param charset 编码
* @return JSONArray * @return JSONArray
* @throws IORuntimeException IO异常 * @throws IORuntimeException IO异常
@@ -247,10 +248,11 @@ public final class JSONUtil {
// -------------------------------------------------------------------- Read end // -------------------------------------------------------------------- Read end
// -------------------------------------------------------------------- toString start // -------------------------------------------------------------------- toString start
/** /**
* 转为JSON字符串 * 转为JSON字符串
* *
* @param json JSON * @param json JSON
* @param indentFactor 每一级别的缩进 * @param indentFactor 每一级别的缩进
* @return JSON字符串 * @return JSON字符串
*/ */
@@ -329,9 +331,9 @@ public final class JSONUtil {
/** /**
* JSON字符串转为实体类对象转换异常将被抛出 * JSON字符串转为实体类对象转换异常将被抛出
* *
* @param <T> Bean类型 * @param <T> Bean类型
* @param jsonString JSON字符串 * @param jsonString JSON字符串
* @param beanClass 实体类对象 * @param beanClass 实体类对象
* @return 实体类对象 * @return 实体类对象
* @since 3.1.2 * @since 3.1.2
*/ */
@@ -342,8 +344,8 @@ public final class JSONUtil {
/** /**
* 转为实体类对象,转换异常将被抛出 * 转为实体类对象,转换异常将被抛出
* *
* @param <T> Bean类型 * @param <T> Bean类型
* @param json JSONObject * @param json JSONObject
* @param beanClass 实体类对象 * @param beanClass 实体类对象
* @return 实体类对象 * @return 实体类对象
*/ */
@@ -354,9 +356,10 @@ public final class JSONUtil {
/** /**
* JSON字符串转为实体类对象转换异常将被抛出 * JSON字符串转为实体类对象转换异常将被抛出
* *
* @param <T> Bean类型 * @param <T> Bean类型
* @param jsonString JSON字符串 * @param jsonString JSON字符串
* @param typeReference {@link TypeReference}类型参考子类可以获取其泛型参数中的Type类型 * @param typeReference {@link TypeReference}类型参考子类可以获取其泛型参数中的Type类型
* @param ignoreError 是否忽略错误
* @return 实体类对象 * @return 实体类对象
* @since 4.3.2 * @since 4.3.2
*/ */
@@ -367,9 +370,10 @@ public final class JSONUtil {
/** /**
* JSON字符串转为实体类对象转换异常将被抛出 * JSON字符串转为实体类对象转换异常将被抛出
* *
* @param <T> Bean类型 * @param <T> Bean类型
* @param jsonString JSON字符串 * @param jsonString JSON字符串
* @param beanType 实体类对象类型 * @param beanType 实体类对象类型
* @param ignoreError 是否忽略错误
* @return 实体类对象 * @return 实体类对象
* @since 4.3.2 * @since 4.3.2
*/ */
@@ -380,10 +384,10 @@ public final class JSONUtil {
/** /**
* 转为实体类对象 * 转为实体类对象
* *
* @param <T> Bean类型 * @param <T> Bean类型
* @param json JSONObject * @param json JSONObject
* @param typeReference {@link TypeReference}类型参考子类可以获取其泛型参数中的Type类型 * @param typeReference {@link TypeReference}类型参考子类可以获取其泛型参数中的Type类型
* @param ignoreError 是否忽略转换错误 * @param ignoreError 是否忽略转换错误
* @return 实体类对象 * @return 实体类对象
* @since 4.6.2 * @since 4.6.2
*/ */
@@ -394,9 +398,9 @@ public final class JSONUtil {
/** /**
* 转为实体类对象 * 转为实体类对象
* *
* @param <T> Bean类型 * @param <T> Bean类型
* @param json JSONObject * @param json JSONObject
* @param beanType 实体类对象类型 * @param beanType 实体类对象类型
* @param ignoreError 是否忽略转换错误 * @param ignoreError 是否忽略转换错误
* @return 实体类对象 * @return 实体类对象
* @since 4.3.2 * @since 4.3.2
@@ -412,7 +416,8 @@ public final class JSONUtil {
/** /**
* 将JSONArray转换为Bean的List默认为ArrayList * 将JSONArray转换为Bean的List默认为ArrayList
* *
* @param jsonArray JSONArray * @param <T> Bean类型
* @param jsonArray JSONArray
* @param elementType List中元素类型 * @param elementType List中元素类型
* @return List * @return List
* @since 4.0.7 * @since 4.0.7
@@ -427,7 +432,7 @@ public final class JSONUtil {
* <li>.表达式可以获取Bean对象中的属性字段值或者Map中key对应的值</li> * <li>.表达式可以获取Bean对象中的属性字段值或者Map中key对应的值</li>
* <li>[]表达式可以获取集合等对象中对应index的值</li> * <li>[]表达式可以获取集合等对象中对应index的值</li>
* </ol> * </ol>
* * <p>
* 表达式栗子: * 表达式栗子:
* *
* <pre> * <pre>
@@ -437,7 +442,7 @@ public final class JSONUtil {
* person.friends[5].name * person.friends[5].name
* </pre> * </pre>
* *
* @param json {@link JSON} * @param json {@link JSON}
* @param expression 表达式 * @param expression 表达式
* @return 对象 * @return 对象
* @see JSON#getByPath(String) * @see JSON#getByPath(String)
@@ -454,7 +459,7 @@ public final class JSONUtil {
* <li>.表达式可以获取Bean对象中的属性字段值或者Map中key对应的值</li> * <li>.表达式可以获取Bean对象中的属性字段值或者Map中key对应的值</li>
* <li>[]表达式可以获取集合等对象中对应index的值</li> * <li>[]表达式可以获取集合等对象中对应index的值</li>
* </ol> * </ol>
* * <p>
* 表达式栗子: * 表达式栗子:
* *
* <pre> * <pre>
@@ -464,9 +469,9 @@ public final class JSONUtil {
* person.friends[5].name * person.friends[5].name
* </pre> * </pre>
* *
* @param json JSON可以为JSONObject或JSONArray * @param json JSON可以为JSONObject或JSONArray
* @param expression 表达式 * @param expression 表达式
* @param value 值 * @param value
*/ */
public static void putByPath(JSON json, String expression, Object value) { public static void putByPath(JSON json, String expression, Object value) {
json.putByPath(expression, value); json.putByPath(expression, value);
@@ -509,7 +514,7 @@ public final class JSONUtil {
* 为了能在HTML中较好的显示会将&lt;/转义为&lt;\/<br> * 为了能在HTML中较好的显示会将&lt;/转义为&lt;\/<br>
* JSON字符串中不能包含控制字符和未经转义的引号和反斜杠 * JSON字符串中不能包含控制字符和未经转义的引号和反斜杠
* *
* @param str 字符串 * @param str 字符串
* @param writer Writer * @param writer Writer
* @return Writer * @return Writer
* @throws IOException IO异常 * @throws IOException IO异常
@@ -523,7 +528,7 @@ public final class JSONUtil {
* 为了能在HTML中较好的显示会将&lt;/转义为&lt;\/<br> * 为了能在HTML中较好的显示会将&lt;/转义为&lt;\/<br>
* JSON字符串中不能包含控制字符和未经转义的引号和反斜杠 * JSON字符串中不能包含控制字符和未经转义的引号和反斜杠
* *
* @param str 字符串 * @param str 字符串
* @param writer Writer * @param writer Writer
* @param isWrap 是否使用双引号包装字符串 * @param isWrap 是否使用双引号包装字符串
* @return Writer * @return Writer
@@ -548,19 +553,19 @@ public final class JSONUtil {
b = c; b = c;
c = str.charAt(i); c = str.charAt(i);
switch (c) { switch (c) {
case '\\': case '\\':
case '"': case '"':
writer.write("\\"); writer.write("\\");
writer.write(c); writer.write(c);
break; break;
case '/': case '/':
if (b == '<') { if (b == '<') {
writer.write('\\'); writer.write('\\');
} }
writer.write(c); writer.write(c);
break; break;
default: default:
writer.write(escape(c)); writer.write(escape(c));
} }
} }
if (isWrap) { if (isWrap) {
@@ -602,11 +607,11 @@ public final class JSONUtil {
* <li>其它 =》 尝试包装为JSONObject否则返回<code>null</code></li> * <li>其它 =》 尝试包装为JSONObject否则返回<code>null</code></li>
* </ul> * </ul>
* *
* @param object 被包装的对象 * @param object 被包装的对象
* @param jsonConfig JSON选项 * @param jsonConfig JSON选项
* @return 包装后的值null表示此值需被忽略 * @return 包装后的值null表示此值需被忽略
*/ */
@SuppressWarnings({ "rawtypes", "unchecked" }) @SuppressWarnings({"rawtypes", "unchecked"})
public static Object wrap(Object object, JSONConfig jsonConfig) { public static Object wrap(Object object, JSONConfig jsonConfig) {
if (object == null) { if (object == null) {
return jsonConfig.isIgnoreNullValue() ? null : JSONNull.NULL; return jsonConfig.isIgnoreNullValue() ? null : JSONNull.NULL;
@@ -623,12 +628,12 @@ public final class JSONUtil {
// 自定义序列化 // 自定义序列化
final JSONSerializer serializer = GlobalSerializeMapping.getSerializer(object.getClass()); final JSONSerializer serializer = GlobalSerializeMapping.getSerializer(object.getClass());
if(null != serializer) { if (null != serializer) {
final Type jsonType = TypeUtil.getTypeArgument(serializer.getClass()); final Type jsonType = TypeUtil.getTypeArgument(serializer.getClass());
if(null != jsonType) { if (null != jsonType) {
if(serializer instanceof JSONObjectSerializer) { if (serializer instanceof JSONObjectSerializer) {
serializer.serialize(new JSONObject(jsonConfig), object); serializer.serialize(new JSONObject(jsonConfig), object);
} else if(serializer instanceof JSONArraySerializer) { } else if (serializer instanceof JSONArraySerializer) {
serializer.serialize(new JSONArray(jsonConfig), object); serializer.serialize(new JSONArray(jsonConfig), object);
} }
} }
@@ -654,7 +659,7 @@ public final class JSONUtil {
} }
// Java内部类不做转换 // Java内部类不做转换
if(ClassUtil.isJdkClass(object.getClass())) { if (ClassUtil.isJdkClass(object.getClass())) {
return object.toString(); return object.toString();
} }
@@ -746,7 +751,7 @@ public final class JSONUtil {
/** /**
* 加入自定义的序列化器 * 加入自定义的序列化器
* *
* @param type 对象类型 * @param type 对象类型
* @param serializer 序列化器实现 * @param serializer 序列化器实现
* @see GlobalSerializeMapping#put(Type, JSONArraySerializer) * @see GlobalSerializeMapping#put(Type, JSONArraySerializer)
* @since 4.6.5 * @since 4.6.5
@@ -758,7 +763,7 @@ public final class JSONUtil {
/** /**
* 加入自定义的序列化器 * 加入自定义的序列化器
* *
* @param type 对象类型 * @param type 对象类型
* @param serializer 序列化器实现 * @param serializer 序列化器实现
* @see GlobalSerializeMapping#put(Type, JSONObjectSerializer) * @see GlobalSerializeMapping#put(Type, JSONObjectSerializer)
* @since 4.6.5 * @since 4.6.5
@@ -770,7 +775,7 @@ public final class JSONUtil {
/** /**
* 加入自定义的反序列化器 * 加入自定义的反序列化器
* *
* @param type 对象类型 * @param type 对象类型
* @param deserializer 反序列化器实现 * @param deserializer 反序列化器实现
* @see GlobalSerializeMapping#put(Type, JSONDeserializer) * @see GlobalSerializeMapping#put(Type, JSONDeserializer)
* @since 4.6.5 * @since 4.6.5
@@ -780,6 +785,7 @@ public final class JSONUtil {
} }
// --------------------------------------------------------------------------------------------- Private method start // --------------------------------------------------------------------------------------------- Private method start
/** /**
* 转义不可见字符<br> * 转义不可见字符<br>
* 见https://en.wikibooks.org/wiki/Unicode/Character_reference/0000-0FFF * 见https://en.wikibooks.org/wiki/Unicode/Character_reference/0000-0FFF
@@ -789,27 +795,27 @@ public final class JSONUtil {
*/ */
private static String escape(char c) { private static String escape(char c) {
switch (c) { switch (c) {
case '\b': case '\b':
return "\\b"; return "\\b";
case '\t': case '\t':
return "\\t"; return "\\t";
case '\n': case '\n':
return "\\n"; return "\\n";
case '\f': case '\f':
return "\\f"; return "\\f";
case '\r': case '\r':
return "\\r"; return "\\r";
default: default:
if (c < StrUtil.C_SPACE || // if (c < StrUtil.C_SPACE || //
(c >= '\u0080' && c <= '\u00a0') || // (c >= '\u0080' && c <= '\u00a0') || //
(c >= '\u2000' && c <= '\u2010') || // (c >= '\u2000' && c <= '\u2010') || //
(c >= '\u2028' && c <= '\u202F') || // (c >= '\u2028' && c <= '\u202F') || //
(c >= '\u2066' && c <= '\u206F')// (c >= '\u2066' && c <= '\u206F')//
) { ) {
return HexUtil.toUnicodeHex(c); return HexUtil.toUnicodeHex(c);
} else { } else {
return Character.toString(c); return Character.toString(c);
} }
} }
} }
// --------------------------------------------------------------------------------------------- Private method end // --------------------------------------------------------------------------------------------- Private method end

View File

@@ -99,7 +99,7 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
/** /**
* 构造使用相对于Class文件根目录的相对路径 * 构造使用相对于Class文件根目录的相对路径
* *
* @param path * @param path 配置文件路径相对于ClassPath或者使用绝对路径
*/ */
public Props(String path) { public Props(String path) {
this(path, CharsetUtil.CHARSET_ISO_8859_1); this(path, CharsetUtil.CHARSET_ISO_8859_1);