【发布时间】:2015-01-03 23:02:25
【问题描述】:
我正在从 db 获取压缩 blob,并以下列方式使用该 blob,
例如:-
byte[] inputBlob = blobfile.getBytes(1, (int) blobfile.length());
得到 blob 后,我得到 zippedStream 并将其传递给另一个 Class 方法(解压缩)。
例如:-
ByteArrayOutputStream zippedStream = null;
InputStream byteInputStream = null;
IParser parser = null;
byte[] buffer = null;
try {
zippedStream = new ByteArrayOutputStream();
byteInputStream = new ByteArrayInputStream(blob);
blob = null;
int bytes_read;
buffer = new byte[byteInputStream.available()];
while ((bytes_read = byteInputStream.read(buffer)) > 0) {
zippedStream.write(buffer, 0, bytes_read);
}
buffer = null;
byteInputStream.close();
byteInputStream = null;
}catch(Exception e){
e.printStackTrace();
}
解压方法: 例如:-
byte[] buffer = new byte[1024];
try {
InputStream decodedInput = new ByteArrayInputStream(zippedStream.toByteArray());
zippedStream.close();
zippedStream = null;
GZIPInputStream unzippedStream = new GZIPInputStream(decodedInput);
decodedInput.close();
decodedInput = null;
int bytes_read;
unzippedOutputstream = new ByteArrayOutputStream();
while ((bytes_read = unzippedStream.read(buffer)) > 0) {
unzippedOutputstream.write(buffer, 0, bytes_read);
}
buffer = null;
unzippedStream.close();
unzippedStream = null;
} catch (Exception ex) {
logger.setException(ex);
logger.error("unzipper", generateMsg("Exception occurred"));
}
使用这种方式,我的应用程序卡住了一段时间,性能非常糟糕。 是否有任何优化方法来获取 zippedstream 文件并轻松解压缩?
【问题讨论】:
-
伙计,你的格式……没有人应该考虑阅读这篇文章。
-
原谅。但是,请查看内容并帮助我。
标签: java string performance inputstream bufferedinputstream