This commit is contained in:
Looly 2023-03-13 12:22:51 +08:00
parent 1ad628f944
commit c1a895bce5
24 changed files with 60 additions and 37 deletions

View File

@ -138,18 +138,18 @@ We provide the T-Shirt and Sweater with Hutool Logo, please visit the shop
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>6.0.0.M1</version>
<version>6.0.0.M2</version>
</dependency>
```
### 🍐Gradle
```
implementation 'cn.hutool:hutool-all:6.0.0.M1'
implementation 'cn.hutool:hutool-all:6.0.0.M2'
```
## 📥Download
- [Maven Repo](https://repo1.maven.org/maven2/cn/hutool/hutool-all/6.0.0.M1/)
- [Maven Repo](https://repo1.maven.org/maven2/cn/hutool/hutool-all/6.0.0.M2/)
> 🔔note:
> Hutool 5.x supports JDK8+ and is not tested on Android platforms, and cannot guarantee that all tool classes or tool methods are available.

View File

@ -141,21 +141,21 @@ Hutool的存在就是为了减少代码搜索成本避免网络上参差不
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>6.0.0.M1</version>
<version>6.0.0.M2</version>
</dependency>
```
### 🍐Gradle
```
implementation 'cn.hutool:hutool-all:6.0.0.M1'
implementation 'cn.hutool:hutool-all:6.0.0.M2'
```
### 📥下载jar
点击以下链接,下载`hutool-all-X.X.X.jar`即可:
- [Maven中央库](https://repo1.maven.org/maven2/cn/hutool/hutool-all/6.0.0.M1/)
- [Maven中央库](https://repo1.maven.org/maven2/cn/hutool/hutool-all/6.0.0.M2/)
> 🔔️注意
> Hutool 5.x支持JDK8+对Android平台没有测试不能保证所有工具类或工具方法可用。

View File

@ -1 +1 @@
6.0.0.M1
6.0.0.M2

View File

@ -1 +1 @@
var version = '6.0.0.M1'
var version = '6.0.0.M2'

View File

@ -9,7 +9,7 @@
<parent>
<groupId>cn.hutool</groupId>
<artifactId>hutool-parent</artifactId>
<version>6.0.0.M1</version>
<version>6.0.0.M2</version>
</parent>
<artifactId>hutool-all</artifactId>

View File

@ -9,7 +9,7 @@
<parent>
<groupId>cn.hutool</groupId>
<artifactId>hutool-parent</artifactId>
<version>6.0.0.M1</version>
<version>6.0.0.M2</version>
</parent>
<artifactId>hutool-bom</artifactId>

View File

@ -9,7 +9,7 @@
<parent>
<groupId>cn.hutool</groupId>
<artifactId>hutool-parent</artifactId>
<version>6.0.0.M1</version>
<version>6.0.0.M2</version>
</parent>
<artifactId>hutool-core</artifactId>

View File

@ -48,15 +48,15 @@ public class SyncInputStream extends FilterInputStream {
/**
* 同步数据到内存
* @return this
*/
public void sync() {
if (false == asyncFlag) {
// 已经是同步模式
return;
public SyncInputStream sync() {
if (asyncFlag) {
this.in = new ByteArrayInputStream(readBytes());
this.asyncFlag = false;
}
this.in = new ByteArrayInputStream(readBytes());
this.asyncFlag = false;
return this;
}
/**

View File

@ -9,7 +9,7 @@
<parent>
<groupId>cn.hutool</groupId>
<artifactId>hutool-parent</artifactId>
<version>6.0.0.M1</version>
<version>6.0.0.M2</version>
</parent>
<artifactId>hutool-cron</artifactId>

View File

@ -9,7 +9,7 @@
<parent>
<groupId>cn.hutool</groupId>
<artifactId>hutool-parent</artifactId>
<version>6.0.0.M1</version>
<version>6.0.0.M2</version>
</parent>
<artifactId>hutool-crypto</artifactId>

View File

@ -9,7 +9,7 @@
<parent>
<groupId>cn.hutool</groupId>
<artifactId>hutool-parent</artifactId>
<version>6.0.0.M1</version>
<version>6.0.0.M2</version>
</parent>
<artifactId>hutool-db</artifactId>

View File

@ -9,7 +9,7 @@
<parent>
<groupId>cn.hutool</groupId>
<artifactId>hutool-parent</artifactId>
<version>6.0.0.M1</version>
<version>6.0.0.M2</version>
</parent>
<artifactId>hutool-extra</artifactId>

View File

@ -9,7 +9,7 @@
<parent>
<groupId>cn.hutool</groupId>
<artifactId>hutool-parent</artifactId>
<version>6.0.0.M1</version>
<version>6.0.0.M2</version>
</parent>
<artifactId>hutool-http</artifactId>

View File

@ -1,14 +1,15 @@
package cn.hutool.http.client;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.io.IORuntimeException;
import cn.hutool.core.text.StrUtil;
import cn.hutool.http.HttpException;
import cn.hutool.http.client.body.ResponseBody;
import cn.hutool.http.html.HtmlUtil;
import cn.hutool.http.meta.ContentTypeUtil;
import cn.hutool.http.meta.Header;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.List;
@ -79,17 +80,25 @@ public interface Response extends Closeable {
* @throws HttpException 包装IO异常
*/
default String bodyStr() throws HttpException {
return HtmlUtil.getString(bodyBytes(), charset(), true);
try(final ResponseBody body = body()){
return body.getString();
} catch (final IOException e) {
throw new IORuntimeException(e);
}
}
/**
* 获取响应流字节码<br>
* 此方法会转为同步模式
* 此方法会转为同步模式读取响应流并关闭之
*
* @return byte[]
*/
default byte[] bodyBytes() {
return body().getBytes();
try(final ResponseBody body = body()){
return body.getBytes();
} catch (final IOException e) {
throw new IORuntimeException(e);
}
}
/**

View File

@ -11,6 +11,7 @@ import cn.hutool.core.text.StrUtil;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.http.HttpException;
import cn.hutool.http.client.Response;
import cn.hutool.http.html.HtmlUtil;
import cn.hutool.http.meta.Header;
import java.io.Closeable;
@ -79,6 +80,15 @@ public class ResponseBody implements HttpBody, Closeable {
return this.bodyStream.readBytes();
}
/**
* 获取响应字符串自动识别判断编码
*
* @return 响应字符串
*/
public String getString() {
return HtmlUtil.getString(getBytes(), response.charset(), true);
}
/**
* 将响应内容写出到{@link OutputStream}<br>
* 异步模式下直接读取Http流写出同步模式下将存储在内存中的响应内容写出<br>
@ -189,6 +199,11 @@ public class ResponseBody implements HttpBody, Closeable {
this.bodyStream.close();
}
@Override
public String toString() {
return getString();
}
// region ---------------------------------------------------------------------------- Private Methods
/**

View File

@ -3,14 +3,13 @@ package cn.hutool.http.client;
import cn.hutool.core.lang.Console;
import cn.hutool.http.client.engine.httpclient4.HttpClient4Engine;
import cn.hutool.http.meta.Method;
import org.junit.Ignore;
import org.junit.Test;
public class HttpClient4EngineTest {
@SuppressWarnings("resource")
@Test
@Ignore
//@Ignore
public void getTest() {
final ClientEngine engine = new HttpClient4Engine();

View File

@ -1,8 +1,8 @@
package cn.hutool.http.client;
import cn.hutool.core.lang.Console;
import cn.hutool.http.meta.Method;
import cn.hutool.http.client.engine.httpclient5.HttpClient5Engine;
import cn.hutool.http.meta.Method;
import org.junit.Ignore;
import org.junit.Test;
@ -18,6 +18,6 @@ public class HttpClient5EngineTest {
final Response res = engine.send(req);
Console.log(res.getStatus());
Console.log(res.body());
Console.log(res.bodyStr());
}
}

View File

@ -9,7 +9,7 @@
<parent>
<groupId>cn.hutool</groupId>
<artifactId>hutool-parent</artifactId>
<version>6.0.0.M1</version>
<version>6.0.0.M2</version>
</parent>
<artifactId>hutool-json</artifactId>

View File

@ -9,7 +9,7 @@
<parent>
<groupId>cn.hutool</groupId>
<artifactId>hutool-parent</artifactId>
<version>6.0.0.M1</version>
<version>6.0.0.M2</version>
</parent>
<artifactId>hutool-log</artifactId>

View File

@ -9,7 +9,7 @@
<parent>
<groupId>cn.hutool</groupId>
<artifactId>hutool-parent</artifactId>
<version>6.0.0.M1</version>
<version>6.0.0.M2</version>
</parent>
<artifactId>hutool-poi</artifactId>

View File

@ -9,7 +9,7 @@
<parent>
<groupId>cn.hutool</groupId>
<artifactId>hutool-parent</artifactId>
<version>6.0.0.M1</version>
<version>6.0.0.M2</version>
</parent>
<artifactId>hutool-setting</artifactId>

View File

@ -9,7 +9,7 @@
<parent>
<groupId>cn.hutool</groupId>
<artifactId>hutool-parent</artifactId>
<version>6.0.0.M1</version>
<version>6.0.0.M2</version>
</parent>
<artifactId>hutool-socket</artifactId>

View File

@ -9,7 +9,7 @@
<parent>
<groupId>cn.hutool</groupId>
<artifactId>hutool-parent</artifactId>
<version>6.0.0.M1</version>
<version>6.0.0.M2</version>
</parent>
<artifactId>hutool-swing</artifactId>

View File

@ -8,7 +8,7 @@
<groupId>cn.hutool</groupId>
<artifactId>hutool-parent</artifactId>
<version>6.0.0.M1</version>
<version>6.0.0.M2</version>
<name>hutool</name>
<description>Hutool是一个小而全的Java工具类库通过静态方法封装降低相关API的学习成本提高工作效率使Java拥有函数式语言般的优雅让Java语言也可以“甜甜的”。</description>
<url>https://github.com/dromara/hutool</url>