[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
pull/2/merge
Phillip Webb 12 years ago
parent a6c03e72e6
commit 9cf33c33fa

@ -17,6 +17,7 @@
package org.springframework.bootstrap.launcher.jar; package org.springframework.bootstrap.launcher.jar;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.EOFException;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
@ -181,7 +182,7 @@ public class RandomAccessJarFile extends JarFile {
public synchronized InputStream getInputStream(ZipEntry ze) throws IOException { public synchronized InputStream getInputStream(ZipEntry ze) throws IOException {
InputStream inputStream = getData(ze).getInputStream(); InputStream inputStream = getData(ze).getInputStream();
if (ze.getMethod() == ZipEntry.DEFLATED) { if (ze.getMethod() == ZipEntry.DEFLATED) {
inputStream = new InflaterInputStream(inputStream, new Inflater(true), 512); inputStream = new ZipInflaterInputStream(inputStream);
} }
return inputStream; return inputStream;
} }
@ -431,4 +432,33 @@ public class RandomAccessJarFile extends JarFile {
return this.contentType; 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);
}
}
}
} }

Loading…
Cancel
Save