From 77c2f72b42451caaa9c164129aa76f6fb0f16bde Mon Sep 17 00:00:00 2001 From: Redkale <22250530@qq.com> Date: Wed, 14 Sep 2016 14:39:15 +0800 Subject: [PATCH] --- src/org/redkale/util/Utility.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/org/redkale/util/Utility.java b/src/org/redkale/util/Utility.java index c7fa45341..ac3c46d52 100644 --- a/src/org/redkale/util/Utility.java +++ b/src/org/redkale/util/Utility.java @@ -645,4 +645,18 @@ public final class Utility { } return charsetName == null ? out.toString() : out.toString(charsetName); } + + public static ByteArrayOutputStream readStream(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); + } + return out; + } + + public static byte[] readBytes(InputStream in) throws IOException { + return readStream(in).toByteArray(); + } }