From 9cf33c33faa57bae110b781b0edd6dcd97649bfd Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Mon, 3 Jun 2013 22:03:49 -0700 Subject: [PATCH] [bs-52] Allow war files to run in place Update RandomAccessJarFile to work around EOFExceptio on JDK 6 [#48386505] [bs-52] Support for running "traditional" webapps in place --- .../launcher/jar/RandomAccessJarFile.java | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/spring-bootstrap-launcher/src/main/java/org/springframework/bootstrap/launcher/jar/RandomAccessJarFile.java b/spring-bootstrap-launcher/src/main/java/org/springframework/bootstrap/launcher/jar/RandomAccessJarFile.java index 835a458f59f..6dbd581021b 100644 --- a/spring-bootstrap-launcher/src/main/java/org/springframework/bootstrap/launcher/jar/RandomAccessJarFile.java +++ b/spring-bootstrap-launcher/src/main/java/org/springframework/bootstrap/launcher/jar/RandomAccessJarFile.java @@ -17,6 +17,7 @@ package org.springframework.bootstrap.launcher.jar; import java.io.BufferedInputStream; +import java.io.EOFException; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; @@ -181,7 +182,7 @@ public class RandomAccessJarFile extends JarFile { public synchronized InputStream getInputStream(ZipEntry ze) throws IOException { InputStream inputStream = getData(ze).getInputStream(); if (ze.getMethod() == ZipEntry.DEFLATED) { - inputStream = new InflaterInputStream(inputStream, new Inflater(true), 512); + inputStream = new ZipInflaterInputStream(inputStream); } return inputStream; } @@ -431,4 +432,33 @@ public class RandomAccessJarFile extends JarFile { return this.contentType; } } + + /** + * {@link InflaterInputStream} that support the writing of an extra "dummy" byte which + * is required with JDK 6 + */ + private static class ZipInflaterInputStream extends InflaterInputStream { + + private boolean extraBytesWritten; + + public ZipInflaterInputStream(InputStream inputStream) { + super(inputStream, new Inflater(true), 512); + } + + @Override + protected void fill() throws IOException { + try { + super.fill(); + } catch (EOFException ex) { + if (this.extraBytesWritten) { + throw ex; + } + this.len = 1; + this.buf[0] = 0x0; + this.extraBytesWritten = true; + this.inf.setInput(this.buf, 0, this.len); + } + } + + } }