Prepare release

This commit is contained in:
Looly 2020-12-16 14:53:18 +08:00
commit ce0b104324
31 changed files with 162 additions and 96 deletions

View File

@ -1,6 +1,15 @@
# Changelog # Changelog
-------------------------------------------------------------------------------------------------------------
# 5.5.4 (2020-12-16)
### 新特性
### Bug修复
* 【core 】 修复IoUtil.readBytes的问题
------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------
# 5.5.3 (2020-12-11) # 5.5.3 (2020-12-11)

View File

@ -125,19 +125,19 @@ Each module can be introduced individually, or all modules can be introduced by
<dependency> <dependency>
<groupId>cn.hutool</groupId> <groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId> <artifactId>hutool-all</artifactId>
<version>5.5.3</version> <version>5.5.4</version>
</dependency> </dependency>
``` ```
### Gradle ### Gradle
``` ```
compile 'cn.hutool:hutool-all:5.5.3' compile 'cn.hutool:hutool-all:5.5.4'
``` ```
## Download ## Download
- [Maven1](https://repo1.maven.org/maven2/cn/hutool/hutool-all/5.5.3/) - [Maven1](https://repo1.maven.org/maven2/cn/hutool/hutool-all/5.5.4/)
- [Maven2](http://repo2.maven.org/maven2/cn/hutool/hutool-all/5.5.3/) - [Maven2](http://repo2.maven.org/maven2/cn/hutool/hutool-all/5.5.4/)
> note: > 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. > 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

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

View File

@ -1 +1 @@
5.5.3 5.5.4

View File

@ -1 +1 @@
var version = '5.5.3' var version = '5.5.4'

View File

@ -9,7 +9,7 @@
<parent> <parent>
<groupId>cn.hutool</groupId> <groupId>cn.hutool</groupId>
<artifactId>hutool-parent</artifactId> <artifactId>hutool-parent</artifactId>
<version>5.5.3</version> <version>5.5.4</version>
</parent> </parent>
<artifactId>hutool-all</artifactId> <artifactId>hutool-all</artifactId>

View File

@ -9,7 +9,7 @@
<parent> <parent>
<groupId>cn.hutool</groupId> <groupId>cn.hutool</groupId>
<artifactId>hutool-parent</artifactId> <artifactId>hutool-parent</artifactId>
<version>5.5.3</version> <version>5.5.4</version>
</parent> </parent>
<artifactId>hutool-aop</artifactId> <artifactId>hutool-aop</artifactId>

View File

@ -7,7 +7,7 @@
<parent> <parent>
<groupId>cn.hutool</groupId> <groupId>cn.hutool</groupId>
<artifactId>hutool-parent</artifactId> <artifactId>hutool-parent</artifactId>
<version>5.5.3</version> <version>5.5.4</version>
</parent> </parent>
<artifactId>hutool-bloomFilter</artifactId> <artifactId>hutool-bloomFilter</artifactId>

View File

@ -7,7 +7,7 @@
<parent> <parent>
<groupId>cn.hutool</groupId> <groupId>cn.hutool</groupId>
<artifactId>hutool-parent</artifactId> <artifactId>hutool-parent</artifactId>
<version>5.5.3</version> <version>5.5.4</version>
</parent> </parent>
<artifactId>hutool-bom</artifactId> <artifactId>hutool-bom</artifactId>

View File

@ -7,7 +7,7 @@
<parent> <parent>
<groupId>cn.hutool</groupId> <groupId>cn.hutool</groupId>
<artifactId>hutool-parent</artifactId> <artifactId>hutool-parent</artifactId>
<version>5.5.3</version> <version>5.5.4</version>
</parent> </parent>
<artifactId>hutool-cache</artifactId> <artifactId>hutool-cache</artifactId>

View File

@ -7,7 +7,7 @@
<parent> <parent>
<groupId>cn.hutool</groupId> <groupId>cn.hutool</groupId>
<artifactId>hutool-parent</artifactId> <artifactId>hutool-parent</artifactId>
<version>5.5.3</version> <version>5.5.4</version>
</parent> </parent>
<artifactId>hutool-captcha</artifactId> <artifactId>hutool-captcha</artifactId>

View File

@ -17,7 +17,7 @@
<parent> <parent>
<groupId>cn.hutool</groupId> <groupId>cn.hutool</groupId>
<artifactId>hutool-parent</artifactId> <artifactId>hutool-parent</artifactId>
<version>5.5.3</version> <version>5.5.4</version>
</parent> </parent>
<artifactId>hutool-core</artifactId> <artifactId>hutool-core</artifactId>

View File

@ -16,11 +16,11 @@ import java.nio.charset.Charset;
* 也就是三位二进制数组经过编码后变为四位的ASCII字符显示长度比原来增加1/3 * 也就是三位二进制数组经过编码后变为四位的ASCII字符显示长度比原来增加1/3
* *
* @author Looly * @author Looly
*
*/ */
public class Base64 { public class Base64 {
// -------------------------------------------------------------------- encode // -------------------------------------------------------------------- encode
/** /**
* 编码为Base64非URL安全的 * 编码为Base64非URL安全的
* *
@ -80,6 +80,7 @@ public class Base64 {
* base64编码不进行padding(末尾不会填充'=') * base64编码不进行padding(末尾不会填充'=')
* *
* @param source 被编码的base64字符串 * @param source 被编码的base64字符串
* @param charset 编码
* @return 被加密后的字符串 * @return 被加密后的字符串
* @since 5.5.2 * @since 5.5.2
*/ */
@ -200,11 +201,11 @@ public class Base64 {
/** /**
* 编码为Base64<br> * 编码为Base64<br>
* 如果isMultiLine为<code>true</code>则每76个字符一个换行符否则在一行显示 * 如果isMultiLine为{@code true}则每76个字符一个换行符否则在一行显示
* *
* @param arr 被编码的数组 * @param arr 被编码的数组
* @param isMultiLine 在76个char之后是CRLF还是EOF * @param isMultiLine 在76个char之后是CRLF还是EOF
* @param isUrlSafe 是否使用URL安全字符一般为<code>false</code> * @param isUrlSafe 是否使用URL安全字符一般为{@code false}
* @return 编码后的bytes * @return 编码后的bytes
*/ */
public static byte[] encode(byte[] arr, boolean isMultiLine, boolean isUrlSafe) { public static byte[] encode(byte[] arr, boolean isMultiLine, boolean isUrlSafe) {
@ -212,6 +213,7 @@ public class Base64 {
} }
// -------------------------------------------------------------------- decode // -------------------------------------------------------------------- decode
/** /**
* base64解码 * base64解码
* *

View File

@ -330,7 +330,7 @@ public class IoUtil extends NioUtil{
} }
/** /**
* 从流中读取内容 * 从流中读取内容读取完成后关闭流
* *
* @param in 输入流 * @param in 输入流
* @param charsetName 字符集 * @param charsetName 字符集
@ -338,7 +338,7 @@ public class IoUtil extends NioUtil{
* @throws IORuntimeException IO异常 * @throws IORuntimeException IO异常
*/ */
public static String read(InputStream in, String charsetName) throws IORuntimeException { public static String read(InputStream in, String charsetName) throws IORuntimeException {
FastByteArrayOutputStream out = read(in); final FastByteArrayOutputStream out = read(in);
return StrUtil.isBlank(charsetName) ? out.toString() : out.toString(charsetName); return StrUtil.isBlank(charsetName) ? out.toString() : out.toString(charsetName);
} }
@ -362,8 +362,27 @@ public class IoUtil extends NioUtil{
* @throws IORuntimeException IO异常 * @throws IORuntimeException IO异常
*/ */
public static FastByteArrayOutputStream read(InputStream in) throws IORuntimeException { public static FastByteArrayOutputStream read(InputStream in) throws IORuntimeException {
return read(in, true);
}
/**
* 从流中读取内容读到输出流中读取完毕后并不关闭流
*
* @param in 输入流
* @param isClose 读取完毕后是否关闭流
* @return 输出流
* @throws IORuntimeException IO异常
* @since 5.5.3
*/
public static FastByteArrayOutputStream read(InputStream in, boolean isClose) throws IORuntimeException {
final FastByteArrayOutputStream out = new FastByteArrayOutputStream(); final FastByteArrayOutputStream out = new FastByteArrayOutputStream();
try {
copy(in, out); copy(in, out);
} finally {
if (isClose) {
close(in);
}
}
return out; return out;
} }
@ -418,25 +437,30 @@ public class IoUtil extends NioUtil{
* 从流中读取bytes * 从流中读取bytes
* *
* @param in {@link InputStream} * @param in {@link InputStream}
* @param isCloseStream 是否关闭输入流 * @param isCLose 是否关闭输入流
* @return bytes * @return bytes
* @throws IORuntimeException IO异常 * @throws IORuntimeException IO异常
* @since 5.0.4 * @since 5.0.4
*/ */
public static byte[] readBytes(InputStream in, boolean isCloseStream) throws IORuntimeException { public static byte[] readBytes(InputStream in, boolean isCLose) throws IORuntimeException {
final InputStream availableStream = toAvailableStream(in); if (in instanceof FileInputStream) {
// 文件流的长度是可预见的此时直接读取效率更高
final byte[] result;
try { try {
final int available = availableStream.available(); final int available = in.available();
if(available > 0){ result = new byte[available];
byte[] result = new byte[available]; final int readLength = in.read(result);
//noinspection ResultOfMethodCallIgnored if (readLength != available) {
availableStream.read(result); throw new IOException(StrUtil.format("File length is [{}] but read [{}]!", available, readLength));
return result;
} }
} catch (IOException e) { } catch (IOException e) {
throw new IORuntimeException(e); throw new IORuntimeException(e);
} }
return new byte[0]; return result;
}
// 未知bytes总量的流
return read(in, isCLose).toByteArray();
} }
/** /**
@ -804,6 +828,7 @@ public class IoUtil extends NioUtil{
* 将指定{@link InputStream} 转换为{@link InputStream#available()}方法可用的流<br> * 将指定{@link InputStream} 转换为{@link InputStream#available()}方法可用的流<br>
* 在Socket通信流中服务端未返回数据情况下{@link InputStream#available()}方法始终为{@code 0}<br> * 在Socket通信流中服务端未返回数据情况下{@link InputStream#available()}方法始终为{@code 0}<br>
* 因此在读取前需要调用{@link InputStream#read()}读取一个字节未返回会阻塞一旦读取到了{@link InputStream#available()}方法就正常了<br> * 因此在读取前需要调用{@link InputStream#read()}读取一个字节未返回会阻塞一旦读取到了{@link InputStream#available()}方法就正常了<br>
* 需要注意的是在网络流中是按照块来传输的所以 {@link InputStream#available()} 读取到的并非最终长度而是此次块的长度<br>
* 此方法返回对象的规则为 * 此方法返回对象的规则为
* *
* <ul> * <ul>

View File

@ -383,6 +383,21 @@ public class PathUtil {
return IoUtil.getReader(getInputStream(path), charset); return IoUtil.getReader(getInputStream(path), charset);
} }
/**
* 读取文件的所有内容为byte数组
*
* @param path 文件
* @return byte数组
* @since 5.5.4
*/
public static byte[] readBytes(Path path){
try {
return Files.readAllBytes(path);
} catch (IOException e) {
throw new IORuntimeException(e);
}
}
/** /**
* 获得输出流 * 获得输出流
* *

View File

@ -563,6 +563,7 @@ public class ZipUtil {
* 获取压缩包中的指定文件流 * 获取压缩包中的指定文件流
* *
* @param zipFile 压缩文件 * @param zipFile 压缩文件
* @param charset 编码
* @param path 需要提取文件的文件名或路径 * @param path 需要提取文件的文件名或路径
* @return 压缩文件流如果未找到返回{@code null} * @return 压缩文件流如果未找到返回{@code null}
* @since 5.5.2 * @since 5.5.2

View File

@ -0,0 +1,14 @@
package cn.hutool.core.io;
import cn.hutool.core.io.resource.ResourceUtil;
import org.junit.Assert;
import org.junit.Test;
public class IoUtilTest {
@Test
public void readBytesTest(){
final byte[] bytes = IoUtil.readBytes(ResourceUtil.getStream("hutool.jpg"));
Assert.assertEquals(22807, bytes.length);
}
}

View File

@ -7,7 +7,7 @@
<parent> <parent>
<groupId>cn.hutool</groupId> <groupId>cn.hutool</groupId>
<artifactId>hutool-parent</artifactId> <artifactId>hutool-parent</artifactId>
<version>5.5.3</version> <version>5.5.4</version>
</parent> </parent>
<artifactId>hutool-cron</artifactId> <artifactId>hutool-cron</artifactId>

View File

@ -9,7 +9,7 @@
<parent> <parent>
<groupId>cn.hutool</groupId> <groupId>cn.hutool</groupId>
<artifactId>hutool-parent</artifactId> <artifactId>hutool-parent</artifactId>
<version>5.5.3</version> <version>5.5.4</version>
</parent> </parent>
<artifactId>hutool-crypto</artifactId> <artifactId>hutool-crypto</artifactId>

View File

@ -9,7 +9,7 @@
<parent> <parent>
<groupId>cn.hutool</groupId> <groupId>cn.hutool</groupId>
<artifactId>hutool-parent</artifactId> <artifactId>hutool-parent</artifactId>
<version>5.5.3</version> <version>5.5.4</version>
</parent> </parent>
<artifactId>hutool-db</artifactId> <artifactId>hutool-db</artifactId>

View File

@ -7,7 +7,7 @@
<parent> <parent>
<groupId>cn.hutool</groupId> <groupId>cn.hutool</groupId>
<artifactId>hutool-parent</artifactId> <artifactId>hutool-parent</artifactId>
<version>5.5.3</version> <version>5.5.4</version>
</parent> </parent>
<artifactId>hutool-dfa</artifactId> <artifactId>hutool-dfa</artifactId>

View File

@ -9,7 +9,7 @@
<parent> <parent>
<groupId>cn.hutool</groupId> <groupId>cn.hutool</groupId>
<artifactId>hutool-parent</artifactId> <artifactId>hutool-parent</artifactId>
<version>5.5.3</version> <version>5.5.4</version>
</parent> </parent>
<artifactId>hutool-extra</artifactId> <artifactId>hutool-extra</artifactId>

View File

@ -9,7 +9,7 @@
<parent> <parent>
<groupId>cn.hutool</groupId> <groupId>cn.hutool</groupId>
<artifactId>hutool-parent</artifactId> <artifactId>hutool-parent</artifactId>
<version>5.5.3</version> <version>5.5.4</version>
</parent> </parent>
<artifactId>hutool-http</artifactId> <artifactId>hutool-http</artifactId>

View File

@ -9,7 +9,7 @@
<parent> <parent>
<groupId>cn.hutool</groupId> <groupId>cn.hutool</groupId>
<artifactId>hutool-parent</artifactId> <artifactId>hutool-parent</artifactId>
<version>5.5.3</version> <version>5.5.4</version>
</parent> </parent>
<artifactId>hutool-json</artifactId> <artifactId>hutool-json</artifactId>

View File

@ -9,7 +9,7 @@
<parent> <parent>
<groupId>cn.hutool</groupId> <groupId>cn.hutool</groupId>
<artifactId>hutool-parent</artifactId> <artifactId>hutool-parent</artifactId>
<version>5.5.3</version> <version>5.5.4</version>
</parent> </parent>
<artifactId>hutool-log</artifactId> <artifactId>hutool-log</artifactId>

View File

@ -8,7 +8,7 @@
<parent> <parent>
<groupId>cn.hutool</groupId> <groupId>cn.hutool</groupId>
<artifactId>hutool-parent</artifactId> <artifactId>hutool-parent</artifactId>
<version>5.5.3</version> <version>5.5.4</version>
</parent> </parent>
<artifactId>hutool-poi</artifactId> <artifactId>hutool-poi</artifactId>

View File

@ -8,7 +8,7 @@
<parent> <parent>
<groupId>cn.hutool</groupId> <groupId>cn.hutool</groupId>
<artifactId>hutool-parent</artifactId> <artifactId>hutool-parent</artifactId>
<version>5.5.3</version> <version>5.5.4</version>
</parent> </parent>
<artifactId>hutool-script</artifactId> <artifactId>hutool-script</artifactId>

View File

@ -9,7 +9,7 @@
<parent> <parent>
<groupId>cn.hutool</groupId> <groupId>cn.hutool</groupId>
<artifactId>hutool-parent</artifactId> <artifactId>hutool-parent</artifactId>
<version>5.5.3</version> <version>5.5.4</version>
</parent> </parent>
<artifactId>hutool-setting</artifactId> <artifactId>hutool-setting</artifactId>

View File

@ -9,7 +9,7 @@
<parent> <parent>
<groupId>cn.hutool</groupId> <groupId>cn.hutool</groupId>
<artifactId>hutool-parent</artifactId> <artifactId>hutool-parent</artifactId>
<version>5.5.3</version> <version>5.5.4</version>
</parent> </parent>
<artifactId>hutool-socket</artifactId> <artifactId>hutool-socket</artifactId>

View File

@ -9,7 +9,7 @@
<parent> <parent>
<groupId>cn.hutool</groupId> <groupId>cn.hutool</groupId>
<artifactId>hutool-parent</artifactId> <artifactId>hutool-parent</artifactId>
<version>5.5.3</version> <version>5.5.4</version>
</parent> </parent>
<artifactId>hutool-system</artifactId> <artifactId>hutool-system</artifactId>

View File

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