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

@@ -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 {
* 3、Proxy-Client-IP
* 4、WL-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;