[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
This commit is contained in:
Phillip Webb 2013-06-03 22:03:49 -07:00
parent a6c03e72e6
commit 9cf33c33fa

View File

@ -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);
}
}
}
}