From 5e2be5e92689e02f3f34a671f1bcede91edb4cad Mon Sep 17 00:00:00 2001 From: Redkale <22250530@qq.com> Date: Thu, 11 May 2017 13:56:36 +0800 Subject: [PATCH] --- src/org/redkale/util/Utility.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/org/redkale/util/Utility.java b/src/org/redkale/util/Utility.java index 25dc52741..aefc0b0f5 100644 --- a/src/org/redkale/util/Utility.java +++ b/src/org/redkale/util/Utility.java @@ -1149,13 +1149,22 @@ public final class Utility { return read(in, "UTF-8"); } + public static String readThenClose(InputStream in) throws IOException { + return read(in, "UTF-8", true); + } + public static String read(InputStream in, String charsetName) throws IOException { + return read(in, charsetName, false); + } + + private static String read(InputStream in, String charsetName, 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 charsetName == null ? out.toString() : out.toString(charsetName); }