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 target 被代理对象
* @param aspect 切面对象
* @return 代理对象
*/

View File

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

View File

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

View File

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

View File

@ -14,7 +14,7 @@ import com.vdurmont.emoji.EmojiParser.FitzpatrickAction;
* 基于<a href=https://github.com/vdurmont/emoji-java>emoji-java</a>的Emoji表情工具类
* <p>
* emoji-java文档以及别名列表见<a href="https://github.com/vdurmont/emoji-java">https://github.com/vdurmont/emoji-java</a>
*
*
* @author looly
* @since 4.2.1
*/
@ -22,7 +22,7 @@ public class EmojiUtil {
/**
* 是否为Emoji表情的Unicode符
*
*
* @param str 被测试的字符串
* @return 是否为Emoji表情的Unicode符
*/
@ -32,7 +32,7 @@ public class EmojiUtil {
/**
* 是否包含Emoji表情的Unicode符
*
*
* @param str 被测试的字符串
* @return 是否包含Emoji表情的Unicode符
* @since 4.5.11
@ -58,7 +58,7 @@ public class EmojiUtil {
/**
* 通过tag方式获取对应的所有Emoji表情
*
*
* @param tag tag标签例如happy
* @return Emoji表情集合如果找不到返回null
*/
@ -68,7 +68,7 @@ public class EmojiUtil {
/**
* 通过别名获取Emoji
*
*
* @param alias 别名例如smile
* @return Emoji对象如果找不到返回null
*/
@ -80,13 +80,13 @@ public class EmojiUtil {
* 将子串中的Emoji别名两个":"包围的格式和其HTML表示形式替换为为Unicode Emoji符号
* <p>
* 例如
*
*
* <pre>
* <code>:smile:</code> 替换为 <code>😄</code>
* <code>&amp;#128516;</code> 替换为 <code>😄</code>
* <code>:boy|type_6:</code> 替换为 <code>👦🏿</code>
* </pre>
*
*
* @param str 包含Emoji别名或者HTML表现形式的字符串
* @return 替换后的字符串
*/
@ -98,22 +98,22 @@ public class EmojiUtil {
* 将字符串中的Unicode Emoji字符转换为别名表现形式两个":"包围的格式
* <p>
* 例如 <code>😄</code> 转换为 <code>:smile:</code>
*
*
* <p>
* {@link FitzpatrickAction}参数被设置为{@link FitzpatrickAction#PARSE}则别名后会增加"|"并追加fitzpatrick类型
* <p>
* 例如<code>👦🏿</code> 转换为 <code>:boy|type_6:</code>
*
*
* <p>
* {@link FitzpatrickAction}参数被设置为{@link FitzpatrickAction#REMOVE}则别名后的"|"和类型将被去除
* <p>
* 例如<code>👦🏿</code> 转换为 <code>:boy:</code>
*
*
* <p>
* {@link FitzpatrickAction}参数被设置为{@link FitzpatrickAction#IGNORE}则别名后的类型将被忽略
* <p>
* 例如<code>👦🏿</code> 转换为 <code>:boy:🏿</code>
*
*
* @param str 包含Emoji Unicode字符的字符串
* @return 替换后的字符串
*/
@ -125,8 +125,9 @@ public class EmojiUtil {
* 将字符串中的Unicode Emoji字符转换为别名表现形式两个":"包围的格式别名后会增加"|"并追加fitzpatrick类型
* <p>
* 例如<code>👦🏿</code> 转换为 <code>:boy|type_6:</code>
*
* @param str 包含Emoji Unicode字符的字符串
*
* @param str 包含Emoji Unicode字符的字符串
* @param fitzpatrickAction {@link FitzpatrickAction}
* @return 替换后的字符串
*/
public static String toAlias(String str, FitzpatrickAction fitzpatrickAction) {
@ -137,7 +138,7 @@ public class EmojiUtil {
* 将字符串中的Unicode Emoji字符转换为HTML 16进制表现形式
* <p>
* 例如<code>👦🏿</code> 转换为 <code>&amp;#x1f466;</code>
*
*
* @param str 包含Emoji Unicode字符的字符串
* @return 替换后的字符串
*/
@ -149,7 +150,7 @@ public class EmojiUtil {
* 将字符串中的Unicode Emoji字符转换为HTML表现形式
* <p>
* 例如<code>👦🏿</code> 转换为 <code>&amp;#128102;</code>
*
*
* @param str 包含Emoji Unicode字符的字符串
* @return 替换后的字符串
*/
@ -159,7 +160,7 @@ public class EmojiUtil {
/**
* 去除字符串中所有的Emoji Unicode字符
*
*
* @param str 包含Emoji字符的字符串
* @return 替换后的字符串
*/
@ -169,7 +170,7 @@ public class EmojiUtil {
/**
* 提取字符串中所有的Emoji Unicode
*
*
* @param str 包含Emoji字符的字符串
* @return Emoji字符列表
*/

View File

@ -29,36 +29,56 @@ import cn.hutool.core.util.StrUtil;
/**
* 邮件发送客户端
*
*
* @author looly
* @since 3.2.0
*/
public class Mail {
/** 邮箱帐户信息以及一些客户端配置信息 */
/**
* 邮箱帐户信息以及一些客户端配置信息
*/
private MailAccount mailAccount;
/** 收件人列表 */
/**
* 收件人列表
*/
private String[] tos;
/** 抄送人列表carbon copy */
/**
* 抄送人列表carbon copy
*/
private String[] ccs;
/** 密送人列表blind carbon copy */
/**
* 密送人列表blind carbon copy
*/
private String[] bccs;
/** 回复地址(reply-to) */
/**
* 回复地址(reply-to)
*/
private String[] reply;
/** 标题 */
/**
* 标题
*/
private String title;
/** 内容 */
/**
* 内容
*/
private String content;
/** 是否为HTML */
/**
* 是否为HTML
*/
private boolean isHtml;
/** 正文、附件和图片的混合部分 */
/**
* 正文附件和图片的混合部分
*/
private Multipart multipart = new MimeMultipart();
/** 是否使用全局会话默认为false */
/**
* 是否使用全局会话默认为false
*/
private boolean useGlobalSession = false;
/**
* 创建邮件客户端
*
*
* @param mailAccount 邮件帐号
* @return {@link Mail}
*/
@ -68,7 +88,7 @@ public class Mail {
/**
* 创建邮件客户端使用全局邮件帐户
*
*
* @return {@link Mail}
*/
public static Mail create() {
@ -76,6 +96,7 @@ public class Mail {
}
// --------------------------------------------------------------- Constructor start
/**
* 构造使用全局邮件帐户
*/
@ -85,7 +106,7 @@ public class Mail {
/**
* 构造
*
*
* @param mailAccount 邮件帐户如果为null使用默认配置文件的全局邮件配置
*/
public Mail(MailAccount mailAccount) {
@ -95,9 +116,10 @@ public class Mail {
// --------------------------------------------------------------- Constructor end
// --------------------------------------------------------------- Getters and Setters start
/**
* 设置收件人
*
*
* @param tos 收件人列表
* @return this
* @see #setTos(String...)
@ -108,7 +130,7 @@ public class Mail {
/**
* 设置多个收件人
*
*
* @param tos 收件人列表
* @return this
*/
@ -119,7 +141,7 @@ public class Mail {
/**
* 设置多个抄送人carbon copy
*
*
* @param ccs 抄送人列表
* @return this
* @since 4.0.3
@ -131,7 +153,7 @@ public class Mail {
/**
* 设置多个密送人blind carbon copy
*
*
* @param bccs 密送人列表
* @return this
* @since 4.0.3
@ -143,7 +165,7 @@ public class Mail {
/**
* 设置多个回复地址(reply-to)
*
*
* @param reply 回复地址(reply-to)列表
* @return this
* @since 4.6.0
@ -155,7 +177,7 @@ public class Mail {
/**
* 设置标题
*
*
* @param title 标题
* @return this
*/
@ -167,7 +189,7 @@ public class Mail {
/**
* 设置正文<br>
* 正文可以是普通文本也可以是HTML默认普通文本可以通过调用{@link #setHtml(boolean)} 设置是否为HTML
*
*
* @param content 正文
* @return this
*/
@ -178,7 +200,7 @@ public class Mail {
/**
* 设置是否是HTML
*
*
* @param isHtml 是否为HTML
* @return this
*/
@ -186,12 +208,12 @@ public class Mail {
this.isHtml = isHtml;
return this;
}
/**
* 设置正文
*
*
* @param content 正文内容
* @param isHtml 是否为HTML
* @param isHtml 是否为HTML
* @return this
*/
public Mail setContent(String content, boolean isHtml) {
@ -201,7 +223,7 @@ public class Mail {
/**
* 设置文件类型附件文件可以是图片文件此时自动设置cid正文中引用图片默认cid为文件名
*
*
* @param files 附件文件列表
* @return this
*/
@ -219,7 +241,7 @@ public class Mail {
/**
* 增加附件或图片附件使用{@link DataSource} 形式表示可以使用{@link FileDataSource}包装文件表示文件附件
*
*
* @param attachments 附件列表
* @return this
* @since 4.0.9
@ -236,7 +258,7 @@ public class Mail {
nameEncoded = InternalMailUtil.encodeText(attachment.getName(), charset);
// 普通附件文件名
bodyPart.setFileName(nameEncoded);
if(StrUtil.startWith(attachment.getContentType(), "image/")) {
if (StrUtil.startWith(attachment.getContentType(), "image/")) {
// 图片附件用于正文中引用图片
bodyPart.setContentID(nameEncoded);
}
@ -248,24 +270,26 @@ public class Mail {
}
return this;
}
/**
* 增加图片图片的键对应到邮件模板中的占位字符串图片类型默认为"image/jpeg"
*
* @param cid 图片与占位符占位符格式为cid:${cid}
* @param cid 图片与占位符占位符格式为cid:${cid}
* @param imageStream 图片文件
* @return this
* @since 4.6.3
*/
public Mail addImage(String cid, InputStream imageStream) {
return addImage(cid, imageStream, null);
}
/**
* 增加图片图片的键对应到邮件模板中的占位字符串
*
* @param cid 图片与占位符占位符格式为cid:${cid}
* @param cid 图片与占位符占位符格式为cid:${cid}
* @param imageStream 图片流不关闭
* @param contentType 图片类型null赋值默认的"image/jpeg"
* @return this
* @since 4.6.3
*/
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 图片文件
* @return this
* @since 4.6.3
*/
public Mail addImage(String cid, File imageFile) {
InputStream in = null;
try{
try {
in = FileUtil.getInputStream(imageFile);
return addImage(cid, in, FileTypeMap.getDefaultFileTypeMap().getContentType(imageFile));
} finally {
@ -298,7 +323,7 @@ public class Mail {
/**
* 设置字符集编码
*
*
* @param charset 字符集编码
* @return this
* @see MailAccount#setCharset(Charset)
@ -310,7 +335,7 @@ public class Mail {
/**
* 设置是否使用全局会话默认为true
*
*
* @param isUseGlobalSession 是否使用全局会话默认为true
* @return this
* @since 4.0.2
@ -323,7 +348,7 @@ public class Mail {
/**
* 发送
*
*
* @return this
* @throws MailException 邮件发送异常
*/
@ -336,9 +361,10 @@ public class Mail {
}
// --------------------------------------------------------------- Private method start
/**
* 执行发送
*
*
* @return this
* @throws MessagingException 发送异常
*/
@ -349,7 +375,7 @@ public class Mail {
/**
* 构建消息
*
*
* @return {@link MimeMessage}消息
* @throws MessagingException 消息异常
*/
@ -390,7 +416,7 @@ public class Mail {
/**
* 构建邮件信息主体
*
*
* @param charset 编码
* @return 邮件信息主体
* @throws MessagingException 消息异常
@ -407,7 +433,7 @@ public class Mail {
/**
* 获取默认邮件会话<br>
* 如果为全局单例的会话则全局只允许一个邮件帐号否则每次发送邮件会新建一个新的会话
*
*
* @param isSingleton 是否使用单例Session
* @return 邮件会话 {@link Session}
* @since 4.0.2

View File

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

View File

@ -71,7 +71,7 @@ public class ServletUtil {
* @return Map
*/
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()) {
params.put(entry.getKey(), ArrayUtil.join(entry.getValue(), StrUtil.COMMA));
}
@ -186,8 +186,7 @@ public class ServletUtil {
* 3Proxy-Client-IP
* 4WL-Proxy-Client-IP
* </pre>
* </p>
*
*
* <p>
* otherHeaderNames参数用于自定义检测的Header<br>
* 需要注意的是使用此方法获取的客户IP地址必须在Http服务器例如Nginx中配置头信息否则容易造成IP伪造
@ -278,7 +277,7 @@ public class ServletUtil {
final Map<String, String> headerMap = new HashMap<>();
final Enumeration<String> names = request.getHeaderNames();
String name = null;
String name;
while (names.hasMoreElements()) {
name = names.nextElement();
headerMap.put(name, request.getHeader(name));
@ -297,7 +296,7 @@ public class ServletUtil {
*/
public static String getHeaderIgnoreCase(HttpServletRequest request, String nameIgnoreCase) {
final Enumeration<String> names = request.getHeaderNames();
String name = null;
String name;
while (names.hasMoreElements()) {
name = names.nextElement();
if (name != null && name.equalsIgnoreCase(nameIgnoreCase)) {
@ -347,9 +346,7 @@ public class ServletUtil {
String userAgent = getHeaderIgnoreCase(request, "User-Agent");
if (StrUtil.isNotBlank(userAgent)) {
userAgent = userAgent.toUpperCase();
if (userAgent.contains("MSIE") || userAgent.contains("TRIDENT")) {
return true;
}
return userAgent.contains("MSIE") || userAgent.contains("TRIDENT");
}
return false;
}
@ -389,11 +386,7 @@ public class ServletUtil {
if (StrUtil.isBlank(contentType)) {
return false;
}
if (contentType.toLowerCase().startsWith("multipart/")) {
return true;
}
return false;
return contentType.toLowerCase().startsWith("multipart/");
}
// --------------------------------------------------------- Header end
@ -417,7 +410,7 @@ public class ServletUtil {
* @return Cookie map
*/
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();
if (null == cookies) {
return null;

View File

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

View File

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

View File

@ -6,7 +6,7 @@ import cn.hutool.core.util.StrUtil;
/**
* 上传的文件的头部信息<br>
* 来自Jodd
*
*
* @author jodd.org
*/
public class UploadFileHeader {
@ -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'.
*
* @return 是否为文件
*/
public boolean isFile() {
return isFile;
}
/**
* Returns form field name.
* 返回表单字段名
*
* @return 表单字段名
*/
public String getFormFieldName() {
return formFieldName;
}
/**
* Returns complete file name as specified at client side.
* 返回表单中的文件名来自客户端传入
*
* @return 表单文件名
*/
public String getFormFileName() {
return formFileName;
}
/**
* Returns file name (base name and extension, without full path data).
* 获取文件名不包括路径
*
* @return 文件名
*/
public String getFileName() {
return fileName;
@ -61,7 +69,8 @@ public class UploadFileHeader {
/**
* Returns uploaded content type. It is usually in the following form:<br>
* mime_type/mime_subtype.
*
*
* @return content type
* @see #getMimeType()
* @see #getMimeSubtype()
*/
@ -71,6 +80,8 @@ public class UploadFileHeader {
/**
* Returns file types MIME.
*
* @return types MIME
*/
public String getMimeType() {
return mimeType;
@ -78,6 +89,8 @@ public class UploadFileHeader {
/**
* Returns file sub type MIME.
*
* @return sub type MIME
*/
public String getMimeSubtype() {
return mimeSubtype;
@ -85,6 +98,8 @@ public class UploadFileHeader {
/**
* Returns content disposition. Usually it is 'form-data'.
*
* @return content disposition
*/
public String getContentDisposition() {
return contentDisposition;
@ -94,9 +109,9 @@ public class UploadFileHeader {
/**
* 获得头信息字符串字符串中指定的值
*
*
* @param dataHeader 头信息
* @param fieldName 字段名
* @param fieldName 字段名
* @return 字段值
*/
private String getDataFieldValue(String dataHeader, String fieldName) {
@ -115,7 +130,7 @@ public class UploadFileHeader {
/**
* 头信息中获得content type
*
*
* @param dataHeader data header string
* @return content type or an empty string if no content type defined
*/
@ -154,7 +169,8 @@ public class UploadFileHeader {
/**
* 处理头字符串使之转化为字段
* @param dataHeader
*
* @param dataHeader 头字符串
*/
private void processHeaderString(String dataHeader) {
isFile = dataHeader.indexOf("filename") > 0;

View File

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

View File

@ -31,16 +31,16 @@ import cn.hutool.json.serialize.JSONSerializer;
/**
* JSON工具类
*
* @author Looly
*
* @author Looly
*/
public final class JSONUtil {
// -------------------------------------------------------------------- Pause start
/**
* 创建JSONObject
*
*
* @return JSONObject
*/
public static JSONObject createObj() {
@ -49,7 +49,7 @@ public final class JSONUtil {
/**
* 创建 JSONArray
*
*
* @return JSONArray
*/
public static JSONArray createArray() {
@ -58,7 +58,7 @@ public final class JSONUtil {
/**
* JSON字符串转JSONObject对象
*
*
* @param jsonStr JSON字符串
* @return JSONObject
*/
@ -69,7 +69,7 @@ public final class JSONUtil {
/**
* JSON字符串转JSONObject对象<br>
* 此方法会忽略空值但是对JSON字符串不影响
*
*
* @param obj Bean对象或者Map
* @return JSONObject
*/
@ -79,8 +79,8 @@ public final class JSONUtil {
/**
* JSON字符串转JSONObject对象
*
* @param obj Bean对象或者Map
*
* @param obj Bean对象或者Map
* @param ignoreNullValue 是否忽略空值如果source为JSON字符串不忽略空值
* @return JSONObject
* @since 3.0.9
@ -91,10 +91,10 @@ public final class JSONUtil {
/**
* JSON字符串转JSONObject对象
*
* @param obj Bean对象或者Map
*
* @param obj Bean对象或者Map
* @param ignoreNullValue 是否忽略空值如果source为JSON字符串不忽略空值
* @param isOrder 是否有序
* @param isOrder 是否有序
* @return JSONObject
* @since 4.2.2
*/
@ -104,7 +104,7 @@ public final class JSONUtil {
/**
* JSON字符串转JSONArray
*
*
* @param jsonStr JSON字符串
* @return JSONArray
*/
@ -114,7 +114,7 @@ public final class JSONUtil {
/**
* JSON字符串转JSONArray
*
*
* @param arrayOrCollection 数组或集合对象
* @return JSONArray
* @since 3.0.8
@ -125,9 +125,9 @@ public final class JSONUtil {
/**
* JSON字符串转JSONArray
*
*
* @param arrayOrCollection 数组或集合对象
* @param ignoreNullValue 是否忽略空值
* @param ignoreNullValue 是否忽略空值
* @return JSONArray
* @since 3.2.3
*/
@ -141,7 +141,7 @@ public final class JSONUtil {
* String: 转换为相应的对象<br>
* Array Collection转换为JSONArray<br>
* Bean对象转为JSONObject
*
*
* @param obj 对象
* @return JSON
*/
@ -171,7 +171,7 @@ public final class JSONUtil {
/**
* XML字符串转为JSONObject
*
*
* @param xmlStr XML字符串
* @return JSONObject
*/
@ -181,7 +181,7 @@ public final class JSONUtil {
/**
* Map转化为JSONObject
*
*
* @param map {@link Map}
* @return JSONObject
*/
@ -191,7 +191,7 @@ public final class JSONUtil {
/**
* ResourceBundle转化为JSONObject
*
*
* @param bundle ResourceBundle文件
* @return JSONObject
*/
@ -209,10 +209,11 @@ public final class JSONUtil {
// -------------------------------------------------------------------- Pause end
// -------------------------------------------------------------------- Read start
/**
* 读取JSON
*
* @param file JSON文件
*
* @param file JSON文件
* @param charset 编码
* @return JSON包括JSONObject和JSONArray
* @throws IORuntimeException IO异常
@ -223,8 +224,8 @@ public final class JSONUtil {
/**
* 读取JSONObject
*
* @param file JSON文件
*
* @param file JSON文件
* @param charset 编码
* @return JSONObject
* @throws IORuntimeException IO异常
@ -235,8 +236,8 @@ public final class JSONUtil {
/**
* 读取JSONArray
*
* @param file JSON文件
*
* @param file JSON文件
* @param charset 编码
* @return JSONArray
* @throws IORuntimeException IO异常
@ -247,10 +248,11 @@ public final class JSONUtil {
// -------------------------------------------------------------------- Read end
// -------------------------------------------------------------------- toString start
/**
* 转为JSON字符串
*
* @param json JSON
*
* @param json JSON
* @param indentFactor 每一级别的缩进
* @return JSON字符串
*/
@ -263,7 +265,7 @@ public final class JSONUtil {
/**
* 转为JSON字符串
*
*
* @param json JSON
* @return JSON字符串
*/
@ -276,7 +278,7 @@ public final class JSONUtil {
/**
* 转为JSON字符串
*
*
* @param json JSON
* @return JSON字符串
*/
@ -289,7 +291,7 @@ public final class JSONUtil {
/**
* 转换为JSON字符串
*
*
* @param obj 被转为JSON的对象
* @return JSON字符串
*/
@ -305,7 +307,7 @@ public final class JSONUtil {
/**
* 转换为格式化后的JSON字符串
*
*
* @param obj Bean对象
* @return JSON字符串
*/
@ -315,7 +317,7 @@ public final class JSONUtil {
/**
* 转换为XML字符串
*
*
* @param json JSON
* @return XML字符串
*/
@ -328,10 +330,10 @@ public final class JSONUtil {
/**
* JSON字符串转为实体类对象转换异常将被抛出
*
* @param <T> Bean类型
*
* @param <T> Bean类型
* @param jsonString JSON字符串
* @param beanClass 实体类对象
* @param beanClass 实体类对象
* @return 实体类对象
* @since 3.1.2
*/
@ -341,22 +343,23 @@ public final class JSONUtil {
/**
* 转为实体类对象转换异常将被抛出
*
* @param <T> Bean类型
* @param json JSONObject
*
* @param <T> Bean类型
* @param json JSONObject
* @param beanClass 实体类对象
* @return 实体类对象
*/
public static <T> T toBean(JSONObject json, Class<T> beanClass) {
return null == json ? null : json.toBean(beanClass);
}
/**
* JSON字符串转为实体类对象转换异常将被抛出
*
* @param <T> Bean类型
* @param jsonString JSON字符串
*
* @param <T> Bean类型
* @param jsonString JSON字符串
* @param typeReference {@link TypeReference}类型参考子类可以获取其泛型参数中的Type类型
* @param ignoreError 是否忽略错误
* @return 实体类对象
* @since 4.3.2
*/
@ -366,24 +369,25 @@ public final class JSONUtil {
/**
* JSON字符串转为实体类对象转换异常将被抛出
*
* @param <T> Bean类型
* @param jsonString JSON字符串
* @param beanType 实体类对象类型
*
* @param <T> Bean类型
* @param jsonString JSON字符串
* @param beanType 实体类对象类型
* @param ignoreError 是否忽略错误
* @return 实体类对象
* @since 4.3.2
*/
public static <T> T toBean(String jsonString, Type beanType, boolean ignoreError) {
return toBean(parseObj(jsonString), beanType, ignoreError);
}
/**
* 转为实体类对象
*
* @param <T> Bean类型
* @param json JSONObject
*
* @param <T> Bean类型
* @param json JSONObject
* @param typeReference {@link TypeReference}类型参考子类可以获取其泛型参数中的Type类型
* @param ignoreError 是否忽略转换错误
* @param ignoreError 是否忽略转换错误
* @return 实体类对象
* @since 4.6.2
*/
@ -393,10 +397,10 @@ public final class JSONUtil {
/**
* 转为实体类对象
*
* @param <T> Bean类型
* @param json JSONObject
* @param beanType 实体类对象类型
*
* @param <T> Bean类型
* @param json JSONObject
* @param beanType 实体类对象类型
* @param ignoreError 是否忽略转换错误
* @return 实体类对象
* @since 4.3.2
@ -411,8 +415,9 @@ public final class JSONUtil {
/**
* 将JSONArray转换为Bean的List默认为ArrayList
*
* @param jsonArray JSONArray
*
* @param <T> Bean类型
* @param jsonArray JSONArray
* @param elementType List中元素类型
* @return List
* @since 4.0.7
@ -427,17 +432,17 @@ public final class JSONUtil {
* <li>.表达式可以获取Bean对象中的属性字段值或者Map中key对应的值</li>
* <li>[]表达式可以获取集合等对象中对应index的值</li>
* </ol>
*
* <p>
* 表达式栗子
*
*
* <pre>
* persion
* persion.name
* persons[3]
* person.friends[5].name
* </pre>
*
* @param json {@link JSON}
*
* @param json {@link JSON}
* @param expression 表达式
* @return 对象
* @see JSON#getByPath(String)
@ -454,19 +459,19 @@ public final class JSONUtil {
* <li>.表达式可以获取Bean对象中的属性字段值或者Map中key对应的值</li>
* <li>[]表达式可以获取集合等对象中对应index的值</li>
* </ol>
*
* <p>
* 表达式栗子
*
*
* <pre>
* persion
* persion.name
* persons[3]
* person.friends[5].name
* </pre>
*
* @param json JSON可以为JSONObject或JSONArray
*
* @param json JSON可以为JSONObject或JSONArray
* @param expression 表达式
* @param value
* @param value
*/
public static void putByPath(JSON json, String expression, Object value) {
json.putByPath(expression, value);
@ -508,8 +513,8 @@ public final class JSONUtil {
* 对所有双引号做转义处理使用双反斜杠做转义<br>
* 为了能在HTML中较好的显示会将&lt;/转义为&lt;\/<br>
* JSON字符串中不能包含控制字符和未经转义的引号和反斜杠
*
* @param str 字符串
*
* @param str 字符串
* @param writer Writer
* @return Writer
* @throws IOException IO异常
@ -522,8 +527,8 @@ public final class JSONUtil {
* 对所有双引号做转义处理使用双反斜杠做转义<br>
* 为了能在HTML中较好的显示会将&lt;/转义为&lt;\/<br>
* JSON字符串中不能包含控制字符和未经转义的引号和反斜杠
*
* @param str 字符串
*
* @param str 字符串
* @param writer Writer
* @param isWrap 是否使用双引号包装字符串
* @return Writer
@ -548,19 +553,19 @@ public final class JSONUtil {
b = c;
c = str.charAt(i);
switch (c) {
case '\\':
case '"':
writer.write("\\");
writer.write(c);
break;
case '/':
if (b == '<') {
writer.write('\\');
}
writer.write(c);
break;
default:
writer.write(escape(c));
case '\\':
case '"':
writer.write("\\");
writer.write(c);
break;
case '/':
if (b == '<') {
writer.write('\\');
}
writer.write(c);
break;
default:
writer.write(escape(c));
}
}
if (isWrap) {
@ -571,7 +576,7 @@ public final class JSONUtil {
/**
* 转义显示不可见字符
*
*
* @param str 字符串
* @return 转义后的字符串
*/
@ -601,12 +606,12 @@ public final class JSONUtil {
* <li>来自于java包 = 字符串</li>
* <li>其它 = 尝试包装为JSONObject否则返回<code>null</code></li>
* </ul>
*
* @param object 被包装的对象
*
* @param object 被包装的对象
* @param jsonConfig JSON选项
* @return 包装后的值null表示此值需被忽略
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@SuppressWarnings({"rawtypes", "unchecked"})
public static Object wrap(Object object, JSONConfig jsonConfig) {
if (object == null) {
return jsonConfig.isIgnoreNullValue() ? null : JSONNull.NULL;
@ -620,15 +625,15 @@ public final class JSONUtil {
) {
return object;
}
// 自定义序列化
final JSONSerializer serializer = GlobalSerializeMapping.getSerializer(object.getClass());
if(null != serializer) {
if (null != serializer) {
final Type jsonType = TypeUtil.getTypeArgument(serializer.getClass());
if(null != jsonType) {
if(serializer instanceof JSONObjectSerializer) {
if (null != jsonType) {
if (serializer instanceof JSONObjectSerializer) {
serializer.serialize(new JSONObject(jsonConfig), object);
} else if(serializer instanceof JSONArraySerializer) {
} else if (serializer instanceof JSONArraySerializer) {
serializer.serialize(new JSONArray(jsonConfig), object);
}
}
@ -654,7 +659,7 @@ public final class JSONUtil {
}
// Java内部类不做转换
if(ClassUtil.isJdkClass(object.getClass())) {
if (ClassUtil.isJdkClass(object.getClass())) {
return object.toString();
}
@ -667,7 +672,7 @@ public final class JSONUtil {
/**
* 格式化JSON字符串此方法并不严格检查JSON的格式正确与否
*
*
* @param jsonStr JSON字符串
* @return 格式化后的字符串
* @since 3.1.2
@ -678,7 +683,7 @@ public final class JSONUtil {
/**
* 是否为JSON字符串首尾都为大括号或中括号判定为JSON字符串
*
*
* @param str 字符串
* @return 是否为JSON字符串
* @since 3.3.0
@ -689,7 +694,7 @@ public final class JSONUtil {
/**
* 是否为JSONObject字符串首尾都为大括号判定为JSONObject字符串
*
*
* @param str 字符串
* @return 是否为JSON字符串
* @since 3.3.0
@ -703,7 +708,7 @@ public final class JSONUtil {
/**
* 是否为JSONArray字符串首尾都为中括号判定为JSONArray字符串
*
*
* @param str 字符串
* @return 是否为JSON字符串
* @since 3.3.0
@ -714,15 +719,15 @@ public final class JSONUtil {
}
return StrUtil.isWrap(str.trim(), '[', ']');
}
/**
* 是否为null对象null的情况包括
*
*
* <pre>
* 1. {@code null}
* 2. {@link JSONNull}
* </pre>
*
*
* @param obj 对象
* @return 是否为null
* @since 4.5.7
@ -734,7 +739,7 @@ public final class JSONUtil {
/**
* XML转JSONObject<br>
* 转换过程中一些信息可能会丢失JSON中无法区分节点和属性相同的节点将被处理为JSONArray
*
*
* @param xml XML字符串
* @return JSONObject
* @since 4.0.8
@ -742,11 +747,11 @@ public final class JSONUtil {
public static JSONObject xmlToJson(String xml) {
return XML.toJSONObject(xml);
}
/**
* 加入自定义的序列化器
*
* @param type 对象类型
*
* @param type 对象类型
* @param serializer 序列化器实现
* @see GlobalSerializeMapping#put(Type, JSONArraySerializer)
* @since 4.6.5
@ -754,11 +759,11 @@ public final class JSONUtil {
public static void putSerializer(Type type, JSONArraySerializer<?> serializer) {
GlobalSerializeMapping.put(type, serializer);
}
/**
* 加入自定义的序列化器
*
* @param type 对象类型
*
* @param type 对象类型
* @param serializer 序列化器实现
* @see GlobalSerializeMapping#put(Type, JSONObjectSerializer)
* @since 4.6.5
@ -766,11 +771,11 @@ public final class JSONUtil {
public static void putSerializer(Type type, JSONObjectSerializer<?> serializer) {
GlobalSerializeMapping.put(type, serializer);
}
/**
* 加入自定义的反序列化器
*
* @param type 对象类型
*
* @param type 对象类型
* @param deserializer 反序列化器实现
* @see GlobalSerializeMapping#put(Type, JSONDeserializer)
* @since 4.6.5
@ -780,36 +785,37 @@ public final class JSONUtil {
}
// --------------------------------------------------------------------------------------------- Private method start
/**
* 转义不可见字符<br>
* https://en.wikibooks.org/wiki/Unicode/Character_reference/0000-0FFF
*
*
* @param c 字符
* @return 转义后的字符串
*/
private static String escape(char c) {
switch (c) {
case '\b':
return "\\b";
case '\t':
return "\\t";
case '\n':
return "\\n";
case '\f':
return "\\f";
case '\r':
return "\\r";
default:
if (c < StrUtil.C_SPACE || //
(c >= '\u0080' && c <= '\u00a0') || //
(c >= '\u2000' && c <= '\u2010') || //
(c >= '\u2028' && c <= '\u202F') || //
(c >= '\u2066' && c <= '\u206F')//
) {
return HexUtil.toUnicodeHex(c);
} else {
return Character.toString(c);
}
case '\b':
return "\\b";
case '\t':
return "\\t";
case '\n':
return "\\n";
case '\f':
return "\\f";
case '\r':
return "\\r";
default:
if (c < StrUtil.C_SPACE || //
(c >= '\u0080' && c <= '\u00a0') || //
(c >= '\u2000' && c <= '\u2010') || //
(c >= '\u2028' && c <= '\u202F') || //
(c >= '\u2066' && c <= '\u206F')//
) {
return HexUtil.toUnicodeHex(c);
} else {
return Character.toString(c);
}
}
}
// --------------------------------------------------------------------------------------------- Private method end

View File

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