From fa2513d9349b97073764cdc4d739e57de1a08265 Mon Sep 17 00:00:00 2001 From: Redkale <22250530@qq.com> Date: Thu, 11 May 2017 13:58:33 +0800 Subject: [PATCH] --- src/org/redkale/util/Utility.java | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/org/redkale/util/Utility.java b/src/org/redkale/util/Utility.java index aefc0b0f5..3a7baf4ed 100644 --- a/src/org/redkale/util/Utility.java +++ b/src/org/redkale/util/Utility.java @@ -1169,12 +1169,21 @@ public final class Utility { } public static ByteArrayOutputStream readStream(InputStream in) throws IOException { + return readStream(in, false); + } + + public static ByteArrayOutputStream readStreamThenClose(InputStream in) throws IOException { + return readStream(in, true); + } + + private static ByteArrayOutputStream readStream(InputStream in, boolean close) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(1024); byte[] bytes = new byte[1024]; int pos; while ((pos = in.read(bytes)) != -1) { out.write(bytes, 0, pos); } + if (close) in.close(); return out; } @@ -1182,17 +1191,6 @@ public final class Utility { return readStream(in).toByteArray(); } - public static ByteArrayOutputStream readStreamThenClose(InputStream in) throws IOException { - ByteArrayOutputStream out = new ByteArrayOutputStream(1024); - byte[] bytes = new byte[1024]; - int pos; - while ((pos = in.read(bytes)) != -1) { - out.write(bytes, 0, pos); - } - in.close(); - return out; - } - public static byte[] readBytesThenClose(InputStream in) throws IOException { return readStreamThenClose(in).toByteArray(); }