来自solr服务器的Java解压缩文件

时间:2016-08-30 04:13:18

标签: java solr gzip compression

当我尝试解压缩来自服务器的文件时,我收到错误,但是我在while循环中收到无效位长度错误。是否存在代码或编码问题。

byte[] buffer = new byte[1024];
        FileInputStream fileInput = null;
        FileOutputStream fileOutputStream = null;
        GZIPInputStream gzipInputStream = null; 
        System.out.println(source_compressed_filepath);
        System.out.println(destinaton_decompressed_filepath);
        try {           
            fileInput = new FileInputStream(source_compressed_filepath);
            gzipInputStream = new GZIPInputStream(fileInput);
            fileOutputStream = new FileOutputStream(destinaton_decompressed_filepath);
            int len;
            while ((len = gzipInputStream.read(buffer)) >=0) {
                fileOutputStream.write(buffer, 0, len);
            }                   
            System.out.println("The file" + source_compressed_filepath + " was DeCompressed successfully!"
                    + destinaton_decompressed_filepath);
        }catch (IOException ex) {
            System.out.println(" error in file decompression " + source_compressed_filepath);
        } finally {
            // close resources
            try {
                fileOutputStream.close();
                gzipInputStream.close();            

            } catch (IOException e) {

            }
        }

0 个答案:

没有答案