Java 9 zip end header exception not found
•
Java
I tried to use Java – SRTM files to batch download zip files from this URL. It requires a user name / password to download. I used the following java code, which gave 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)
This is my java version
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)
This is the code I use to download –
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,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 someone help me explain why I failed?
Solution
Some (closed) errors in Java 9 mention this exception (for example, jdk-8170276, jdk-8172872) Since Java 9 is still in the testing stage and you are using a version more than a year ago (April 14, 2016 and July 2017 at the time of writing this article), you should upgrade to the latest Java 9 EA version or stick to Java 8 until Java 9 is publicly released
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码