add test and comment

This commit is contained in:
Looly 2021-07-26 18:10:29 +08:00
parent 86479585a8
commit 2ce5b2cc79
4 changed files with 25 additions and 5 deletions

View File

@ -196,7 +196,7 @@ public class UploadFile {
int memoryThreshold = setting.memoryThreshold; int memoryThreshold = setting.memoryThreshold;
if (memoryThreshold > 0) { if (memoryThreshold > 0) {
final ByteArrayOutputStream baos = new ByteArrayOutputStream(memoryThreshold); final ByteArrayOutputStream baos = new ByteArrayOutputStream(memoryThreshold);
int written = input.copy(baos, memoryThreshold); final long written = input.copy(baos, memoryThreshold);
data = baos.toByteArray(); data = baos.toByteArray();
if (written <= memoryThreshold) { if (written <= memoryThreshold) {
// 文件存放于内存 // 文件存放于内存

View File

@ -3604,7 +3604,13 @@ public class CharSequenceUtil {
} }
/** /**
* 替换所有正则匹配的文本并使用自定义函数决定如何替换 * 替换所有正则匹配的文本并使用自定义函数决定如何替换<br>
* replaceFun可以通过{@link Matcher}提取出匹配到的内容的不同部分然后经过重新处理组装变成新的内容放回原位
*
* <pre class="code">
* replaceAll(this.content, "(\\d+)", parameters -> "->" + parameters.group(1) + "<-")
* // 结果为"ZZZaaabbbccc中文->1234<-"
* </pre>
* *
* @param str 要替换的字符串 * @param str 要替换的字符串
* @param pattern 用于匹配的正则式 * @param pattern 用于匹配的正则式

View File

@ -771,7 +771,13 @@ public class ReUtil {
} }
/** /**
* 替换所有正则匹配的文本并使用自定义函数决定如何替换 * 替换所有正则匹配的文本并使用自定义函数决定如何替换<br>
* replaceFun可以通过{@link Matcher}提取出匹配到的内容的不同部分然后经过重新处理组装变成新的内容放回原位
*
* <pre class="code">
* replaceAll(this.content, "(\\d+)", parameters -> "->" + parameters.group(1) + "<-")
* // 结果为"ZZZaaabbbccc中文->1234<-"
* </pre>
* *
* @param str 要替换的字符串 * @param str 要替换的字符串
* @param regex 用于匹配的正则式 * @param regex 用于匹配的正则式
@ -784,7 +790,13 @@ public class ReUtil {
} }
/** /**
* 替换所有正则匹配的文本并使用自定义函数决定如何替换 * 替换所有正则匹配的文本并使用自定义函数决定如何替换<br>
* replaceFun可以通过{@link Matcher}提取出匹配到的内容的不同部分然后经过重新处理组装变成新的内容放回原位
*
* <pre class="code">
* replaceAll(this.content, "(\\d+)", parameters -> "->" + parameters.group(1) + "<-")
* // 结果为"ZZZaaabbbccc中文->1234<-"
* </pre>
* *
* @param str 要替换的字符串 * @param str 要替换的字符串
* @param pattern 用于匹配的正则式 * @param pattern 用于匹配的正则式

View File

@ -3,10 +3,12 @@ package cn.hutool.core.text;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import java.util.regex.Pattern;
public class CharSequenceUtilTest { public class CharSequenceUtilTest {
@Test @Test
public void replace() { public void replaceTest() {
String actual = CharSequenceUtil.replace("SSM15930297701BeryAllen", Pattern.compile("[0-9]"), matcher -> ""); String actual = CharSequenceUtil.replace("SSM15930297701BeryAllen", Pattern.compile("[0-9]"), matcher -> "");
Assert.assertEquals("SSMBeryAllen", actual); Assert.assertEquals("SSMBeryAllen", actual);
} }