1
System.out.println("Input String length : " + str.length());
System.out.println("SWB==="+sw.getTime());
byte[] bytes = Base64.decodeBase64(str);
System.out.println("SWB==="+sw.getTime());
GZIPInputStream gis = new GZIPInputStream(new ByteArrayInputStream(bytes));
BufferedReader bf = new BufferedReader(new InputStreamReader(gis));
String outStr = "";
String line;
while ((line=bf.readLine())!=null) {
outStr += line;
}
System.out.println("SWB==="+sw.getTime());
System.out.println("Output String lenght : " + outStr.length());
上述代碼打印爲什麼GZIPInputStream需要相當長的時間?
SWB===1
SWB===4
SWB===27052
Output String lenght : 1750825
但相同的字符串的壓縮需要相當短的時間(小於100ms)。我在這裏做錯了什麼?
嘗試使用'StringBuilder'而不是'outStr + = line'。 – Jack 2014-10-01 10:44:06
我發現這個工作更快:http://stackoverflow.com/a/10572491/393639 – dinesh707 2014-10-01 10:46:59