功能:
-
toString 读取InputStream 中的数据流并转为String
源码:
package com.dotions.utils;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
/**
* @Description String toolkit
*
* @author Dotions 2016年7月26日 下午3:29:06
*/
public class StringUtils {
public static String toString(InputStream input) throws IOException {
if (input == null) {
return null;
}
BufferedReader reader = new BufferedReader(new InputStreamReader(input, CharsetName.UTF_8));
StringBuilder builder = new StringBuilder();
String str = null;
while ((str = reader.readLine()) != null) {
builder.append(str);
}
return builder.toString();
}
/**
* Charset
*/
@SuppressWarnings("unused")
private static interface CharsetName {
public String UTF_8 = "UTF-8";
public String GBK = "GBK";
public String ISO8859_1 = "ISO8859-1";
}
}
网友评论