找不到Java 9 Zip结束标头异常 [英] Java 9 Zip End Header Not Found Exception

查看:255
本文介绍了找不到Java 9 Zip结束标头异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为Google员工编辑:原来是由于使用Java 9的最新Beta版本引起的。

I我正尝试使用java- SRTM文件从该URL批量下载zip文件。 ,并且需要用户名/密码才能下载,并且我正在使用以下Java代码,并且给了我以下异常

I am trying to batch download zip files from this URL using java - SRTM files and it requires a username/password to download and I am using the following java code and it gives me the following exception

java.util.zip.ZipException: zip END header not found
at java.util.zip.ZipFile$Source.zerror(java.base@9-internal/ZipFile.java:1210)
at java.util.zip.ZipFile$Source.findEND(java.base@9-internal/ZipFile.java:1119)
at java.util.zip.ZipFile$Source.initCEN(java.base@9-internal/ZipFile.java:1126)
at java.util.zip.ZipFile$Source.<init>(java.base@9-internal/ZipFile.java:963)
at java.util.zip.ZipFile$Source.get(java.base@9-internal/ZipFile.java:933)
at java.util.zip.ZipFile.<init>(java.base@9-internal/ZipFile.java:213)
at java.util.zip.ZipFile.<init>(java.base@9-internal/ZipFile.java:145)
at java.util.zip.ZipFile.<init>(java.base@9-internal/ZipFile.java:159)
at toposwapper.rules.ZipFileDownloadAction.execute(ZipFileDownloadAction.java:29)

这是我的Java版本

 java openjdk version "9-internal"
 OpenJDK Runtime Environment (build 9-internal+0-2016-04-14-195246.buildd.src)
 OpenJDK 64-Bit Server VM (build 9-internal+0-2016-04-14-195246.buildd.src, mixed mode)

这是我正在下载-

    URL url1 = null;
    URLConnection conn = null;
    InputStream inputs = null;
    FileOutputStream out = null;
    try 
    {
        url1 = new URL(url);
        conn = url1.openConnection();
        conn.setDoInput(true);
        conn.setDoOutput(false);
        conn.setRequestProperty("file-name", output.getName());
        conn.setRequestProperty("content-type","application/zip");
        String userpass = this.username + ":" + this.password;
        String basicAuth = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(userpass.getBytes());
        conn.setRequestProperty("Authorization",basicAuth);
    } 
  catch (MalformedURLException ex) {
           Logger.getLogger(SrtmDownloadManager.class.getName()).log(Level.SEVERE, "", ex);
    throw new TopoSwapperException(ex.getMessage());
    }
  catch (IOException ioe)
    {
    Logger.getLogger(SrtmDownloadManager.class.getName()).log(Level.SEVERE, "", ioe);
    throw new TopoSwapperException(ioe.getMessage());
    }

    try 
      {
         inputs = conn.getInputStream();
         out = new FileOutputStream(output);
         byte[] b = new byte[1024];
         int count;
         while ((count = inputs.read(b)) > -1)
          {
            out.write(b,0,count);
           }
         out.flush();
         inputs.close();
         out.close();

      } 
    catch (FileNotFoundException ex) 
    {
        throw new TopoSwapperException(ex.getMessage());
    } 
    catch (IOException ex) 
    {
    Logger.getLogger(SrtmDownloadManager.class.getName()).log(Level.SEVERE, "", ex);
    throw new TopoSwapperException(ex.getMessage());
    }
finally
    {
        close(inputs);
        close(out);
    }

有人能帮我为什么会失败吗?

Can somebody help me why this fails ?

推荐答案

Java 9的一些(已关闭)错误提到了此异常(例如, JDK-8170276 JDK-8172872 )。由于Java 9仍处于测试阶段,并且您使用的是一年多以前的版本(2016年4月14日与撰写本文时的2017年7月),因此您应该升级到最新的Java 9 EA版本或坚持使用Java 8直到Java 9公开发布。

There are a few (already closed) bugs for Java 9 that mention this exception (eg. JDK-8170276, JDK-8172872). Since Java 9 is still in beta and you're using a version from over a year ago (2016-04-14 vs. July 2017 of the time of writing) you should upgrade to the newest Java 9 EA release or stick to Java 8 until a public release of Java 9.

这篇关于找不到Java 9 Zip结束标头异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆