mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
Merge remote-tracking branch 'upstream/v5-dev' into v5-dev
This commit is contained in:
commit
adce91e733
@ -1,6 +1,7 @@
|
||||
package cn.hutool.core.io;
|
||||
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
@ -90,7 +91,7 @@ public class FastByteArrayOutputStream extends OutputStream {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new String(toByteArray());
|
||||
return toString(CharsetUtil.defaultCharset());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -104,11 +105,12 @@ public class FastByteArrayOutputStream extends OutputStream {
|
||||
|
||||
/**
|
||||
* 转为字符串
|
||||
* @param charset 编码
|
||||
* @param charset 编码,null表示默认编码
|
||||
* @return 字符串
|
||||
*/
|
||||
public String toString(Charset charset) {
|
||||
return new String(toByteArray(), charset);
|
||||
return new String(toByteArray(),
|
||||
ObjectUtil.defaultIfNull(charset, CharsetUtil.defaultCharset()));
|
||||
}
|
||||
|
||||
}
|
@ -2,7 +2,6 @@ package cn.hutool.core.net.multipart;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.map.multi.ListValueMap;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -78,7 +77,7 @@ public class MultipartFormData {
|
||||
putFile(header.formFieldName, newFile);
|
||||
} else {
|
||||
// 标准表单项
|
||||
putParameter(header.formFieldName, IoUtil.read(input, charset));
|
||||
putParameter(header.formFieldName, input.readString(charset));
|
||||
}
|
||||
|
||||
input.skipBytes(1);
|
||||
|
@ -1,5 +1,7 @@
|
||||
package cn.hutool.core.net.multipart;
|
||||
|
||||
import cn.hutool.core.io.FastByteArrayOutputStream;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
@ -144,7 +146,20 @@ public class MultipartRequestInputStream extends BufferedInputStream {
|
||||
// ---------------------------------------------------------------- copy
|
||||
|
||||
/**
|
||||
* 全部字节流复制到out
|
||||
* 读取字节流,直到下一个boundary
|
||||
*
|
||||
* @param charset 编码,null表示系统默认编码
|
||||
* @return 读取的字符串
|
||||
* @throws IOException 读取异常
|
||||
*/
|
||||
public String readString(Charset charset) throws IOException {
|
||||
final FastByteArrayOutputStream out = new FastByteArrayOutputStream();
|
||||
copy(out);
|
||||
return out.toString(charset);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字节流复制到out,直到下一个boundary
|
||||
*
|
||||
* @param out 输出流
|
||||
* @return 复制的字节数
|
||||
|
@ -1,4 +1,4 @@
|
||||
package cn.hutool.http.test;
|
||||
package cn.hutool.http;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
@ -1,4 +1,4 @@
|
||||
package cn.hutool.http.test;
|
||||
package cn.hutool.http;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
@ -1,4 +1,4 @@
|
||||
package cn.hutool.http.test;
|
||||
package cn.hutool.http;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.date.TimeInterval;
|
@ -1,4 +1,4 @@
|
||||
package cn.hutool.http.test;
|
||||
package cn.hutool.http;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.lang.Console;
|
@ -1,4 +1,4 @@
|
||||
package cn.hutool.http.test;
|
||||
package cn.hutool.http;
|
||||
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
@ -1,4 +1,4 @@
|
||||
package cn.hutool.http.test;
|
||||
package cn.hutool.http;
|
||||
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.http.Header;
|
@ -1,20 +1,20 @@
|
||||
package cn.hutool.http.test;
|
||||
package cn.hutool.http;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 文件上传单元测试
|
||||
* @author looly
|
||||
*
|
||||
* @author looly
|
||||
*/
|
||||
public class UploadTest {
|
||||
|
||||
@ -48,4 +48,24 @@ public class UploadTest {
|
||||
String result = HttpUtil.post("http://wthrcdn.etouch.cn/weather_mini", paramMap);
|
||||
System.out.println(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void uploadTest() {
|
||||
//客户端
|
||||
String url = "http://localhost:8888/file";
|
||||
Path file = Paths.get("D:\\testBigData_upload.xlsx");
|
||||
Map<String, String> headers = new HashMap<>(16);
|
||||
headers.put("md5", "aaaaaaaa");
|
||||
|
||||
Map<String, Object> params = new HashMap<>(16);
|
||||
params.put("fileName", file.toFile().getName());
|
||||
params.put("file", file.toFile());
|
||||
HttpRequest httpRequest = HttpRequest.post(url)
|
||||
.setChunkedStreamingMode(1024 * 1024)
|
||||
.headerMap(headers, false)
|
||||
.form(params);
|
||||
HttpResponse httpResponse = httpRequest.execute();
|
||||
Console.log(httpResponse);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user