From ff23934b248b1267b685c7a40249bc2fca00fe9e Mon Sep 17 00:00:00 2001 From: Looly Date: Sun, 14 Mar 2021 09:14:05 +0800 Subject: [PATCH] fix io bug --- CHANGELOG.md | 1 + .../src/main/java/cn/hutool/core/io/IoUtil.java | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c530c81c7..79c8e7622 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ ### 新特性 * 【crypto 】 SecureUtil去除final修饰符(issue#1474@Github) ### Bug修复 +* 【core 】 修复IoUtil.readBytes的FileInputStream中isClose参数失效问题(issue#I3B7UD@Gitee) ------------------------------------------------------------------------------------------------------------- diff --git a/hutool-core/src/main/java/cn/hutool/core/io/IoUtil.java b/hutool-core/src/main/java/cn/hutool/core/io/IoUtil.java index b29e0e5cb..fe645a3bd 100644 --- a/hutool-core/src/main/java/cn/hutool/core/io/IoUtil.java +++ b/hutool-core/src/main/java/cn/hutool/core/io/IoUtil.java @@ -448,12 +448,12 @@ public class IoUtil extends NioUtil { * 从流中读取bytes * * @param in {@link InputStream} - * @param isCLose 是否关闭输入流 + * @param isClose 是否关闭输入流 * @return bytes * @throws IORuntimeException IO异常 * @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; @@ -466,12 +466,16 @@ public class IoUtil extends NioUtil { } } 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(); } /**