diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9fab546fb..c01e32018 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -15,6 +15,7 @@
### 🐞Bug修复
* 【core 】 修复UrlBuilder.addPath歧义问题(issue#1912@Github)
+* 【core 】 修复StrBuilder中总长度计算问题(issue#I4F9L7@Gitee)
-------------------------------------------------------------------------------------------------------------
diff --git a/hutool-core/src/main/java/cn/hutool/core/text/StrBuilder.java b/hutool-core/src/main/java/cn/hutool/core/text/StrBuilder.java
index 0de657e51..69bc75f04 100644
--- a/hutool-core/src/main/java/cn/hutool/core/text/StrBuilder.java
+++ b/hutool-core/src/main/java/cn/hutool/core/text/StrBuilder.java
@@ -579,7 +579,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable {
private static int totalLength(CharSequence... strs) {
int totalLength = 0;
for (CharSequence str : strs) {
- totalLength += (null == str ? 4 : str.length());
+ totalLength += (null == str ? 0 : str.length());
}
return totalLength;
}
diff --git a/hutool-crypto/src/main/java/cn/hutool/crypto/digest/DigestUtil.java b/hutool-crypto/src/main/java/cn/hutool/crypto/digest/DigestUtil.java
index 775d6183c..fc6fd61ce 100644
--- a/hutool-crypto/src/main/java/cn/hutool/crypto/digest/DigestUtil.java
+++ b/hutool-crypto/src/main/java/cn/hutool/crypto/digest/DigestUtil.java
@@ -1,13 +1,12 @@
package cn.hutool.crypto.digest;
+import cn.hutool.core.util.CharsetUtil;
+
+import javax.crypto.SecretKey;
import java.io.File;
import java.io.InputStream;
import java.nio.charset.Charset;
-import javax.crypto.SecretKey;
-
-import cn.hutool.core.util.CharsetUtil;
-
/**
* 摘要算法工具类
*
@@ -424,7 +423,7 @@ public class DigestUtil {
* 创建HMac对象,调用digest方法可获得hmac值
*
* @param algorithm {@link HmacAlgorithm}
- * @param key 密钥,如果为null
生成随机密钥
+ * @param key 密钥,如果为{@code null}生成随机密钥
* @return {@link HMac}
* @since 3.0.3
*/
@@ -436,7 +435,7 @@ public class DigestUtil {
* 创建HMac对象,调用digest方法可获得hmac值
*
* @param algorithm {@link HmacAlgorithm}
- * @param key 密钥{@link SecretKey},如果为null
生成随机密钥
+ * @param key 密钥{@link SecretKey},如果为{@code null}生成随机密钥
* @return {@link HMac}
* @since 3.0.3
*/
diff --git a/hutool-extra/src/main/java/cn/hutool/extra/qrcode/QrCodeUtil.java b/hutool-extra/src/main/java/cn/hutool/extra/qrcode/QrCodeUtil.java
index f9b800282..36e048d2b 100644
--- a/hutool-extra/src/main/java/cn/hutool/extra/qrcode/QrCodeUtil.java
+++ b/hutool-extra/src/main/java/cn/hutool/extra/qrcode/QrCodeUtil.java
@@ -313,9 +313,10 @@ public class QrCodeUtil {
// 默认配置
config = new QrConfig();
}
+
BitMatrix bitMatrix;
try {
- bitMatrix = multiFormatWriter.encode(content, format, config.width, config.height, config.toHints());
+ bitMatrix = multiFormatWriter.encode(content, format, config.width, config.height, config.toHints(format));
} catch (WriterException e) {
throw new QrCodeException(e);
}
diff --git a/hutool-extra/src/main/java/cn/hutool/extra/qrcode/QrConfig.java b/hutool-extra/src/main/java/cn/hutool/extra/qrcode/QrConfig.java
index f9aae03e7..0c2789c87 100644
--- a/hutool-extra/src/main/java/cn/hutool/extra/qrcode/QrConfig.java
+++ b/hutool-extra/src/main/java/cn/hutool/extra/qrcode/QrConfig.java
@@ -3,6 +3,7 @@ package cn.hutool.extra.qrcode;
import cn.hutool.core.img.ImgUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.CharsetUtil;
+import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
@@ -331,13 +332,31 @@ public class QrConfig {
* @return 配置
*/
public HashMap toHints() {
+ return toHints(BarcodeFormat.QR_CODE);
+ }
+
+ /**
+ * 转换为Zxing的二维码配置
+ *
+ * @param format 格式,根据格式不同,{@link #errorCorrection}的值类型有所不同
+ * @return 配置
+ */
+ public HashMap toHints(BarcodeFormat format) {
// 配置
final HashMap hints = new HashMap<>();
if (null != this.charset) {
hints.put(EncodeHintType.CHARACTER_SET, charset.toString().toLowerCase());
}
if (null != this.errorCorrection) {
- hints.put(EncodeHintType.ERROR_CORRECTION, this.errorCorrection);
+ Object value;
+ if(BarcodeFormat.AZTEC == format || BarcodeFormat.PDF_417 == format){
+ // issue#I4FE3U@Gitee
+ value = this.errorCorrection.getBits();
+ } else {
+ value = this.errorCorrection;
+ }
+
+ hints.put(EncodeHintType.ERROR_CORRECTION, value);
}
if (null != this.margin) {
hints.put(EncodeHintType.MARGIN, this.margin);
diff --git a/hutool-extra/src/test/java/cn/hutool/extra/qrcode/QrCodeUtilTest.java b/hutool-extra/src/test/java/cn/hutool/extra/qrcode/QrCodeUtilTest.java
index cfb5dd251..7f31d796f 100644
--- a/hutool-extra/src/test/java/cn/hutool/extra/qrcode/QrCodeUtilTest.java
+++ b/hutool-extra/src/test/java/cn/hutool/extra/qrcode/QrCodeUtilTest.java
@@ -4,6 +4,7 @@ import cn.hutool.core.codec.Base64;
import cn.hutool.core.img.ImgUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.lang.Console;
+import com.google.zxing.BarcodeFormat;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import org.junit.Assert;
import org.junit.Ignore;
@@ -87,4 +88,10 @@ public class QrCodeUtilTest {
final String decode = QrCodeUtil.decode(ImgUtil.read("d:/test/qr_a.png"), false, true);
Console.log(decode);
}
+
+ @Test
+ public void pdf417Test(){
+ final BufferedImage image = QrCodeUtil.generate("content111", BarcodeFormat.PDF_417, QrConfig.create());
+ Assert.assertNotNull(image);
+ }
}