Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 需要提高从数据库解压缩文件的性能_Java_String_Performance_Inputstream_Bufferedinputstream - Fatal编程技术网

Java 需要提高从数据库解压缩文件的性能

Java 需要提高从数据库解压缩文件的性能,java,string,performance,inputstream,bufferedinputstream,Java,String,Performance,Inputstream,Bufferedinputstream,我正在从db中获取压缩块,并以下面的方式使用该块 例:- 在获取blob之后,我获取zippedStream并将其传递给另一个类方法(unzipper)的方式 例:- 解开拉链的方法: 例:- 使用这种方式,我的应用程序有一段时间被阻塞了,性能非常差。 有没有什么优化方法可以轻松地获取zippedstream文件并解压缩?所有这些缓冲都是真正需要的。你能用IParser解析一个流吗 InputStream zippedStream = ... IParser parser = ... pa

我正在从db中获取压缩块,并以下面的方式使用该块

例:-

在获取blob之后,我获取zippedStream并将其传递给另一个类方法(unzipper)的方式

例:-

解开拉链的方法: 例:-

使用这种方式,我的应用程序有一段时间被阻塞了,性能非常差。
有没有什么优化方法可以轻松地获取zippedstream文件并解压缩?

所有这些缓冲都是真正需要的。你能用IParser解析一个流吗

 InputStream zippedStream = ...
 IParser parser = ...
 parser.parse(new GZIPInputStream(zippedStream));

这将读取压缩的数据,并在进行压缩时进行解压缩,这将更加高效。

Mate,您的格式。。没有人会想到读这篇文章。原谅。但是,请看一下内容,帮我想想。你能给我一个避免上述方法性能的想法吗?我不知道你的意思。解析器可以接收输入流吗?
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"));
}
 InputStream zippedStream = ...
 IParser parser = ...
 parser.parse(new GZIPInputStream(zippedStream));