一、前言
关于dspace-services-utils-2.0.3.jar源码包工具类,对输入流InputStream基于BufferedReader对字符串String读取转换处理。
二、源码说明
package org.dspace.utils;@b@@b@import java.io.BufferedReader;@b@import java.io.IOException;@b@import java.io.InputStream;@b@import java.io.InputStreamReader;@b@@b@public class StreamUtils@b@{@b@ public static String convertStreamToString(InputStream is)@b@ {@b@ if (is == null) {@b@ throw new IllegalArgumentException("Invalid input stream, cannot be null");@b@ }@b@@b@ BufferedReader reader = new BufferedReader(new InputStreamReader(is));@b@ StringBuilder sb = new StringBuilder();@b@@b@ String line = null;@b@ try {@b@ while ((line = reader.readLine()) != null)@b@ sb.append(new StringBuilder().append(line).append("\n").toString());@b@ }@b@ catch (IOException e) {@b@ e.printStackTrace();@b@ } finally {@b@ try {@b@ is.close();@b@ } catch (IOException e) {@b@ e.printStackTrace();@b@ }@b@ }@b@ return sb.toString();@b@ }@b@}