From 4cdc1f82c5997e7f928095ad0c03c52431d40634 Mon Sep 17 00:00:00 2001 From: Redkale <22250530@qq.com> Date: Wed, 14 Sep 2016 14:41:30 +0800 Subject: [PATCH] --- src/org/redkale/util/Utility.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/org/redkale/util/Utility.java b/src/org/redkale/util/Utility.java index ac3c46d52..35d7b0414 100644 --- a/src/org/redkale/util/Utility.java +++ b/src/org/redkale/util/Utility.java @@ -659,4 +659,19 @@ public final class Utility { public static byte[] readBytes(InputStream in) throws IOException { 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(); + } }