mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
fix code
This commit is contained in:
parent
063314ee2f
commit
a2e8c9d28f
@ -21,12 +21,7 @@ import org.dromara.hutool.core.io.IoUtil;
|
||||
import org.dromara.hutool.core.io.StreamProgress;
|
||||
import org.dromara.hutool.core.text.StrUtil;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.EOFException;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FilterInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* 同步流,可将包装的流同步为ByteArrayInputStream,以便持有内容并关闭原流
|
||||
|
@ -92,8 +92,11 @@ public class ResponseBody implements HttpBody, Closeable {
|
||||
*
|
||||
* @return 响应内容bytes
|
||||
*/
|
||||
@SuppressWarnings("resource")
|
||||
@Override
|
||||
public byte[] getBytes() {
|
||||
// issue#IANZ38 同步数据到内存
|
||||
sync();
|
||||
return this.bodyStream.readBytes();
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,26 @@
|
||||
package org.dromara.hutool.http.client;
|
||||
|
||||
import org.dromara.hutool.core.lang.Console;
|
||||
import org.dromara.hutool.http.client.engine.ClientEngineFactory;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class IssueIANZ38Test {
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
void toStringTest() {
|
||||
final Request request = Request.of("https://hutool.cn/");
|
||||
try(final Response response = ClientEngineFactory.createEngine("JdkClient").send(request)) {
|
||||
final String bodyStr = response.bodyStr();
|
||||
|
||||
Console.log(bodyStr);
|
||||
// 读取过一次bodyStr后,再读取就关闭流了,此处做修改,读取body时同步响应body到内存
|
||||
Console.log(response.toString());
|
||||
} catch (final IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user