* @param filename The filename of the manifest file containing the properties (normally
* META-INF/MANIFEST.MF).
* @throws IOException If there is a temporary files error or the jar is corrupted. */
static Properties parseProperties(InputStream is, String filename) throws IOException {
Properties props = new Properties();
ZipInputStream zis = new ZipInputStream(is);
try {
ZipEntry ze;
while(true) {
ze = zis.getNextEntry();
if(ze == null) break;
if(ze.isDirectory()) continue;
String name = ze.getName();
if(name.equals(filename)) {
if(logMINOR) Logger.minor(NodeUpdater.class, "Found manifest");
long size = ze.getSize();
if(logMINOR) Logger.minor(NodeUpdater.class, "Manifest size: "+size);
if(size > MAX_MANIFEST_SIZE) {
Logger.error(NodeUpdater.class, "Manifest is too big: "+size+" bytes, limit is "+MAX_MANIFEST_SIZE);
break;
}
byte[] buf = new byte[(int) size];
DataInputStream dis = new DataInputStream(zis);
dis.readFully(buf);
ByteArrayInputStream bais = new ByteArrayInputStream(buf);
props.load(bais);
} else {
// Read the file. Throw if there is a CRC error.
// Note that java.util.zip.ZipInputStream only checks the CRC for compressed
// files, so this is not entirely foolproof.
long size = ze.getSize();
FileUtil.copy(zis, new NullOutputStream(), size);
zis.closeEntry();
}
}
} finally {
Closer.close(zis);
}