mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
add method
This commit is contained in:
parent
41e488a36b
commit
d571567c52
@ -3,9 +3,12 @@
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
# 5.7.16 (2021-10-21)
|
||||
# 5.7.16 (2021-10-23)
|
||||
|
||||
### 🐣新特性
|
||||
* 【core 】 增加DateTime.toLocalDateTime
|
||||
* 【core 】 CharSequenceUtil增加normalize方法(pr#444@Gitee)
|
||||
* 【core 】 MailAccount增加setEncodefilename()方法,可选是否编码附件的文件名(issue#I4F160@Gitee)
|
||||
|
||||
### 🐞Bug修复
|
||||
|
||||
|
@ -12,6 +12,7 @@ import java.sql.Timestamp;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
@ -701,6 +702,16 @@ public class DateTime extends Date {
|
||||
return new java.sql.Date(getTime());
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为 {@link LocalDateTime}
|
||||
*
|
||||
* @return {@link LocalDateTime}
|
||||
* @since 5.7.16
|
||||
*/
|
||||
public LocalDateTime toLocalDateTime() {
|
||||
return LocalDateTimeUtil.of(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算相差时长
|
||||
*
|
||||
|
@ -18,6 +18,7 @@ import cn.hutool.core.util.StrUtil;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.text.MessageFormat;
|
||||
import java.text.Normalizer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
@ -4338,7 +4339,21 @@ public class CharSequenceUtil {
|
||||
* @return 给定字符串的所有字符是否都一样
|
||||
* @since 5.7.3
|
||||
*/
|
||||
public static boolean isCharEquals(String str) {
|
||||
return isBlank(str.replace(str.charAt(0), CharUtil.SPACE));
|
||||
public static boolean isCharEquals(CharSequence str) {
|
||||
Assert.notEmpty(str, "Str to check must be not empty!");
|
||||
return count(str, str.charAt(0)) == str.length();
|
||||
}
|
||||
|
||||
/**
|
||||
* 对字符串归一化处理,如 "Á" 可以使用 "u00C1"或 "u0041u0301"表示,实际测试中两个字符串并不equals<br>
|
||||
* 因此使用此方法归一为一种表示形式,默认按照W3C通常建议的,在NFC中交换文本。
|
||||
*
|
||||
* @param str 归一化的字符串
|
||||
* @return 归一化后的字符串
|
||||
* @see Normalizer#normalize(CharSequence, Normalizer.Form)
|
||||
* @since 5.7.16
|
||||
*/
|
||||
public static String normalize(CharSequence str) {
|
||||
return Normalizer.normalize(str, Normalizer.Form.NFC);
|
||||
}
|
||||
}
|
||||
|
@ -33,5 +33,19 @@ public class CharSequenceUtilTest {
|
||||
Assert.assertEquals( str + " is Good", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void normalizeTest(){
|
||||
// https://blog.csdn.net/oscar999/article/details/105326270
|
||||
|
||||
String str1 = "\u00C1";
|
||||
String str2 = "\u0041\u0301";
|
||||
|
||||
Assert.assertNotEquals(str1, str2);
|
||||
|
||||
str1 = CharSequenceUtil.normalize(str1);
|
||||
str2 = CharSequenceUtil.normalize(str2);
|
||||
Assert.assertEquals(str1, str2);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------ remove
|
||||
}
|
||||
|
@ -36,6 +36,7 @@ import java.util.Date;
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public class Mail implements Builder<MimeMessage> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 邮箱帐户信息以及一些客户端配置信息
|
||||
@ -262,7 +263,10 @@ public class Mail implements Builder<MimeMessage> {
|
||||
for (DataSource attachment : attachments) {
|
||||
bodyPart = new MimeBodyPart();
|
||||
bodyPart.setDataHandler(new DataHandler(attachment));
|
||||
nameEncoded = InternalMailUtil.encodeText(attachment.getName(), charset);
|
||||
nameEncoded = attachment.getName();
|
||||
if(this.mailAccount.isEncodefilename()){
|
||||
nameEncoded = InternalMailUtil.encodeText(nameEncoded, charset);
|
||||
}
|
||||
// 普通附件文件名
|
||||
bodyPart.setFileName(nameEncoded);
|
||||
if (StrUtil.startWith(attachment.getContentType(), "image/")) {
|
||||
|
@ -34,8 +34,10 @@ public class MailAccount implements Serializable {
|
||||
private static final String SOCKET_FACTORY_FALLBACK = "mail.smtp.socketFactory.fallback";
|
||||
private static final String SOCKET_FACTORY_PORT = "smtp.socketFactory.port";
|
||||
|
||||
// 其他
|
||||
private static final String MAIL_DEBUG = "mail.debug";
|
||||
private static final String SPLIT_LONG_PARAMS = "mail.mime.splitlongparameters";
|
||||
// private static final String ENCODE_FILE_NAME = "mail.mime.encodefilename";
|
||||
|
||||
public static final String[] MAIL_SETTING_PATHS = new String[]{"config/mail.setting", "config/mailAccount.setting", "mail.setting"};
|
||||
|
||||
@ -75,7 +77,11 @@ public class MailAccount implements Serializable {
|
||||
/**
|
||||
* 对于超长参数是否切分为多份,默认为false(国内邮箱附件不支持切分的附件名)
|
||||
*/
|
||||
private boolean splitlongparameters;
|
||||
private boolean splitlongparameters = false;
|
||||
/**
|
||||
* 对于文件名是否使用{@link #charset}编码,默认为 {@code true}
|
||||
*/
|
||||
private boolean encodefilename = true;
|
||||
|
||||
/**
|
||||
* 使用 STARTTLS安全连接,STARTTLS是对纯文本通信协议的扩展。它将纯文本连接升级为加密连接(TLS或SSL), 而不是使用一个单独的加密通信端口。
|
||||
@ -332,6 +338,26 @@ public class MailAccount implements Serializable {
|
||||
this.splitlongparameters = splitlongparameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* 对于文件名是否使用{@link #charset}编码,默认为 {@code true}
|
||||
*
|
||||
* @return 对于文件名是否使用{@link #charset}编码,默认为 {@code true}
|
||||
* @since 5.7.16
|
||||
*/
|
||||
public boolean isEncodefilename() {
|
||||
return encodefilename;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置对于文件名是否使用{@link #charset}编码
|
||||
*
|
||||
* @param encodefilename 对于文件名是否使用{@link #charset}编码
|
||||
* @since 5.7.16
|
||||
*/
|
||||
public void setEncodefilename(boolean encodefilename) {
|
||||
this.encodefilename = encodefilename;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否使用 STARTTLS安全连接,STARTTLS是对纯文本通信协议的扩展。它将纯文本连接升级为加密连接(TLS或SSL), 而不是使用一个单独的加密通信端口。
|
||||
*
|
||||
|
@ -20,3 +20,7 @@ starttlsEnable = true
|
||||
sslEnable = true
|
||||
# 调试模式
|
||||
debug = true
|
||||
# 对于超长参数是否切分为多份,默认为false(国内邮箱附件不支持切分的附件名)
|
||||
splitlongparameters = false
|
||||
# 是否编码附件文件名(默认true)
|
||||
encodefilename = true
|
||||
|
@ -346,4 +346,5 @@ public class HttpUtilTest {
|
||||
.execute().body();
|
||||
Console.log(body);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user