Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.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中动态提取.gz文件?_Java - Fatal编程技术网

如何在Java中动态提取.gz文件?

如何在Java中动态提取.gz文件?,java,Java,许多.gz文件的URL如下所示: <loc> http://www.newegg.com//Sitemap/USA/newegg_sitemap_product01.xml.gz </loc> 只需将输入流打包,它就会在您读取数据时解压。只需将输入流打包,它就会在您读取数据时解压。private void processGzip(URL URL,byte[]response)抛出畸形的异常异常、IOException、UnknownFormatException

许多.gz文件的URL如下所示:

<loc>
    http://www.newegg.com//Sitemap/USA/newegg_sitemap_product01.xml.gz
</loc>

只需将输入流打包,它就会在您读取数据时解压。

只需将输入流打包,它就会在您读取数据时解压。

private void processGzip(URL URL,byte[]response)抛出畸形的异常异常、IOException、UnknownFormatException{if(DEBUG)System.out.println(“正在处理gzip”);InputStream is=new ByteArrayInputStream(响应);//Remove.gz结束字符串xmlUrl=url.toString().replaceFirst(\\\.gz$”,“”);if(DEBUG)System.out.println(“XML url=+xmlUrl”);InputStream解压缩后=新的GZIPInputStream(is);InputSource in=新的InputSource(解压缩);in.setSystemId(xmlUrl);processXml(url,in);解压缩的.close();}java.io.IOException:在java.util.zip.GZIPInputStream.readHeader(未知源)的java.util.zip.GZIPInputStream处不是GZIP格式。(未知源)@user1047251:这意味着您提供的数据不是gzip格式。请尝试将其保存到一个文件中,并在命令行上使用
gunzip
,看看是否有效(几乎肯定不会)。InputStream decompressed=new GZIPInputStream(is)中出现异常;行请帮助我如何修复..Thanksprivate void processGzip(URL URL,byte[]response)抛出错误的异常,IOException,UnknownFormatException{if(DEBUG)System.out.println(“Processing gzip”);InputStream is=new ByteArrayInputStream(response);//Remove.gz结束字符串xmlUrl=URL.toString().replaceFirst(“\\.gz$”,”);if(DEBUG)System.out.println(“XML url=“+xmlUrl”);InputStream decompressed=new GZIPInputStream(is);InputSource in=new InputSource(decompressed);in.setystemid(xmlUrl);processXml(url,in);decompressed.close();}java.io.IOException:java.util.zip.GZIPInputStream.readHeader(未知源)处的java.util.zip.GZIPInputStream.(未知源)处的java.util.zip.GZIPInputStream.(未知源)处的GZIP格式@user1047251:这意味着您提供的数据不是gzip格式。请尝试将其保存到一个文件中,并在命令行上使用
gunzip
,看看是否有效(几乎肯定不会)。InputStream decompressed=new GZIPInputStream(is);line中出现异常。请帮助我如何修复它。谢谢
private void processGzip(URL url, byte[] response) throws MalformedURLException,
            IOException, UnknownFormatException {

        if (DEBUG) System.out.println("Processing gzip");

        InputStream is = new ByteArrayInputStream(response);

        // Remove .gz ending
        String xmlUrl = url.toString().replaceFirst("\\.gz$", "");

        if (DEBUG) System.out.println("XML url = " + xmlUrl);

        InputStream decompressed = new GZIPInputStream(is);
        InputSource in = new InputSource(decompressed);
        in.setSystemId(xmlUrl);         
        processXml(url, in);
        decompressed.close();
    }