mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
修复IoUtil.readBytes使用SocketInputStream读取不完整问题
This commit is contained in:
parent
6260fcd8ea
commit
b958f9f9d2
@ -18,6 +18,7 @@
|
|||||||
* 【core 】 修复HexUtil.isHexNumber()对"-"的判断问题(issue#2857@Github)
|
* 【core 】 修复HexUtil.isHexNumber()对"-"的判断问题(issue#2857@Github)
|
||||||
* 【core 】 修复FileTypeUtil判断wav后缀的录音文件类型不能匹配问题(pr#2834@Github)
|
* 【core 】 修复FileTypeUtil判断wav后缀的录音文件类型不能匹配问题(pr#2834@Github)
|
||||||
* 【core 】 修复FileUtil的rename在newName与原文件夹名称一样时,文件夹会被删除问题(issue#2845@Github)
|
* 【core 】 修复FileUtil的rename在newName与原文件夹名称一样时,文件夹会被删除问题(issue#2845@Github)
|
||||||
|
* 【core 】 修复IoUtil.readBytes使用SocketInputStream读取不完整问题(issue#I6AT49@Gitee)
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -471,27 +471,6 @@ public class IoUtil extends NioUtil {
|
|||||||
* @since 5.0.4
|
* @since 5.0.4
|
||||||
*/
|
*/
|
||||||
public static byte[] readBytes(InputStream in, boolean isClose) throws IORuntimeException {
|
public static byte[] readBytes(InputStream in, boolean isClose) throws IORuntimeException {
|
||||||
if (in instanceof FileInputStream) {
|
|
||||||
// 文件流的长度是可预见的,此时直接读取效率更高
|
|
||||||
final byte[] result;
|
|
||||||
try {
|
|
||||||
final int available = in.available();
|
|
||||||
result = new byte[available];
|
|
||||||
final int readLength = in.read(result);
|
|
||||||
if (readLength != available) {
|
|
||||||
throw new IOException(StrUtil.format("File length is [{}] but read [{}]!", available, readLength));
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new IORuntimeException(e);
|
|
||||||
} finally {
|
|
||||||
if (isClose) {
|
|
||||||
close(in);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 未知bytes总量的流
|
|
||||||
return read(in, isClose).toByteArray();
|
return read(in, isClose).toByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user